Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 3 months ago.
UARTSerial does not write bytes
Hi all,
I have the following code:
first code
int main() {
DigitalOut led(LED1);
UARTSerial pc(USBTX, USBRX, 921600);
while (true) {
char r = 0;
char w = 10;
led.write(1);
pc.read(&r, 1);
led.write(0);
wait(0.1);
pc.write(&r, 1);
pc.sync();
}
return 0;
}
The problem is that if I leave the code as it is it writes -1 on serial.
If I change the write call to send the w variable I simply don't read anything from the pc.
second code
int main() {
DigitalOut led(LED1);
UARTSerial pc(USBTX, USBRX, 921600);
while (true) {
char r = 0;
char w = 10;
led.write(1);
pc.read(&r, 1);
led.write(0);
wait(0.1);
pc.write(&w 1); // changed the variable
pc.sync();
}
return 0;
}
What is the problem?
Thank you.
1 Answer
6 years, 3 months ago.
Hi Noè,
It seems you miss a comma in your code, your code snippet is
pc.write(&w 1);, I believe it should be
pc.write(&w, 1);
Let me know if you have any questions.
Thanks,
Desmond