Hi Everyone,
This is my first post here, so first of all, hello world.
I’m fairly new to serial comms but I’ve succeeded in some basic command outputs.
I’m having problems trying to send structured data packets from my Arduino UNO to an Atomos Samurai video recording device which has a serial remote control input. I have a data sheet for the serial protocol, which I have attached, but I will copy the key info into my post here.
I have my UNO serial going through a MAX485 board to convert my serial commands to RS485, and I have my USB logic analyser attached to the output of the MAX485. I can successfully send individual bytes using the following code:
const int enable = 4; // set enable command output pin to 4
void setup(){
pinMode(enable, OUTPUT); // 'enable' set as output
Serial.begin(9600);
}
void loop() {
digitalWrite(enable, HIGH); // set as 'enable' high
delay(10);
Serial.write(0x14); // sends '0x14' in hex
}
This works fine, and returns a ‘0x14’ every second on my logic analyser sample. However, I need to send a structured packet from the UNO, with a CRC attached. More specifically, in this format:
Packet Structure
The packet is variable length with BIG endian data ordering which has a minimum length of 16 bytes and a maximum length of 24 bytes.
Size | 2 bytes | Total size of the packet in bytes INCLUDING the 4-byte CRC appended to the data. |
---|---|---|
Command | 2 bytes | Command id or status id. |
Address | 8 bytes | Client address (unit name) or SERIAL_COMMAND_BROADCAST_ADDRESS. |
Data | Packet data, zero or more bytes with the caveat that it must be in multiples of 4 bytes. | |
CRC | 4 bytes | 16-bit CRC of entire packet. An example in C is given in Appendix B. |
The datasheet gives an example for sending a simple broadcast ‘record’ command in C, as follows:
s8 data[0x14] =
{
0x00, 0x14,
0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
};
u32 len = sizeof(data);
u32 crc = crc_16((const u8*)data, len - sizeof(u32));
*(u32*)(data + len - sizeof(u32)) = SWAP_U32(crc);
serial_write(serial, data, len);
Now I know C is pretty closely related to Aduino-speak, but I’m really not expert enough to make my UNO send this sort of data packet. That’s where I’d like some advice if anyone would be so kind as to help.
How can I send a structured packet of data like this from my Arduino UNO? Is it possible/worthwhile writing a CRC calculation script or should I just calculate it beforehand and stick it on the back end of each command? I only need to send four commands to the unit - Record, Stop, Touchscreen Lock and Touchscreen Unlock. I don’t mind manually (via online calculator ;)) calculating the CRC for each of those.
Any advise very much appreciate.
samurai_serial_remote_control.doc (149 KB)