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

sd_app_evt_wait cause uart not work.

Hi, I use nrf52832's uart with a simple driver, not "nrf_drv_uart", because I don't know how to use receive and transmit interruption with "nrf_drv_uart". the uart drive i used is bellow:

void drv_uart_init(void)

 init_io();
 init_uart();
}

static void init_io(void)

 nrf_gpio_cfg_output(UART_TX);
 nrf_gpio_pin_set(UART_TX);
 nrf_gpio_cfg_input( UART_RX,NRF_GPIO_PIN_PULLUP);
}

static void init_uart(void)
{
 NRF_UART0->BAUDRATE = DEFAULT_BAUD;
 
 NRF_UART0->PSELTXD = UART_TX;
 NRF_UART0->PSELRXD = UART_RX;
 
 enable_interrupt();
 // ????
 NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled;
 NRF_UART0->TASKS_STARTTX = 1;
 NRF_UART0->TASKS_STARTRX = 1;
}

static void enable_interrupt(void)
{
 NRF_UART0->EVENTS_RXDRDY = 0;  
 NRF_UART0->INTENSET = (UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos)|(UART_INTENSET_TXDRDY_Enabled << UART_INTENSET_TXDRDY_Pos);
 
 NVIC_SetPriority(UART0_IRQn, 7);
    NVIC_ClearPendingIRQ(UART0_IRQn);
    NVIC_EnableIRQ(UART0_IRQn);
}

void UARTE0_UART0_IRQHandler(void)
{
 if(NRF_UART0->EVENTS_RXDRDY==1)
 {
  NRF_UART0->EVENTS_RXDRDY = 0;
  *m_p_rx_buf=NRF_UART0->RXD;
  m_p_rx_buf++;
  *m_p_rx_len=*m_p_rx_len+1;
 }
 if(NRF_UART0->EVENTS_TXDRDY==1)
 {
  NRF_UART0->EVENTS_TXDRDY = 0;
  if(m_tx_len>0)
  {
   NRF_UART0->TXD = *m_p_tx_buf;
   m_p_tx_buf++;
   m_tx_len=m_tx_len-1;
  }
 }
}

In the idle hook function, I call nrf_pwr_mgmt_run(), as follows:

void vApplicationIdleHook( void )
{
  nrf_pwr_mgmt_run();
}

when I remove "nrf_pwr_mgmt_run();", or remove "ret_code_t ret_code = sd_app_evt_wait();" in the nrf_pwr_mgmt_run function, the uart can work correctly,  I can receive all data on my computer, but when i use "nrf_pwr_mgmt_run" or "sd_app_evt_wait", the uart cannot work, i receive no data on my computer.

why?

Parents Reply Children
Related