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.
8 years, 3 months ago.
How should I use the NUCLEO STM32L053R8's Serial 3 to communicate with another board ?
Hi,
I'm trying to use the Serial 3 TX/RX pins to send data to another board, but I can't figure how to configure it in my mbed code.
Can anyone help me ?
I know it's a low power UART, so, should I only use two boards which offer LPUARTs or can I make a "standard" UART send data to the L053R8 LPUART ?
Here's what I've tried
using it like this works
Serial lpuart(PC_10,PC_11); lpuart.baud(9600); Serial pc(USBTX, USBRX); pc.baud(9600); char read = 0; while(1) { if(lpuart.readable()) { read = lpuart.getc(); pc.printf("read %c\r\n", read); ++read; wait(0.2f); } if(lpuart.writeable()) { lpuart.putc(read); wait(0.2f); } }
Here, the values returned are correct.
using it like this doesn't works
Serial uart(PA_9, PA_10); // Serial 1 uart.baud(9600); Serial lpuart(PC_10,PC_11); // Serial 3 lpuart.baud(9600); Serial pc(USBTX, USBRX); pc.baud(9600); char read = 33; //UART -> LPUART while(1) { // UART1 send if(lpuart.writeable()) { uart.putc((read)); pc.printf("LPUART writeable, UART sent: %c(%d)\r\n", read, read); wait(0.2f); } // LPUART read if(lpuart.readable()) { pc.printf("LPUART should read: %c(%d)\r\n", read, read); read = lpuart.getc(); pc.printf("LPUART read: %c(%d)\r\n", read, read); ++read; wait(0.2f); } }
But here, they're not, and seem to always cycle through the same incorrect pattern
Question relating to:
3 Answers
8 years, 3 months ago.
Hi, I've been able to reproduce the issue so I logged it here: https://github.com/mbedmicro/mbed/issues/2074 I think I may a fix ... so I will push a Pull Request that maybe you could test. cheers
Hi, and thanks for your fix, I'll try it as soon as I can and keep you informed!
posted by 30 Jun 2016if you want to test the fix in advance, it's here: https://github.com/LMESTM/mbed/commit/0bc9d157a0fd7e8ef203122aac7822d4af21a595
posted by 30 Jun 20168 years, 3 months ago.
Looks like you are checking the wrong writable channel in the second example. This could still work but may not be what you want. I am guessing you loopback TX1 to RX3. Make sure you have the correct pins wired,
... //UART -> LPUART while(1) { // UART1 send // if(lpuart.writeable()) { //<= wrong if(uart.writeable()) { //<= correct uart.putc((read)); // pc.printf("LPUART writeable, UART sent: %c(%d)\r\n", read, read); //<= wrong pc.printf("UART writeable, UART sent: %c(%d)\r\n", read, read); //<= correct wait(0.2f); } // LPUART read ...
Thanks for your answer, and sorry to forget mentioning this code was to try looping back using the same board pins. Regarding my example, thanks for pointing out my mistake, yours is what I was looking for, but unfortunately the problem is still present.
This code was written to find out where the problem was coming from. In the main program I'm writting, more boards and expansion shields are actually used. So for now I can't really use other ports and I'm stuck with the ones of the Serial 3.
Any other ideas ?
posted by 29 Jun 20168 years, 3 months ago.
Hello,
You are right, the baudrate configuration of the lpuart seem off by a ratio 2 in mbed library.
unexpectedly, the following code works with Mbed library Release 121:
lpuart baud rate issue test code
#include "mbed.h" Serial uart(PA_9, PA_10); // Serial 1 Serial lpuart(PC_10,PC_11); // Serial 3 Serial pc(USBTX, USBRX); int main() { uart.baud(9600); lpuart.baud(19200); pc.baud(9600); char read = 33; //UART -> LPUART while(1) { // UART1 send if(uart.writeable()) { uart.putc((read)); pc.printf("UART writeable, UART sent: %c(%d)\r\n", read, read); wait(1.0f); } // LPUART read if(lpuart.readable()) { pc.printf("LPUART should read: %c(%d)\r\n", read, read); read = lpuart.getc(); pc.printf("LPUART read: %c(%d)\r\n", read, read); ++read; wait(1.0f); } } }