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

un-init and then re-init buarte_async module will report NRF_LIBUARTE_ASYNC_EVT_ERROR

Hi, support team 

       I need to realize two-wire uarte receiver(with low power), in the scenario there is no data come from TX in most time, so after receiving the data I need to un-initialize the uarte module and step into low-power mode. I choose libuarte sample on SDK16.0.0 + nrf52840 platform. the logic is like this :

      gpiote init(waiting port event)-> libuarte_async_init->received data until timeout -> libuarte_async_uninit->re-init gpiote (waiting for port event and new data)

      So I directly made some modification on our libuarte sample.

      First, I defined my instance as easy as possible:

           NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 1, 3);

      Then in my main loop, once gpio port event coming , myGPIOTE_EVENT_FLAG will be set, and then prepares to receive uarte data(un-init gpiote/init+enable libuarte_async) ; when the timeout event coming(myRX_DONE_FLAG be set) , it un-init libuarte_async module and re-init the two PORT to gpio mode(wait event). My main C file is here:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "nrf_libuarte_async.h"
#include "nrf_drv_clock.h"
#include <bsp.h>
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_queue.h"
#include "nrf_log.h"
#include "nrf_drv_gpiote.h"
volatile bool myGPIOTE_EVENT_FLAG=false;
volatile bool myRX_DONE_FLAG=false;
NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 1, 3);
volatile uint8_t myindex=0;
uint8_t rxdata_array[10]={0};
#define RXD_GPIOTE_PIN 26
#define TXD_GPIOTE_PIN 27
nrf_libuarte_async_config_t nrf_libuarte_async_config = {
.tx_pin = TXD_GPIOTE_PIN,
.rx_pin = RXD_GPIOTE_PIN,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I add an NRF_LIBUARTE_ASYNC_EVT_TIMEROUT event to inform the main loop that it ‘s time to change to gpio mode.

It defined in components\libraries\libuarte\nrf_libuarte_async.c => nrf_libuarte_async_timeout_handler(), I added the logic:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
......
if (capt_rx_count > p_libuarte->p_ctrl_blk->rx_count)
{
......//default code
}
else if(capt_rx_count = p_libuarte->p_ctrl_blk->rx_count){
nrf_libuarte_async_evt_t evt = {
.type = NRF_LIBUARTE_ASYNC_EVT_TIMEROUT
.data = NULL
};
p_libuarte->p_ctrl_blk->evt_handler(p_libuarte->p_ctrl_blk->context, &evt);
}
......
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In my test demo, I choose TX send 5Byte data each round and then sleep 10s, then sending 5Byte, then sleep…always looping .

     I run my RX code in nrf52840DK, The first round of receiving 5Byte data is right(in fact, in each round the first Byte is for triggering gpio port event , I do not care its detail), But when the second round of data coming, it reports error. like this :

Maybe before I un-init the module, I need to clear something or recover something to default?  so the next the re-init & receiving can becomes normal??

And also I'm not sure of the right using of timeout event.

Please help to give some advices, thanks!

BR

Smile

Top Replies