I’m trying to use the following codes to establish communication between two boards. However the results are “Not readable” and “Not writeable.” What could be the potential problem?(mbed-os-5.15)
#include “mbed.h”
Serial uart(D1,D0);
int main()
{
char data={‘A’,‘B’};
while(1)
{
if(uart.writeable())
uart.puts(data);
else
printf(“Not writeable.\n”);
}
}
I’ve found the problem. The interior of one line is broken… What a joke… But new problem occurs. I change the data to
char data={‘A’,‘B’,‘C’,‘D’,‘E’,‘F’};
The reciever is tested under different parameters.
For: uart.gets(data,6); The result is EABCD. I guess the problem is related to ‘\0’
For: uart.gets(data,7);The result is FABCDE. Still wrong about the order.
How do I fix it?
Is good to have a starting and/or ending delimiter (example !mystring\n) and make a logic around. Instead of gets use getc in a loop, colect byte per byte into a buffer and check these delimiters until the right one comes.
I usually use getc() until receive \n, then know this is end of message.