2.5 Input/Output Configuration and Level Control of GPIO Pins
The RNBD350 module has 7 GPIO pins, and all pins must be shared with RNBD function pins and the General Purpose Input Output (GPIO) pins functionality .If the read GPIO pin is occupied by a function pin whose function is enabled, it will reply to an error response. Out of all available pins, the GPIO pins that can be controlled using ASCII commands are defined as I/O level control by ASCII command. The RNBD350 module datasheet Table 3-1 captures the detailed pin description details for all available pins
For easy understanding, the GPIO pins that can be controlled using ASCII commands are captured in below table.
Note:In the RNBD350 Add on Board, the gpio pins are not brought out. This configurtation will be helpful for the module users.
Pin Number | Name |
13 | PB8 |
9 | PB5 |
11 | PB4 |
23 | PA10 |
22 | PA9 |
24 | PA8 |
10 | PA3 |
The ASCII command provide the flexibility to configure these GPIO pins as either input and read its pins digital state or configure as output pins and set the desired output pin level to it. The functionality of configuring the pin as digital input and reading its value is made possible with Set Digital Input and Read Port (|I, <hex16>) command. By using the Set Digital Output Port (|O, <hex16>, <hex16>) command, the GPIO pin can be configured as Output pin and set its default level. For detailed description of these commands, refer to the RNBD350 Bluetooth Low Energy Module User’s Guide available in product page.
Individual bitmap values are assigned to each pin in the module firmware. Thus, the bitmap values are considered as an identification pointer for each pin. This method of assignation helps to configure multiple pins in singe command execution. Refer below table to understand the assigned bitmap values for each pin.
Table: Digital I/O Bitmap
Bitmap | RNBD350 Pins |
0001 | PA3 |
0002 | PA8 |
0004 | PA9 |
0008 | PA10 |
0010 | PB4 |
0020 | PB5 |
0040 | PB8 |
1.1 Set Digital Input Command Implementation and Usage
Set Digital Input and Read Port (|I, <hex16>)
Format: |I, <hex16>
Command |I do the functionality of configure the pin as digital input and read the input level of the pin in single command execution. The command expects a hex16 value as its parameter which indicate the corresponding bitmap value of the RNBD350 pin. The Table: Digital I/O Bitmap provides details about the I/O pin bitmap format. The expected response for the command is also a bitmap. If the corresponding pin to read is high, then the bit in theresponse is set, otherwise, the bit is cleared
Example 1: Set Digital input pin PA3 and PA8 and read back
Example:
|I,0003
// Read digital I/O PA0 and
PA1.
// If return value is 0002,
// then PA3 is low and PA8 is high
Response:
AOK
// Success
ERR
// Syntax error or invalid parameter
The general idea: If we want to configure multiple pins, then we need to add the bitmap values of the indented pins provide as input parameter to the command.
In the above example, the pins PA3 and PA8 are set as input and its input levels are read. For that, the corresponding bitmap values of PA3 and PA8 is added. That is 0001 + 0002 = 0003. The input should be in hex16 format for the command to process. Else the command respond Err.
If the response value received is 0002. That shows that the PA3 is low and PA8 is high.
The corresponding binary equivalent value will give more idea about the pins state.
Binary equivalent of 2 is 0010
0(PA10) 0(PA9) 1(PA8) 0(PA3)
Example 2: Set Digital input pin PA10 and PB4 and read back
Example:
|I,0018
// Read digital I/O PA10 and PB4.
// If return value is 0018,
Response:
AOK
// Success
ERR
// Syntax error or invalid parameter
In the above example, the pins PA10 and PB4 are set as input and its input levels are read. For that, the corresponding bitmap values of PA0 and PA1 is added. That is 0008 + 0010 = 0018
If the response value received is 0018. That shows that the PA10 is Low and PB4 is high.
Binary equivalent of 18 is 0001 0010
0(PB8) 0(PB5) 1(PB4) 0(PA10) 0(PA9) 1(PA8) 0(PA3)