7 years ago.  This question has been closed. Reason: Duplicate question

Serial2 not working on Nucleo L476RG

Hi,

I am currently Arduino users and I was able to communicate with Ublox Neo-6M module successfully with Arduino Uno R3 board using TinyGPS++ Arduino AVR library. Now, my requirements are changed and one of them performance and memory requirements hence I have selected Nucleo L476RG board as it supports mebd library.

I was able to successfully testing , Digital I/0, PWM, ADC, DAC, etc., but I could not get Serial2 (PA_2 and PA_3) connecting Ublox module using mbed library.

Also note that Ublox connected via separate 3.3 V power supply with common ground.

I have attached the code for your reference.

Appreciate if you could assist on how to troubleshoot this issue as I am not sure problem with Nucleo board or anything else.

mbed Code

#include "mbed.h"
#include "Ublox.h"

DigitalOut myled(LED1);
 
Serial pc(USBTX, USBRX);
Serial gps(PA_2, PA_3);  // tx, rx
Ublox ublox;

void processGPS()
{
    if(gps.readable()) {
        char c = gps.getc();
        ublox.encode(c);
    }
}
    
int main() {
    pc.baud(9600);
    pc.format(8,SerialBase::None,1);
    myled=1;
    gps.attach(&processGPS, Serial::RxIrq);
    
    pc.printf("lat,");  
    pc.printf("long,");
    pc.printf("time\r\n");
    
    while(1) {
        pc.printf("%f,", ublox.latitude);  
        pc.printf("%f,", ublox.longitude);
        pc.printf("%d/%d/%d - %d:%d:%d\r\n", 
            ublox.datetime.year, 
            ublox.datetime.month, 
            ublox.datetime.day, 
            ublox.datetime.hours+8, 
            ublox.datetime.minutes,
            ublox.datetime.seconds);
        myled = !myled;
        wait(1);
    }
}

1 Answer

7 years ago.

Unless you are using the BufferedSerial library (here at mbed) I believe you are not allowed to call getc() within the interrupt handler. Alternatively you can set a global volatile variable and do your getc in the main while loop.

Accepted Answer