Sending AT Commands


i’m trying to send commands to my SHIELD following the AT protocol.
I have the following hardware.

  • DISCO-L475VG-IoT-01A
  • Shiratech IoT Shield with the quectel BG96

My simplified code looks like this.

#include "mbed.h"

#include "ATCmdParser.h" 

#include "UnbufferedSerial.h"

ATCmdParser *at;

UnbufferedSerial *us;

int main()


    printf("\nAT Commando's \n\n");

    us = new UnbufferedSerial(D1, D0);

    at = new ATCmdParser(us, "\r\n");

    char buffer[1024];

    // Enable debugging.


    // Set to default timeout of the quectel. 


    // Send this line to the AT.


    // Received ok? 

    if (at->recv("OK")){

        printf("[AT+GMI=?] Returned result %s", buffer);

    } else {

        printf("[AT+GMI=?] Request failed");



And this is the result im getting:


(NOTE: it does not print my result).

Please help me :slight_smile:

Hello Koen,

I’m not sure why (most likely because the serial console used for debugging and the UnbufferedSerial used for communication with the modem share the same serial line) but appending \r\n as below could help:

printf("[AT+GMI=?] Request failed\r\n");

Few additional comments:

  • According to the user manual the communication with the shield is based on the UART protocol using a baud rate of 115200 baud. So after creating an UnbufferedSerial object change the bit rate:
us = new UnbufferedSerial(D1, D0);
  • I’m not sure how the ATCmdParser's debug feature works but because the DISCO’s serial console is connected to same pins (serial line) as the Shiratech shield UART you’d probably need to adjust it’s speed too using an mbed_app.json configuration file. For example:
    "target_overrides": {
        "*": {
            "platform.stdio-baud-rate": 115200

Best regards, Zoltan

Hey Zoltan,

I now do indeed get a return, but sadly it is an Request Failed.
On your comment on the baudrate. that should be all the same now.
Do you have any idea how I can make it work?

Best regards,


Hello Koen,

Since the serial console shares the serial line with the shield you can try to send AT commands to the shield manually from the serial terminal running on your PC without having the ST MCU on the DISCO board involved:

  • Disconnect the shield from the DISCO board.

  • Connect the shield to the DISCO board with wires as follows:

| DISCO | Shield |
| D0    | D1     |
| D1    | D0     |
| GND   | GND    |
| +5V   | +5V    |
| +3.3V | +3.3V  |
  • Program your DISCO board to do nothing. For example:
#include "mbed.h"

int main() {}
  • Set the serial terminal speed to 115200 and configure it to append a “carriage return + new line” to the message to be sent.

  • Send an AT command manually by typing it to your serial monitor. For example:


Hit ENTER or click on the “Send” button (depends on the used serial terminal).

  • The shield’s response, if any, should be then sent back to the serial terminal.

  • If it works remove the wires and plug the shield to the DISCO board.

  • Try your program again but remove/comment out:


Best regards, Zoltan

Hey Zoltan,

The commant above has not been working out as expected.
I connected the wires like u told me to, it seems to power on, but not communicate.
I’ve tried to send commands via the terminal, but is doesn’t pick them up. with the shield placed normally and following your suggestion.
Also i’ve tried my other program that should be able to connect to the BG96, but also there inline terminal command’s are not received.

Do you have any other suggestions, because i cannot figure this out.

Best regards,

– update –
Thanks to a colleague I now have an ATHandler, this should be able to send a command to the modem.
I can see it appear in the modem logs, but it still doesn’t respond to it.

Hello Koen,

If you have an Arduino Uno try to follow the steps suggested in section “4. Using the Shield for the First Time” of the user manual.

Best regards, Zoltan

I Managed to solve it.
My final code is the following:

#include “mbed.h”

#include <MQTTClientMbedOs.h>

#include "CellularContext.h"

#include "CellularInformation.h"

#include "CellularLog.h"

int main()


    CellularInterface  *net = CellularInterface::get_default_instance();

    CellularDevice * dev = CellularDevice::get_default_instance();

    ATHandler * devat = dev->get_at_handler();






"target_overrides": {

        "*": {

            "platform.memory-tracing-enabled": true,

            "platform.stdio-baud-rate"                  : 115200,

            "platform.stdio-convert-newlines"           : true,

            "platform.stdio-buffered-serial"            : true,

            "platform.stdio-flush-at-exit"              : true,

            "rtos.main-thread-stack-size"               : 5120,

            "events.shared-stacksize"                   : 2048,

            "events.shared-eventsize"                   : 2048,

            "mbed-trace.enable"                         : true


        "DISCO_L475VG_IOT01A": {

            ""     : "CELLULAR",

            "ppp.ipv4-enabled": false,

            "ppp.ipv6-enabled": true,

            "lwip.ipv4-enabled": true,

            "lwip.ipv6-enabled": true,

            "lwip.ethernet-enabled": false,

            "lwip.ppp-enabled": false,

            "lwip.tcp-enabled": true,

            "nsapi.default-cellular-apn": "\"\"",

            "nsapi.default-cellular-username": "\"\"",

            "nsapi.default-cellular-password": "\"\"",

            "cellular.debug-at": true,

            "QUECTEL_BG96.provide-default": true,

            "QUECTEL_BG96.tx": "D1",

            "QUECTEL_BG96.rx": "D0",

            "QUECTEL_BG96.pwr": "A5",

            "QUECTEL_BG96.rst": "A4",

            "QUECTEL_BG96.polarity": 1