I have to send an array of data between a nucleo f446re and a pc with ubuntu using the UARTSerial class.
The code that I'm using on the mbed is the following:
int main() {
UARTSerial pc(USBTX, USBRX, 921600);
uint8_t buff[256] = {
5, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4
};
pc.sync();
while(true) {
pc.write(buff, 23);
pc.sync();
wait(1);
}
return 0;
}
The code that I'm running on the pc is:
int main() {
struct termios tattr{0};
// open the device in read/write sync
int com = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_SYNC );
if (com == -1)
throw std::runtime_error("ERROR: can't open the serial");
tcgetattr(com, &tattr);
tattr.c_iflag &= ~(INLCR|IGNCR|ICRNL|IXON);
tattr.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET);
tattr.c_cflag = CS8 | CREAD | CLOCAL;
tattr.c_lflag &= ~(ICANON|ECHO);
tattr.c_cc[VMIN] = 1;
tattr.c_cc[VTIME] = 0;
tattr.c_ispeed = 921600;
tattr.c_ospeed = 921600;
tcsetattr (com, TCSAFLUSH, &tattr);
while (true) {
usleep(1000);
tcflush(com, TCIOFLUSH);
uint8_t buff[24];
::read(com, buff, 23);
printf("reading frame... ");
for (auto b : buff) {
printf("%02X ", b);
}
puts("\n");
}
}
The output that I receive on the pc is:
[...]
reading frame... 00 00 8D 9C 1E 7F 00 00 00 00 00 00 00 00 00 00 70 5B C7 01 AD 55 00 00
reading frame... 00 00 8D 9C 1E 7F 00 00 00 00 00 00 00 00 00 00 70 5B C7 01 AD 55 00 00
[...]
As you can see the result is not the same that I'm expecting.
I've already tried to send one byte at a time with a loop, but the result is the same.
I cannot understand why I can't read the USB I've tried to flush the usb both on the pc and on the nucleo board.