3. CodeLess Examples
3.1. GPIO Pin References
- A port pin is referenced as a two digit decimal number:
First digit is the port number, second digit is the pin number
Port 1, pin 3 (P1_3) is thus referenced “13”
Port 0, pin 2 (P0_2) is referenced “02” or simply “2”
For example, setting P0_3 as an input with pull-up (GPIO type 2):
AT+IOCFG=3,2
Note
P0_5 and P0_6 are used for the UART interface and cannot be assigned to other functions. Only ports P0_0 to P0_3 can be used as analog inputs.
3.2. First Example
You can begin with first example wherein you send AT as a command on the terminal and you receive OK. This verifies that the connection is established.
AT” gives you the CodeLess version and type description
AT+BDADDR displays your BD Address as show in Figure 21
Refer to Section 9 for detailed commands syntax.
Note
Make sure you use CAPS for the commands as they are case-sensitive.
Note
When you enter the AT commands, do not add space at the end of the command.
3.3. Examples - Local Board
3.3.1. Toggle LED
AT commands for DA1458x:
AT (To verify the connection by getting an “OK” back)
AT+IOCFG=10,4 (“10” implies Port 1, Pin 0 ; “4” implies IO Functionality where 4 here means IO Output)
AT+IO=10,1 (AT+IO=10,0 for LED OFF)
User LED D3 is toggled
AT commands for DA1453x:
AT (To verify the connection by getting an “OK” back)
AT+IOCFG=9,4 (“9” implies Port 0, Pin 9 ; “4” implies IO Functionality where 4 here means IO Output)
AT+IO=9,1 (AT+IO=9,0 for LED OFF)
User LED D5 is toggled
Note
On both basic and pro kits, make sure the J9 jumper is connected.
3.3.2. Read ADC
Note
Here the analog input is connected to 3V supply.
Steps on DA14580 Pro-DK:
Connect the P0_2 and VBAT_580 as shown in the figure.
When it is connected, send the following AT Commands for DA14585/586:
AT
AT+IOCFG=2,6 (P0_2, 6 implies analog input)
AT+ADC=2 (Reading the value from P0_2)
The ADC value shows 934 (10-bit ADC value) which can be converted to Voltage value by doing the following:
You can connect an analog voltage from an external source and do the experiment again. This way you can verify what voltage you are measuring as compared to the input supply.
Note
The ADC value will be around 930 for a 3V voltage on the ADC input. The max voltage that can be measured is 3.6V for 3x attenuation.
3.3.3. Write/Read I2C
We will be using the Adafruit MCP9808 I2C Temperature sensor to read the temperature value. The connections are as shown in Figure 26.
Connections for DA1458x with DA14580 Pro-DK:
Vdd <-> VBat
Gnd <-> Gnd
SCL <-> P1_1
SDA <-> P0_2
AT Commands for DA1458x:
AT+IOCFG=11,7 (Pin P1_1 represented here as “11” is used as SCL, “7” is Hardware AT command for I2C CLK … refer AT Commands section )
AT+IOCFG=2,8 (Pin 0_2 , “8” is Hardware AT command for I2C SDA)
AT+I2CSCAN (This gives you the sensor slave address, seen here as 0x18)
AT+I2CCFG=7,400,16 (The slave addressing bit count: “7” for 7 bit or “10” for 10 bit; The bit rate: “100” for 100 kbit/s or “400” for 400 kbit/s; The slave register width: “8” for 8 bit or “16” for 16 bit.)
AT+I2CREAD=0x18,5 (read the sensor at hardware address 0x18, register 5)
We receive a reading of 0xC195 which translates to 25.3°C
- Calculation :
Ta = (upper byte * 16 + lower byte/16)
Ta = (1 * 16 + 149 / 16)
Ta= 25.3°C
Connections for DA1453x with DA1453xx Pro-DK:
Vdd <-> V3
Gnd <-> Gnd
SCL <-> P0_9
SDA <-> P0_11
AT Commands for DA1453x:
AT+IOCFG=9,7 (Pin P0_9 represented here as “9” is used as SCL, “7” is Hardware AT command for I2C CLK … refer AT Commands section)
AT+IOCFG=11,8 (Pin 0_11 , “8” is Hardware AT command for I2C SDA)
AT+I2CSCAN (This gives you the sensor slave address, seen here as 0x18)
AT+I2CCFG=7,400,16 (The slave addressing bit count: “7” for 7 bit or “10” for 10 bit; The bit rate: “100” for 100 kbit/s or “400” for 400 kbit/s; The slave register width: “8” for 8 bit or “16” for 16 bit)
AT+I2CREAD=0x18,5 (Read the sensor at hardware address 0x18, register 5)
3.3.4. Command Sequencer for DA145xx
Commands can be stored in the command slots and triggered either by a command or by a timer. The following is a blinky example that toggles the board led of basic kit every 1 sec:
AT+IOCFG=10,4 (Set up pin 10 as GPIO output)
AT+CMDSTORE=0,AT+IO=10,1;AT+TMRSTART=0,1,100 (Command slot 0:Turn led on and after 1 sec run command slot 1)
AT+CMDSTORE=1,AT+IO=10,0;AT+TMRSTART=1,0,100 (Command slot 1:Turn led off and after 1 sec run command slot 0)
AT+CMDPLAY=0 (Trigger command sequence in command slot 0)
3.4. Examples - Remote Board
The general setup to perform remote AT commands is similar to the setup as shown in the above examples, except, we have another board with a similar configuration.
The board setup for the DA14585/586 and DA14531 is as shown below. Any combination is possible.
DA1453x and DA1458x (Remote)
DA1453x and DA1453x (Remote)
DA1458x and DA1453x (Remote)
DA1458x and DA1458x (Remote)
Setup:
Connect both the DA145xx Pro-DK and the DA14580 Pro-kit via USB to the PC.
As before, make a note of the COM ports from device manager.
Note the BD Address of both the boards.
Execute remote AT commands from the server or the client sides.
Note
Take a note of “r” in the AT commands. It indicates that you are referring to the remote board.
3.4.1. Advertise/Scan
Follow the set of AT commands to scan and connect to the peripheral device
AT+ADVSTOP
AT+CENTRAL
AT+GAPSCAN
AT+GAPCONNECT=<BD_address_of_peripheral>,R
ATrI (“r” implies remote board here)
Note
BDADDR as seen above is DF:CF:E7:66:8D:6C,R where the 6 bytes indicates unique BD Address of your device and the R implies Random address.
Warning
The DA14531-01 can’t be configured as a central, the AT+CENTRAL,AT+GAPSCAN and AT+GAPCONNECT commands are not supported.
3.4.2. Blink LED
The set of AT commands listed below will scan and connect to your peripheral device and blink the LED.
AT commands:
AT+ADVSTOP
AT+CENTRAL
AT+GAPSCAN
AT+GAPCONNECT=<BD_address_of_peripheral>,R
ATrI
ATr+IOCFG=10,4
ATr+IO=10,1 (Switches on LED D3)
ATr+IO=10,0 (Switches off LED D3)
- For the DA14531:
ATr+IOCFG=9,4
ATr+IO=9,1 (Switches on LED D5)
ATr+IO=9,0 (Switches off LED D5)
Warning
The DA14531-01 can’t be configured as a central, the AT+CENTRAL,AT+GAPSCAN and AT+GAPCONNECT commands are not supported.
3.4.3. Write/Read I2C
Setup:
The connections are similar to the ones already done for the Local Examples. You can refer this figure to do the connections.
AT commands for DA1458x:
AT+ADVSTOP
AT+CENTRAL
AT+GAPSCAN
AT+GAPCONNECT = <BD_address_of_peripheral>
ATrI
ATr+IOCFG=11,7 (ATr+IOCFG=9,7 for DA14531)
ATr+IOCFG=2,8 (ATr+IOCFG=11,8 for DA14531)
ATr+I2CSCAN
ATr+I2CCFG=7,400,16
ATr+I2CREAD=0x18,5
We receive a reading of 0xC170 which translates to 23°C. The calculations are done in similar way as done for the local I2C example.
Warning
The DA14531-01 can’t be configured as a central, the AT+CENTRAL,AT+GAPSCAN and AT+GAPCONNECT commands are not supported.
3.4.4. Read ADC
The connections are as shown in the Figure 35 and is similar to the Local example.
AT commands for DA1458x:
AT+ADVSTOP
AT+CENTRAL
AT+GAPSCAN
AT+GAPCONNECT=<BD_address_of_peripheral>,R
ATrI
ATr+IOCFG=2,6 (ATr+IOCFG=3,6 for DA1453x)
ATr+ADC=2 (ATr+ADC=2 for DA1453x)
The ADC value shows 915(10-bit ADC value) which can be converted to Voltage value 2.951 V.
Warning
The DA14531-01 can’t be configured as a central, the AT+CENTRAL,AT+GAPSCAN and AT+GAPCONNECT commands are not supported.