6 years, 10 months ago.

"Serial" port constructor function blocks the MCU of NRF51822 (old MBED library)

Hello,

A little disclaimer at first: I am using some old version of mbed library (from July 2015 I guess) in an already existing project and thus I must keep to it. Maybe it is a known bug to some version of mbed?

I have a problem with using UART on my NRF51822 module. Simply put, this program works (a led lights):

#include "mbed.h"

DigitalOut led1(p8, 1);


int main(void)
{
	while(1);
}

...and this one doesn't :

#include "mbed.h"

DigitalOut led1(p8, 1);

Serial uart(TX_PIN_NUMBER, RX_PIN_NUMBER);

int main(void)
{
	while(1);
}

So it's cleraly the line defining serial port that creates problems. I have no clue what might be wrong here... will appreciate any help.

1 Answer

6 years, 10 months ago.

Hello Jakub,
According to the platform info pin p8 is used also for Serial flow control (RTS). It could happen that the Serial constructor sets RTS (pin p8) status and overwrites the status set before by the DigitalOut constructor. Try to swap the two lines as follows:

#include "mbed.h"
  
Serial uart(TX_PIN_NUMBER, RX_PIN_NUMBER);

DigitalOut led1(p8, 1);
 
int main(void)
{
    while(1) {};
}

Or try to set p8 again in the main function:

#include "mbed.h"
 
DigitalOut led1(p8, 1);
 
Serial uart(TX_PIN_NUMBER, RX_PIN_NUMBER);
 
int main(void)
{
    led1 = 1;

    while(1) {};
}

NOTE: Unfortunately I do not possess a nRF51822 board so I was not able to test it.

Thank you.

Actually I've just found a real problem - my Eclipse was using a library for TARGET_NRF51822_SDK instead of _MDK, which has different pin assignments! So the initialising function probably thrown an error that would reset the MCU.

I guess I should now apologise for wasting your time (such a stupid mistake!). But I still thank you for a note about p8 pin as I had problems with this LED anyways... changed the pin and now everything seems fine.

posted by Jakub K 12 Jun 2017