Bus Mode Selection and Remote Control

This application note demonstrates bus mode selection, described in Serial Interface.

All the three bus modes are demonstrated: local COMMAND mode, STREAM mode, and remote COMMAND mode. The remote COMMAND mode demonstration shows how to remotely control a TruConnect device from another TruConnect device.

All the methods of selecting bus mode are demonstrated: mode_sel GPIO, str command, automatic bus mode selection, and BLE mode characteristic.

This demonstration uses two AMS001-E01 Wahoo boards. It is similar to the procedure described in Getting Started, with variations to cover the various methods for bus mode selection.

Set Up

Plug each of the AMS001-E01 Wahoo boards into a separate USB port on a computer and open a TruConnect Terminal for each board. See Getting Started, Opening a TruConnect Terminal.

It is assumed both Wahoo evaluation boards are in their factory default configuration, with the mode_sel GPIO assigned to GPIO 9, corresponding to Button 2.

Manual Bus Mode Selection Using the mode_sel GPIO

The Wahoo boards boot up as BLE peripherals with advertising turned on, in Stream Mode.

On both boards, the tri-colour LED lights flash green when the boards are not connected.

We'll refer to the Wahoo boards as WahooA and WahooB:

Connecting WahooB to WahooA

WahooB connects as a central to WahooB as a peripheral.

To connect to a BLE device, it must be advertising. Wahoo boards are configured to turn off advertising after a few minutes. Press the Reset button to restart and begin advertising again, or use the adv command to turn on advertising:

adv
> scan high
!  # RSSI BD_ADDR           Device Name
> 
#  1  -58 20:73:7a:12:9a:42 AMS-9A42
> con 1
Success

Manual Bus Mode Selection Using the str Command

If a TruConnect module is in local COMMAND mode, you can switch it to STREAM mode with the str command.

With the Wahoo boards connected:

> str
STREAM_MODE
> str
STREAM_MODE

With both TruConnect modules connected in STREAM mode, anything you type on the WahooA terminal appears on the WahooB terminal, and anything you type on the WahooB terminal appears on the WahooA terminal.

So far this is the same as the Getting Started procedure.

Automatic Bus Mode Selection

When the mode_sel GPIO function is not configured, bus mode selection is automatic. The TruConnect module is in local COMMAND mode when no BLE device is connected, and in STREAM mode when another BLE device is connected.

By default, the mode_sel function is assigned to Wahoo GPIO 9.

> get gp u
!  # Description
...
#  9 mode_sel
...

Now assign the none function to GPIO 9.

gfu 9 none
> get gp u
!  # Description
...
#  9 none
...
save
reboot
> [COMMAND_MODE]

WahooA is now using automatic bus selection. No BLE device is connected, so WahooA is in local COMMAND mode.

Now, follow the procedure described above in Connecting WahooB to WahooA, to connect WahooB to WahooA. When WahooB connects, WahooA switches to STREAM mode.

> scan high
!  # RSSI BD_ADDR           Device Name
> #  1  -49 20:73:7a:12:9a:42 AMS-9A42
> con 1
Success
STREAM_MODE

Disconnect to return WahooB to local COMMAND mode:

> dct
Success
COMMAND_MODE

Reconnect WahooA to WahooB. WahooA returns to STREAM mode.

>str
STREAM_MODE

WahooA and WahooB are connected together in STREAM mode, and what you type on one terminal appears on the other.

Disconnect to return WahooA automatically to local COMMAND mode:

COMMAND_MODE

Remotely Controlling a TruConnect Device

To remote control a TruConnect module, it must be placed in remote COMMAND mode.

This demonstration shows how to control a TruConnect module from another TruConnect module.

There are several steps to controlling WahooA from WahooB:

The rbmode command works by setting the BLE mode characteristic for WahooA. Setting the BLE mode characteristic to remote COMMAND mode is the only way to place a TruConnect module in remote COMMAND mode.

You can control a TruConnect device from a non-TruConnect BLE device by setting the BLE mode characteristic. See Communicating via BLE, Switching to remote COMMAND mode or STREAM mode. This is how theyACKme app controls a TruConnect device.

To check that this procedure is successful, we need to be able to distinguish WahooA from WahooB. We can do this with the unique BLE address.

Obtaining the BLE address

The BLE address is unique to the Wahoo evaluation used. The addresses shown below are examples only.

> get bl a
20737A129A42
> get bl a
20737A1C3110

Now that we can distinguish WahooA from WahooB, we start the procedure for controlling WahooA from WahooB.

Enabling remote COMMAND mode

A TruConnect module is by default enabled for remote COMMAND mode: the sy r e (system remote enable) is set to 1. To check this, get the sy r e variable:


> get sy r e
1

Placing WahooA in STREAM mode

In order to place WahooA in remote COMMAND mode, it must first be placed in STREAM mode. This can be done remotely, by connecting to WahooA, if WahooA is configured for automatic bus mode selection.

Connecting WahooB to WahooA

WahooB must be configured for manual bus mode selection for this demonstration, and must begin in local COMMAND mode. Ensure the mode_sel is assigned to GPIO 9:

> get gp u
!  # Description
...
#  9 mode_sel
...
> scan high
!  # RSSI BD_ADDR           Device Name
> #  1  -62 20:73:7a:12:9a:42 AMS-9A42
con 1
Success
STREAM_MODE

Placing WahooA in remote COMMAND mode

> rbmode
stream
> rbmode remote
Success
REMOTE_MODE

Note that WahooB is still in local COMMAND mode, and is not yet able to send commands to WahooA:

> get bl a
20737A1C3110

Cycling through WahooA Bus Modes

With WahooB in local COMMAND mode, and WahooA configured for automatic bus mode selection, you can cycle WahooA through all bus modes under the control of WahooB.

Disconnect WahooB to return WahooA to local COMMAND mode:

> dct
Success
COMMAND_MODE

Reconnect:

> con 1
Success
STREAM_MODE

Use rbmode to place WahooA back in remote COMMAND mode.

> rbmode remote
Success
REMOTE_MODE

Placing WahooB in STREAM mode

> str
STREAM_MODE

Now commands are sent from WahooB to WahooA.

> get bl a
20737A129A42

The response is the WahooA address.

With WahooB in STREAM mode, connected to WahooA in remote COMMAND mode, a command sent from WahooB is issued on WahooA, and the response is streamed back to WahooB.

Returning WahooA to STREAM mode

We can issue any command from WahooB to WahooA. For example, we can issue the stream command.

STREAM_MODE

Once again, WahooA and WahooB are connected together in STREAM mode, and what you type on one terminal appears on the other.

ModifiedChangesTruConnect Version
Required
2015-03-18Created1.0+