Reading UART with CMSIS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading UART with CMSIS

1,552 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by justmakeit on Thu Mar 06 04:04:38 MST 2014
Hello,

I'm using the LPC1766 MCU ant trying to receive data using the UART1.But i'm only receiving 16 bytes. I'm using the CMSIS (v3.2) lib to receive the data.

The interupt handler for UART1:
void UART_Handler(uint8_t uartnr, LPC_UART_TypeDef * UARTx){
  uint8_t tmpc;
  uint32_t rLen;

  while(1){
    // Call UART read function in UART driver
    rLen = UART_Receive(UARTx, &tmpc, 1, NONE_BLOCKING);
    // If data received
    if (rLen){
      if(end_char[uartnr] == tmpc){
         process_post_synch(handler_uart[uartnr], event_newline_uart[uartnr], NULL); 
      }
      ringbuf_put(&ringbuf_uart[uartnr], tmpc);
    }
    
    else {// no more data
      break;
    }
  }   
}

volatile void UART1_IRQHandler(void){
 UART_Handler(1,(LPC_UART_TypeDef *)LPC_UART1);
}


The init code:


void UART1_P2_Dev_Init(uint32_t Baud_rate, struct process * handler, char LineEndChar)
{ 
    UART_FIFO_CFG_Type Fifo_CFG; 
      
    UART_Dev_Init((LPC_UART_TypeDef *)LPC_UART1, Baud_rate);
    
    PINSEL_CFG_Type pinsel;  
    //TX
    pinsel.Portnum = PINSEL_PORT_2;
    pinsel.Pinnum = PINSEL_PIN_0;
    pinsel.Funcnum = PINSEL_FUNC_2;
    pinsel.Pinmode = PINSEL_PINMODE_TRISTATE;
    pinsel.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
    PINSEL_ConfigPin(&pinsel);

    //RX
    pinsel.Pinnum = PINSEL_PIN_1;
    PINSEL_ConfigPin(&pinsel);
    
    //FIFO
    UART_FIFOConfigStructInit(&Fifo_CFG);
    UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART1, &Fifo_CFG);
    
    //Interrupt enable
    UART_IntConfig((LPC_UART_TypeDef *)LPC_UART1, UART_INTCFG_RBR, ENABLE);
    NVIC_EnableIRQ(UART1_IRQn);
    
    //Ringbuffer init
    ringbuf_init(&ringbuf_uart[1],(uint8_t *)buffer_uart[1],BUFLEN_UART1);
    end_char[1] = LineEndChar;

    //Event init
    handler_uart[1] = handler;
    event_newline_uart[1] = process_alloc_event();
}




hopefully someone can give me an idea of ​​what is going wrong. I'm only receiving 16 byte ...
even when i remove the break command in the handler.

thanks
Labels (1)
0 Kudos
2 Replies

868 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by justmakeit on Fri Mar 07 01:17:11 MST 2014
Your right,
I used UART_Receive(UARTx, &tmpc, 1, NONE_BLOCKING); to receive multiple bytes with one interrupt. But that is none sense  ;-) . The interrupt should stay active while there is data in the receive buffer.

the ringbuffer forget the new data when its full. And the buffer is 64 bytes long

I solved a part of the mystery. The reason that i'm only receiving 16 byte is that the debugger slowed down my program. On this moment the whole packet shows up but after sending it a couple times it stops activating the interrupt. 
register status when interrupt stop working:

its not pending in the uart1 register
U1IIR->IP = 1

The FIFO disables and the TX reset activates (wont clear it self ).
U1FCR->FCRFE  = 0
U1FCR->TFR  = 1




0 Kudos

868 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketdawg on Thu Mar 06 09:54:59 MST 2014
what is define BUFLEN_UART1 ?  is it 16 ?

this is wasteful
rLen = UART_Receive(UARTx, &tmpc, 1, NONE_BLOCKING);
you are getting one character, so why not use the more efficient
UART_ReceiveByte(LPC_USARTn_Type* UARTx);

what does ringbuf_put() do when the ringbuffer is full?
0 Kudos