Hello,

I am writing a program on si. I want to transfer the following sequence of bytes to the uart: "0x1F 0x10 0x00 0x01 0x00 0x01". Because There is no byte type in C, I use char.

The program looks something like this:

char str[6]= {31, 16, 0, 1, 0, 1 }; printf("%s\n", str); 

The problem is that I output this sequence to the terminal of the serial port and it outputs only 0x1F 0x10, because '0' is the end of line character, so he thinks that the line ends and cuts off the rest.

Can you please tell whether it is possible to output the entire line with zero to the terminal together, i.e. so that zero is not the end of the line?

I use the termite terminal.

Thank you all for the answers.

The problem was solved with the use of not an array of char characters but an array with type uint8_t (analogous to byte in C ), which is located in the library stdint.h . Program Code:

  #include <stdint.h> uint8_t str[6] = {0x1F, 0x10, 0x00, 0x01, 0x00, 0x01}; fwrite(str,sizeof(str),1,stdout); 

Thank you very much, gbg , for your help.

  • 3
    Print a sequence of characters, not as an ASCIIZ string. - PinkTux 4:05 pm
  • @PinkTux, thanks for the answer, for some reason it didn’t work for me by character, it displays an error. Maybe I am doing something wrong, but this command, for example, does not work: * printf ("% c \ n", 'A'); *. (the compiler displays an error) - foxis
  • In general, uint8_t is a typedef unsigned char uint8_t . your KO - Yaroslav

1 answer 1

The first. The type of bytes in C is and is called uint8_t . Lives in stdint.h

The second. Use fwrite(str,sizeof(str),1,stdout);

  • 2
    Thank you very much, it all worked. Now I will keep in mind that uint8_t is an analogue of byte . Thanks again, gbg . - foxis