Search code examples
carrayshexuart

syntax to declare array of strings (Hex commands) in c


I want to send the Hex commands below over uart to hardware attached to my mcu. I want to put them into an array and write them all at once as opposed to one at a time.

0x56
0x36
0x01

How do you declare this array in native c? Is it an array of strings?

This is the function to send the data.

uart_write_buff(const uart_t uart, const uint8_t *const data,
                 uint32_t len);

Solution

  • Do it like this:

    unsigned char data[] = { 0x56, 0x36, 0x01 };
    

    It is an array of bytes.

    Or better:

    uint8_t data[] = { 0x56, 0x36, 0x01 };