Setting Multiple GPIO Simultaneously



This section refers to the following sample application(s):

  • 01-gpio_multi

This application is new to OCSDK 1.2.0

When used as outputs, GPIO can be set/cleared simultaneously in two groups using a "pins" device.  Group 1 covers GPIO 0-15, and Group 2 covers GPIO 16-27. The same subset of GPIO that are available to your application (described in the GPIO sample) apply here.  All bits start at the de-asserted (low) state unless otherwise configured in the fuse table.

The 02-gpio_multi Sample Application

The 02-gpio_multi sample application implements a simple 3-bit counter, printing the current count on the mote's CLI and illuminating its LEDs. INDICATOR_0 is bit 0, STATUS_1 is bit 1, and STATUS_0 is bit 2.


gpio multi app, ver 1.2.0.1
SmartMeshIP stack, ver 1.4.1.6
Count = 0
Count = 1
Count = 2
...

To see the state of the LEDs on the

DC9003

board, you need to close the LED EN jumper.


Implementation Details

The 02-gpio_multi sample application uses the Helper Modules to initialize the CLI Module and for interaction with the local interface. It passes JOIN_NO in the fJoin flag when initializing the local module in the loc_task_init() to prevent the local module from attempting to join. It uses an initPins() helper function to open the "pins" device.  

Pins are configured in two 16-bit groups.  Each group is passed two bitmaps:  one of bits to set, and one of bits to clear.  Only three group 2 pins are used in this sample. Once set in one dn_ioctl() call, pins remain set until they are cleared by a subsequent call.   As an example, the behavior of a 4-bit section of a group is as follows:

Bits to setBits to clearResult
111100001111
000001011010
010110000111

The sample uses a single task (gpioTask) which:

  • Opens the pins device
  • In a while(1) loop, the application sets the pins according to the current count, and changes the pin levels using a dn_ioctl() call on the DN_GPIO_OUT_PINS_DEV_ID device. 
  • It then increments the count., and after a 500 ms delay it, de-asserts all pins for 100 ms, then resumes the loop.  This delay makes it easier to see that the LEDs are lighting as a group.