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

UART0 Interrupt stops after some time

Hi , I am using S120 ble_app_multilink_central example. I have configured UART0 in interrupt mode. I send some command and expect some response. It work very well in starting but after some time it stops responding. Although UART0 is functional but its interrupt stops responding.

I am sending command "HNDSK\r\n" and expect response "OK Done\r\n". My code is as below-

void UART0_IRQHandler(void)
{ 
  if(NRF_UART0->EVENTS_RXDRDY == 1)
  { 	  
		uart_buffer[uart_buf_head] =  (uint8_t)NRF_UART0->RXD;
		uart_buf_head++;
		NRF_UART0->EVENTS_RXDRDY = 0;
		if(uart_buffer[uart_buf_head-1]==0x0a && uart_buffer[uart_buf_head-2]==0x0d){																															   
			if(strstr((const char*)uart_buffer, "HNDSK\r\n")) //Handshake
					simple_uart_putstring((const uint8_t*)"OK Done\r\n");				

			uart_buf_head=0;
			ClearBuffer(uart_buffer,20);
			uart_buf_head=0;
		}
		else if(uart_buf_head>10){
			ClearBuffer(uart_buffer,20);
			uart_buf_head=0;
		} 	
  }

}

int main(void){

	app_trace_init();    
	NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;
    NVIC_SetPriority(UART0_IRQn, 1);//APP_IRQ_PRIORITY_LOW==3
    NVIC_EnableIRQ(UART0_IRQn);

    ble_stack_init();	
    client_handling_init();
    device_manager_init();
    scan_start();
	start_timer();//i ms interrupt

    for (;;)
    {	 


    }
} 

Please help.

Parents
  • @Hung Bui. Thank you for your help. Yes i did the same at first but didnt work. Because interrupt didnt triggered so could not set the flag.

    But I solved the problem by making a small change. I replaced the following code-

    uart_buffer[uart_buf_head] =  (uint8_t)NRF_UART0->RXD;
    uart_buf_head++;
    NRF_UART0->EVENTS_RXDRDY = 0;
    

    By this code-

     NRF_UART0->EVENTS_RXDRDY = 0;
        uart_buffer[uart_buf_head] =  (uint8_t)NRF_UART0->RXD;
        uart_buf_head++;
    

    Now my interrupt is working perfectly and it does not stuck.

Reply
  • @Hung Bui. Thank you for your help. Yes i did the same at first but didnt work. Because interrupt didnt triggered so could not set the flag.

    But I solved the problem by making a small change. I replaced the following code-

    uart_buffer[uart_buf_head] =  (uint8_t)NRF_UART0->RXD;
    uart_buf_head++;
    NRF_UART0->EVENTS_RXDRDY = 0;
    

    By this code-

     NRF_UART0->EVENTS_RXDRDY = 0;
        uart_buffer[uart_buf_head] =  (uint8_t)NRF_UART0->RXD;
        uart_buf_head++;
    

    Now my interrupt is working perfectly and it does not stuck.

Children
No Data
Related