Serial2 not working on Nucleo L476RG

STM32F103 Nucleo boards e.g. STM Nucleo F103RB
Post Reply
dhamukrish
Posts: 5
Joined: Thu Apr 06, 2017 10:54 am

Serial2 not working on Nucleo L476RG

Post by dhamukrish » Fri Apr 07, 2017 4:36 am

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 Arduino STM32 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 ArduinoSTM32 libraries.

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.

Code: Select all

#include <TinyGPS++.h>
TinyGPSPlus gps;
void setup()
{
    Serial.begin(9600);
    Serial2.begin(9600); // Nucleo D0 RX <-> Ublox TX, Nucleo D1 TX <-> Ublox RX
    Serial.println(F("DeviceExample.ino"));
    Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
    Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
    Serial.println(F("by Mikal Hart"));
    Serial.println();
}
void loop()
{
    // This sketch displays information every time a new sentence is correctly encoded.
    while (Serial2.available() > 0)
        if (gps.encode(Serial2.read()))
            displayInfo();
        
    if (millis() > 5000 && gps.charsProcessed() < 10)
    {
        Serial.println(F("No GPS detected: check wiring."));
        while(true);
    }
}
void displayInfo()
{
    Serial.print(F("Location: "));
    if (gps.location.isValid())
    {
        Serial.print(gps.location.lat(), 6);
        Serial.print(F(","));
        Serial.print(gps.location.lng(), 6);
    }
    else
    {
        Serial.print(F("INVALID"));
    }
    
    Serial.print(F(" Date/Time: "));
    if (gps.date.isValid())
    {
        Serial.print(gps.date.month());
        Serial.print(F("/"));
        Serial.print(gps.date.day());
        Serial.print(F("/"));
        Serial.print(gps.date.year());
    }
    else
    {
        Serial.print(F("INVALID"));
    }
    Serial.print(F(" "));
    if (gps.time.isValid())
    {
        if (gps.time.hour() < 10) Serial.print(F("0"));
        Serial.print(gps.time.hour());
        Serial.print(F(":"));
        if (gps.time.minute() < 10) Serial.print(F("0"));
        Serial.print(gps.time.minute());
        Serial.print(F(":"));
        if (gps.time.second() < 10) Serial.print(F("0"));
        Serial.print(gps.time.second());
        Serial.print(F("."));
        if (gps.time.centisecond() < 10) Serial.print(F("0"));
        Serial.print(gps.time.centisecond());
    }
    else
    {
        Serial.print(F("INVALID"));
    }
    Serial.println();
}


edogaldo
Posts: 281
Joined: Fri Jun 03, 2016 8:19 am

Re: Serial2 not working on Nucleo L476RG

Post by edogaldo » Fri Apr 07, 2017 7:25 am

First of all, which core are you using? The Grumpy core or the STM core? This info is important in order to know the corresponding Serial<->USART mappings..
Furthermore, did you check the Nucleo L476RG documentation? Are you aware that PA2 and PA3 are not connected ootb to the CN9 and CN10 connectors and you have to follow the procedure specified in order to connect them?

Best, E.

dhamukrish
Posts: 5
Joined: Thu Apr 06, 2017 10:54 am

Re: Serial2 not working on Nucleo L476RG

Post by dhamukrish » Fri Apr 07, 2017 9:08 am

Thanks edogaldo for your reply.

I guess STM core (version 2017.1.19) and I have configured below link in Arduino preference.
https://github.com/stm32duino/BoardMana ... index.json

Moreover, I can see this below from documentation and requires board alteration.
Hence, is there any other way to use any other Serial ports without alteration as breaks ST-Link?
The USART2 interface available on PA2 and PA3 of the STM32 microcontroller can be
connected to ST-LINK MCU, ST morpho connector or to Arduino connector. The choice can
be changed by setting the related solder bridges. By default the USART2 communication
between the target STM32 and ST-LINK MCU is enabled, in order to support virtual COM
port for mbed (SB13 and SB14 ON, SB62 and SB63 OFF). If the communication between
the target STM32 PA2 (D1) or PA3 (D0) and shield or extension board is required, SB62 and
SB63 should be ON, SB13 and SB14 should be OFF. In such case it is possible to connect
another USART to ST-LINK MCU using flying wires between ST morpho connector and
CN3
Please forgive me if I ask silly question as I am very new to STM32 world.

edogaldo
Posts: 281
Joined: Fri Jun 03, 2016 8:19 am

Re: Serial2 not working on Nucleo L476RG

Post by edogaldo » Fri Apr 07, 2017 9:50 am

Ok, so, it looks like you are using the STM core.

Now, in the STM core, the Serial mappings are:

Code: Select all

UARTClass Serial(USART2_E);    //available on PA2/PA3
UARTClass Serial1(USART1_E);   //available on PA9/PA10
USARTClass Serial2(USART2_E);  //available on PA2/PA3
USARTClass Serial3(UART4_E);   //available on PA0/PA1
(cfr. variants/STM32L476RG_Nucleo/variant.cpp)

On the other end, on Nucleo boards USART2 (PA2 and PA3) are connected ootb to the STLink VCP so you should be able to:
  • use Serial (USART2 - PA2/PA3) for debug purpose.
  • use Serial1 (USART1 - PA9/PA10) or Serial3 (UART4 - PA0/PA1) - you should be able to find them in the connectors - for your GPS device
Best, E.

PS: please also note that in the STM core both Serial and Serial2 map to the same USART2 device.

dhamukrish
Posts: 5
Joined: Thu Apr 06, 2017 10:54 am

Re: Serial2 not working on Nucleo L476RG

Post by dhamukrish » Fri Apr 07, 2017 10:32 am

Great edogaldo and it is working with Serial1 now, I will test Serial3 and post if any issue.

Also noticed that below pin diagram is confusing as Serial1 mentioned thrice.
https://developer.mbed.org/media/upload ... 6_7_22.png

Anyway, thanks again.

Post Reply