-1

I'm having trouble writing a hex string for UART. I can send a single byte, for example:

 UART2_Write(0x80);

I'm now needing to do a full hex string so something like the following:

 UART2_Write(0x80, 0x70, 0xAD, etc)

Can anyone help? Do I need to create a string and send the string over UART? Any help is much appreciated :)

Finners
  • 37
  • 7

1 Answers1

0

You can only write one byte, so you have to write one byte at a time. For example like this:

void UART2_Write_string(unsigned char * data, int data_len)
{
    for (int i = 0; i < data_len; i++) {
        UART2_Write(data[i]);
    }
}

You can use the function like this:

unsigned char text1[] = "This is a text I want to print";
unsigned char data1[] = {0x80, 0x70, 0xAD};

UART2_Write_string(text1, sizeof(text1));
UART2_Write_string(data1, sizeof(data1));

This will send through the UART the information in text1 and the information in data1.