Uart.configure() issue


I have the following simple code to check if my BMG113 device (connected to an imp005 board) is being successfully being configured.

The device is connected through uart0. I have this simple code to check if the FIFO data is being stored in the buffer or not:

var <- hardware.uart0;
var.configure(115432, 8, 0, 1, 0);

The value in the log always shows -1 despite choosing different value settings and even the other 2 available board pins (uart1 and uart2), meaning FIFO is empty. Is it correct to assume that the device isn’t connected?

Is it possible that it might be physically connected but unable to be read because of some firmware issue?

Thanks for your time,




After you’ve configured the UART, the buffer will be empty unless a byte has been received in the time between the configure and your serial.log statement.

As UARTs are asynchronous, you can’t really tell the difference between an idle line (ie the other end has nothing to send you) and a line that isn’t connected. It’s very unlikely that the BGM module will be sending much data until you actually ask it something.

Even if it was sending, you’d still probably get -1 because there’s no time to receive a byte between when you configure the UART and when you try to read it.

If you did this:

var <- hardware.uart0;
var.configure(115200, 8, PARITY_NONE, 1, 0);

function poll() {
  imp.wakeup(1, poll);

Then it will print a byte every second. If you start this, see lots of -1’s, then power up the attached BGM113 you’ll likely see some other bytes come through if it sends some sort of welcome string.

(aside: it’s easier to read if you use the built-in constants, eg configure(115432, 8, PARITY_NONE, 1, 0), and I’m assuming you want to run at 115,200bps - baudrates aren’t necessarily perfectly accurate, you usually get within 1-2% though)

1 Like


Helpful and insightful, Hugo.

Thanks, truly.