UART configuration causes hang

14 Dec 2018

Hi,

I asked this as a question a while back, but never had a response - was hoping someone here could help me out..?

I am using FRDM-KW41Z and need to be able to communicate over UART using a specific parity/stop bit configuration. However, when I add the call to Serial::format(), the UART just hangs indefinitely when I try to send anything (but is fine if I don't call it). Here's some example code...

#include "mbed.h"
#include <SerialBase.h>

Serial uart(PTC7, PTC6, 9600); // tx, rx
InterruptIn button3(SW3);
DigitalOut led(LED_BLUE);

EventQueue queue(32 * EVENTS_EVENT_SIZE);
Thread t;

void send() {
    led = 0;  //execution gets stuck after this
    uart.printf("test");
    led = 1;
}

int main() {
    led = 1;
    uart.format(8, SerialBase::Even, 1); //adding this causes the problem
    t.start(callback(&queue, &EventQueue::dispatch_forever));
    button3.rise(queue.event(send));
}

Any idea what I am doing wrong? The LED turns on, but then nothing is sent and the LED never turns off again.

15 Dec 2018

I tried ur code on NUCLEO_F303RE. It works well.

You should export it to your ide and put your board into debug mode. It will gives you more information. It can help you pinpoint where exactly the mcu is stuck.