Tristating a pin

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

  • 02-tristate

This application is new to OCSDK 1.2.0

By default, unless driven by your application as inputs or outputs, or set similarly in the fuse table, all GPIO are tristated (hi-z) at boot. You can explicitly tristate a pin and optionally drive it to the asserted (high) or de-asserted (low) state in your application.

The 02-tristate Sample Application

The application provides five CLI functions for setting the state of pin DP2 (GPIO 21):

  • out <0|1> - sets the pin to be an output and sets the level to low (0) or high (1)
  • tristate <0|1|2> - set the pin to tristate, with no pull-up (0), pull-up (1) or pull-down (2)

Each CLI command prints the current state of the pin:

Tristate app, ver 1.2.0.1
SmartMeshIP stack, ver 1.4.1.6

> out 1
Setting pin to output 1


> tristate 0 
Setting pin to tristate with no pull

Implementation Details

The 02-tristate 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 includes five CLI handlers for setting the various pin states.  

It uses a single task (tristateTask) that:

  • Opens the DP2 pin.
  • Waits in a while(1) loop.

All pin setting changes are handled directly in the CLI handlers.  Since the CLI handlers block other application tasks, the CLI handlers can be written to copy information to a global variable and post a semaphore for asynchronous handling by another task.