C030-R412m: No serial monitor output

Hi!

I’m a beginner with Mbed and have purchased the C030-R412m target. Even simple applications are impossible to run and cannot understand why.

  • Target is detected right and successful connected (green symbol) in Mbed Studio.
  • Empty Mbed program successfully created.
  • Build profile is Develop.
  • OS mbed-os-5.15.6 is installed in libraries.
  • Switch on target is on position 2 (default).
  • Serial monitor baud rate 9600 or 115200.

Her my code:

#include "Serial.h"
#include "mbed.h"

Serial rs(PD_8, PD_9); // Arduino Serial pinout.

void rs_recv() {
    while(rs.readable()) {
        printf("%d", rs.getc());
    }
}

int main() {
    printf("Hello!");

    rs.baud(115200);
    rs.attach(&rs_recv, Serial::RxIrq);

    while (true) {}
}

The program compiles without errors and after run i get no output on the serial monitor.

  • No “Hello!”.
  • No data from serial “rs”.
  • Nothing!

I have tried different things without success. This is very frustrating. I’m familiar with the Arduino family, where simplest programs work out of the box. So, what I’m doing wrong?

How can I connect to UART3 (Arduino Uno R3 Interface)? Is this the right way: Serial rs(PD_8, PD_9); ?

Hello,

there differencis between

the first one, without object rs will put your string to default debug console under default 9600

 printf("%d", rs.getc());

and second one will put your string to pins what you have set in constructor of rs object, under 115200

rs. printf("%d", rs.getc());

BR, Jan

2 Likes

Thx! This helps me to understand better how printf works.

How can I instantiate the USB debug serial for my target? Is this correct?

Serial pc(USBTX, USBRX);

According to u-blox C030-R412M LTE CatM1/NB1 and 2G | Mbed, the board include on-board debuger → ST-link.
If you not have installed drivers for ST-link’s VCP, then download it from ST web pages and then just check the COM port of ST-link in your PC device management.

Yes, Serial pc(USBTX, USBRX); is correct - ST-link pins
Anyway, if you will use it in default configuration, then just use the printf without object of Serial class.

BR, Jan

1 Like

Thank you very much!!! Very important informations for my first steps. Now some parts are working. But not the rs.attach(): Mutex: Not allowed in ISR context. I need to read more about this error.

No problem.

All methods (Serial class =printf, putc, getc and so on) what manipulate with data are protected with Mutex in RTOS. So it is unusable in ISR alone.

  • You can workaround it with EventQueue.
  • Alternatively if you not need RTOS functionality then you can try Bare metal profile = no RTOS = no Mutex.
  • If you want RTOS and interrupts, then use RawSerial. Here is the protection by Mutex off, but you must protect your data by your self.

BTW this rules about Mutex are applied also for another APIs - I2C, SPI, CAN and so on.

BR, Jan

1 Like

I understand. Strange, I want only to read data from serial (PD_8, PD_9) and print the data to the serial monitor. Mutex, event queue, etc. for this simple task? OK, then so be it. :sweat_smile:

Hi @JohnnyK.

Any idea what I’m doing wrong? I get no output on the serial monitor. Whit a second Arduino I send data to the serial Arduino poinout of my target (PD_8 and PD_9). But printToMonitor don’t output anything received from serial rs.

#include "RawSerial.h"
#include "mbed.h"

EventQueue *queue = mbed_event_queue(); 

RawSerial rs(PD_8, PD_9); // Arduino Serial pinout.

void rsRecv();

void printToMonitor() {
    printf("Text received %c\n\r", rs.getc()); // Print to serial monitor.
    rs.attach(&rsRecv, Serial::RxIrq);  // Re-attach to Irq.
}

void rsRecv() {
    rs.attach(NULL, Serial::RxIrq); // Detach from Irq.
    queue->call(printToMonitor); // Process in a different context.
}


int main() {
    printf("Hello World!");

    rs.baud(115200);
    rs.attach(&rsRecv, Serial::RxIrq);

    queue->dispatch_forever();
}

SOLVED THIS ISSUE

Bad baudrate between second Arduino (sender) and target C030 (receiver) . Setting the same baudrate on both sides solves the issue on this simple test code. :star_struck: :man_dancing:

Here another simple test:

#include "RawSerial.h"
#include "mbed.h"

RawSerial rs(PD_8, PD_9); // Arduino Serial pinout.

int main() {
    printf("Hello World!");

    rs.baud(115200);

    while(true) {
        if (rs.readable()) {
            printf("Text received %c\n\r", rs.getc());
        }
    }
}

Serial monitor shows “Text received” any time I send a char from second Arduino to the target, but %c is still empty. So, if I send f, the target receives the data and rs.readable() triggers but rs.getc() is empty and only message “Text received” is shown in serial monitor.

SOLVED THIS ISSUE

Bad baudrate between second Arduino (sender) and target C030 (receiver) . Setting the same baudrate on both sides solves the issue on this simple test code. :star_struck: :man_dancing: :partying_face:

Hello,

at first look, I see nothing wrong but currently I can not test it, maybe later.

Just for clarification… You try to send some data via SerialMonitor to, or directly from Arduino. Arduino is connected via its UART (with common ground and cross wired - TX->RX & RX->TX) to UART of Ublox and then you check the result on SerialMonitor what is connected to ST-link’s VCP. That is right?

BR, Jan

What I’m doing:

  • Arduino Mega → Sender
  • MBed Target Ublox C030-R412m → Receiver

Workflow

  1. Serial Monitor of Arduino Mega → Setup OK
  2. Input char with keyboard → OK
  3. Arduino passes the data to Arduino Serial → OK
  4. Arduino serial (Sender) sends data to target (Receiver) → OK
  5. Target serial (PD_8, PD_9) triggers readable() → OK
  6. Output data to targets serial monitor → ???

The Arduino code works fine. Because I have tested the data transmission from Arduino to Arduino. And theoretically it should also work for Arduino to Ublox C030.

See solutions above!

@JohnnyK many thanks for your important info and help that you gave me for my first Mbed program!

Please allow me to ask one more question. What is the best practice if I have different data sources (serial, i2c, Gnss, etc.) that periodically sends data to my target and the target should evaluate incoming data and send this data over MQTT? Should every source be handled in an own thread? Did you know an open source project where I can learn from?

You’re welcome

About your next question I recommend starting a new topic, beacuse it is out of the issue about Serial and also I am not an expert :slight_smile:
Basically, you want to keep it as simple as possible but it depend on your application and requirements.
For start you can place all to the main, collect data one by one (like Arduino) and then send it. It will be better for debug and test all peripherals. Later when you see it’s slow or something, you can add Threads or EventQueue.

BR, Jan

1 Like