NT Bus Protocol

From STorM32-BGC Wiki V1
Revision as of 21:57, 30 September 2015 by OlliW (talk | contribs) (→‎Concept)
Jump to navigation Jump to search

The information on this page refers to firmware v0.86e and higher.

This page describes the protocol of the NT bus communication.

Hardware Details

The NT bus is nothing else than a standard TTL-UART, with parameters:

2.000.000 bps, 8 bits, 1 stop, no parity

The voltage levels are 3.3 V.

The Tx pin of any NT module connected to the bus must be in a high-impedance state in normal conditions. This line should be pulled to high on the main board side of the bus.

Concept

The NT bus is designed as a master-slave network, with one master, the main STorM32 board. Any slave connected to the bus needs its own unique ID. The ID has 4 bits. ID = 0 is used to address all NT slaves on the bus, so that up to 15 slaves can be addressed.

The slaves are either Talker&Listener or only Listener. At any point in time only one slave is permitted to be talking, i.e. to send data to the master. Any slave may talk only in response to a command received by the master, a slave may not send any message on its own.

Currently these IDs are assigned:

#define NTBUS_ID_ALLMODULES               0
#define NTBUS_ID_IMU1                     1
#define NTBUS_ID_IMU2                     2
#define NTBUS_ID_MOTORALL                 3
#define NTBUS_ID_MOTORPITCH               4
#define NTBUS_ID_MOTORROLL                5
#define NTBUS_ID_MOTORYAW                 6
#define NTBUS_ID_CAMERA                   7
#define NTBUS_ID_JOYSTICK                 8
#define NTBUS_ID_KEYS                     9
#define NTBUS_ID_PWMOUT                   10
#define NTBUS_ID_LOGGER                   11

Communication Details

Communication from Master to Slaves

Every message emitted by the master is started with a start byte, which has three fields:

bit 7:        always 1, indicates that it is a start byte
bits 6,5,4:   short command
bits 3,2,1,0: ID of the NT module the message is for
#define NTBUS_STX                         0x80 // 0b 1000 0000
#define NTBUS_SFMASK                      0x70 // 0b 0111 0000
#define NTBUS_IDMASK                      0x0F // 0b 0000 1111

The following short commands are defined:

#define NTBUS_FLASH                       0x70 // 0b 0111 0000
#define NTBUS_RESET                       0x50 // 0b 0101 0000
#define NTBUS_SET                         0x40 // 0b 0100 0000
#define NTBUS_GET                         0x30 // 0b 0011 0000
#define NTBUS_TRIGGER                     0x10 // 0b 0001 0000
#define NTBUS_CMD                         0x00 // 0b 0000 0000

The start byte may be followed by further bytes, but these bytes must have their 7th bit set to low!

Transmitted data must be protected by a crc byte at its end. It is calculated by a xor over all data bytes, with the 7th bit set to low.

Examples:

  • The first message emitted by the master at the beginning of every new cycle is a group trigger, i.e.
0x90:  triggers all NT modules
  • When the data of the camera imu (IMU1) is requested by emitting
0xB1: get IMU1 data
  • Eventually the new motor angles will be send to all motor modules, which is done by addressing them all, i.e.
0xC3 + 10x motor data bytes + crc: set all motor to the new positions

Communication from Slave to Master

Whenever a NT module sends data to the STorM32, it first must enable it's Tx line, wait 2 us, send the data, wait 2us, and then disable the Tx line.

In contrast to the messages from master to slaves, full bytes can be send (i.e. the 7th bit doesn't have to be 0), since by design a slave never sends a command.

Error Handling

In the data stream from the master to the slaves only the start byte may have the 7th bit high. The data parser must reset on this occasion, which establishes the mechanism to return to proper operation if some error should have occurred.

In addition the receiving UARTs should check for error conditions offered by the hardware. For a STM32F103 this would be e.g. the overrun, noise, and frame flags.