This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

app_uart_put() before NVIC_SystemReset()

Hi,

I'm trying to send out 3 bytes just before I reset the chip. I am using nRF51, SD 130 1.0 and SDK v10.0.0. UART works well in other parts of code.

My original solution was:

    app_uart_put(0x01);
	app_uart_put(0x02);
	app_uart_put(0x03);
	
	app_uart_flush();	
	NVIC_SystemReset();

but I only see 0x01 sent out. So the reset must be happening too fast. I tried multiple versions of above snippet, trying to send out all bytes before reset, but none works. This one is very hardcore and I really have no explanation why I see only first byte, but not others:

    app_uart_put(0x01);
	nrf_delay_ms(1);
	app_uart_put(0x02);
	nrf_delay_ms(1);
	app_uart_put(0x03);
	nrf_delay_ms(1);
	
	app_uart_flush();
	
	nrf_delay_ms(500);		
	NVIC_SystemReset();

What is happening here? How can I send out three bytes via UART before reset?

Parents
  • Hi

    In the first solution I think it is pretty obvious that you get an overflow. app_uart_put() is a non-blocking function as documented in app_uart.h. This means that you can't call it one after another like that before you are certain the first byte is transmitted. The first byte, however should be transferred without a problem.

    Regarding the second solution; what baudrate do you use? If you use e.g. 9600 the transmission of a byte will actually take ~1 ms. So with only 1 ms pause you might still get an overflow. It works on my system though. Did you try longer pauses?

    You can wait until the UART is ready like this:

    while(app_uart_put('a'))
       ;
    while(app_uart_put('b'))
       ;
    while(app_uart_put('c'))
       ;
    

    although this will block your application if something goes wrong so it is not very elegant. So the best thing would probably be to look into app_uart_fifo which allows you to send strings.

Reply
  • Hi

    In the first solution I think it is pretty obvious that you get an overflow. app_uart_put() is a non-blocking function as documented in app_uart.h. This means that you can't call it one after another like that before you are certain the first byte is transmitted. The first byte, however should be transferred without a problem.

    Regarding the second solution; what baudrate do you use? If you use e.g. 9600 the transmission of a byte will actually take ~1 ms. So with only 1 ms pause you might still get an overflow. It works on my system though. Did you try longer pauses?

    You can wait until the UART is ready like this:

    while(app_uart_put('a'))
       ;
    while(app_uart_put('b'))
       ;
    while(app_uart_put('c'))
       ;
    

    although this will block your application if something goes wrong so it is not very elegant. So the best thing would probably be to look into app_uart_fifo which allows you to send strings.

Children
Related