11 months, 3 weeks ago.

Why does calling Serial format() cause UART to hang?

Hi,

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.

Thanks! Joel

One commentor in the forum said they tried this code on a different board and it works OK - could this just be a bug in the implementation of mBed for KW41Z?

posted by Joel Lurcook 11 Jan 2019
Comment on this question
Be the first to answer this question.

You need to log in to post a question