I am testing the serial communication with Arduino like this:
timeStamp = 0xFFFFFFFF;
Serial.flush();
Serial.write((uint8_t*)timeStamp, 4)
On the other side, I am reading this byte with read(fd, &rx, 4)
in a C program. I expect to read always the same value, but instead of reading 0xffffffff
I have 0x370066bf
so there is a problem with decoding. Ps: I have set the serial port to read raw bytes, so there are no dedicated bytes to encode carriage return or other special characters.
I believe your problem is that your Serial.write((uint8_t*)timeStamp, 4)
always sends 4 bytes from memory starting with address 0xFFFFFFFF
. This is because timeStamp
is not a pointer, but you cast it to a pointer. Please try casting the address of timeStamp
instead: Serial.write(((uint8_t*)(&timeStamp)), 4);
and see if that works.
User contributions licensed under CC BY-SA 3.0