8 years, 5 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:

Affordable and flexible platform to ease prototyping using a STM32L053R8T6 microcontroller.

3 Answers

8 years, 5 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

Accepted Answer

Hi, and thanks for your fix, I'll try it as soon as I can and keep you informed!

posted by Ausy AER 30 Jun 2016

if you want to test the fix in advance, it's here: https://github.com/LMESTM/mbed/commit/0bc9d157a0fd7e8ef203122aac7822d4af21a595

posted by Laurent Meunier 30 Jun 2016
8 years, 5 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 Ausy AER 29 Jun 2016
8 years, 5 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);
        }
    }
}

Thanks for your answer, I've tested it and it works using only one L0. I think it should also with multiple boards, but for now I can't do more testing, I'll keep you guys informed next week. Thanks!

posted by Ausy AER 30 Jun 2016