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:

  • On WahooA, press Button 2 to switch to command mode. The terminal displays COMMAND_MODE. This is local COMMAND mode.
  • On the WahooA terminal:
    • Press the Enter key and wait for a command prompt > and Ready

Follow the same procedure to place WahooB in local COMMAND mode.

  • On WahooB, press Button 2 to switch to command mode. The terminal displays COMMAND_MODE.
  • On the WahooB terminal:
  • Press the Enter key and wait for a command prompt > and Ready

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:

  • On the WahooA terminal:
    adv
  • On Wahoo B, enter the command scan high. Within a few seconds, TruConnect displays a list of ACKme BLE devices discovered. For example,
    > scan high
    !  # RSSI BD_ADDR           Device Name
    > 
    #  1  -58 20:73:7a:12:9a:42 AMS-9A42
  • Issue the con (connect) command, with the index number of the WahooA board listed by the scan results.
    > con 1
    Success
  • On both boards, the tri-colour LEDs light continuously green when the boards are connected.

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:

  • On the WahooA terminal, issue the str command. TruConnect responds with STREAM_MODE:
    > str
    STREAM_MODE
  • On the WahooB terminal, issue the str command. TruConnect responds with 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.

  • To see this, issue the get gp u (gpio usage) command:
    > get gp u
    !  # Description
    ...
    #  9 mode_sel
    ...

Now assign the none function to GPIO 9.

  • On the WahooA terminal:
    • Set the GPIO 9 function to none with the gfu command:
      gfu 9 none
    • Now issue the get gp u command:
      > get gp u
      !  # Description
      ...
      #  9 none
      ...
  • Save and restart. WahooA restarts in local COMMAND mode
    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.

  • On the WahooB terminal:
    > scan high
    !  # RSSI BD_ADDR           Device Name
    > #  1  -49 20:73:7a:12:9a:42 AMS-9A42
    > con 1
    Success
  • On the WahooA terminal, TruConnect responds:
    STREAM_MODE

Disconnect to return WahooB to local COMMAND mode:

  • On the WahooB terminal, issue the dct (disconnect) command:
    > dct
    Success
  • On the WahooA terminal, TruConnect responds:
    COMMAND_MODE

Reconnect WahooA to WahooB. WahooA returns to STREAM mode.

  • On the WahooB terminal, issue the stream command:
    >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:

  • On WahooB, press the Reset button.
  • On the WahooA terminal, TruConnect responds:
    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:

  • Ensure WahooA is configured to allow remote COMMAND mode
  • Place WahooA in STREAM mode
  • Connect WahooB to WahooA
  • Place WahooA in remote COMMAND mode by running the rbmode (remote bus mode) command on WahooB.
  • Place WahooB in STREAM mode, so commands can be sent from WahooB to WahooA.

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.

  • On the WahooA terminal, get the bl a variable (BLE device address):
    > get bl a
    20737A129A42
  • On the WahooB terminal, get the BLE Device address:
    > 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:

  • On the WahooA terminal, issue the command:
      
    > 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.

  • Configure WahooA for automatic bus mode selection; that is, assign WahooA GPIO 9 to none, as described above in Automatic Bus Mode Selection.
  • Restart WahooA. It starts in local COMMAND mode.

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:

  • On the WahooB terminal, get the gp u gp usage variable:
    > get gp u
    !  # Description
    ...
    #  9 mode_sel
    ...
  • Connect WahooB to WahooA, as described above in Connecting WahooB to WahooA.
    > scan high
    !  # RSSI BD_ADDR           Device Name
    > #  1  -62 20:73:7a:12:9a:42 AMS-9A42
    con 1
    Success
  • WahooA automatically switches to STREAM mode
    STREAM_MODE

Placing WahooA in remote COMMAND mode

  • On the WahooB terminal, issue the rbmode (remote bus mode) command, with no argument. TruConnect responds with the remote device (WahooA) bus mode:
    > rbmode
    stream
  • On the WahooB terminal, issue the rbmode (remote bus mode) command with the remote argument:
    > rbmode remote
    Success
  • WahooA switches to remote COMMAND mode:
    REMOTE_MODE

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

  • On the WahooB terminal, get the BLE device address again. The response is the WahooB address as before:
    > 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:

  • On the WahooB terminal:
    > dct
    Success
  • On the WahooA terminal:
    COMMAND_MODE

Reconnect:

  • On the WahooB terminal:
    > con 1
    Success
  • On the WahooA terminal:
    STREAM_MODE

Use rbmode to place WahooA back in remote COMMAND mode.

  • On the WahooB terminal:
    > rbmode remote
    Success
  • On the WahooA terminal:
    REMOTE_MODE

Placing WahooB in STREAM mode

  • Now on the WahooB terminal, switch to STREAM mode:
    > str
    STREAM_MODE

Now commands are sent from WahooB to WahooA.

  • Issue the get bl a command:
    > 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.

  • On the WahooB terminal, issue the stream command:
    > str
  • On the WahooA terminal, the response appears:
    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+