Skip to content

The UART Connection

The cloud module can be controlled through UART as well, similar in the way that it works through CAN. In fact it is so similar that the syntax of the UART messages the user needs to send to the cloud module, are essentially the serialised versions of the same CAN messages.

Technical Information

The system works with a fixed baud rate of 115200. For good measure, both TX and RX lines of the cloud module should be connected. However currently the cloud module does not send any messages on the UART line. In the future, it will send acknowledgements to received messages.

Message Format

Each UART message is sent as a packet of ASCII characters expressing 7 bytes of data, 1 byte of CRC as well as the start character. The bytes are serialised into character before sending. Keeping in mind that one byte of information can be expressed in the hex format with two characters (e.g. the byte 0X5F can be expressed as a character array of ['5', 'F']), 7+1=8 bytes of data plus the start character equals 17 characters per packet in total.

The first character is always an ASCII :, signalling the start of a new packet and causes the cloud module to clear its internal buffers. This is followed by the index (2 bytes), subindex (1 byte) and data (4 bytes) and lastly the single CRC byte.

Below is a table with an annotated example message and its UART packet equivalent:

IndexSubindexValueCRC
0x001F0x020x123456780xE6

This should be compiled into the string ":1F000278563412E6".

DANGER

Notice that the data should be parsed in little endian format.

sendData() Function

The message formatting described above, should be implemented by the user of the cloud module library in the void SendData(uint16_t index, uint8_t subindex, uint32_t value) function. The encoded message is then sent through the UART line. The function is called with all the necessary parameters for encoding, except the CRC. The user is responsible for calculating the CRC inside the sendData function as detailed below.

CRC

Since UART does not provide any inherent method to verify data integrity, the user is responsible for adding a CRC byte at the end of the packet. Cloud module runs the same CRC algorithm over the received message in order to verify correct data, and discards the packet if it was compromised.

The cloud module header comes with a helper function to generate this CRC byte. The user must use this function this function in order to make sure there aren't any differences between the CRC values generated in the user code and the cloud module code.

This function uint8_t GenerateCrc(uint8_t *data, size_t len) should be called with the data being an array of bytes and the length always 7 currently.

So in the table example given above, the user would be responsible for creating an array with the values [0x1F, 0x00, 0x02, 0x78, 0x56, 0x34, 0x12] and passing this into the GenerateCrc function. The returned byte is the calculated CRC value (0xE6 in this case), which should be appended to the UART packet.