LPC1769 receive string using ringbuffers

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

LPC1769 receive string using ringbuffers

1,812 Views
lucasfontan
Contributor I

Hi, I'm using LPCOpen with FreeRTOS and I need to read from a WiFi module with AT commands a string which length is larger than a one that could be read with the the function Chip_UART_Read(), so I decided to use ringbuffers. I can send data without problem, but no receiving the response of the module, It seems that I'm not using well the Chip_UART_ReadRB() function. This is my code:

 

void WIFI_UART_IRqHandler (void) {   static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;    NVIC_DisableIRQ(WIFI_UART_IRQ);   NVIC_ClearPendingIRQ(WIFI_UART_IRQ);     Chip_UART_TXIntHandlerRB(WIFI_UART_LPC, &WIFI_RxRingBuffer);     xSemaphoreGiveFromISR(xUartIRQSemaforo, &xHigherPriorityTaskWoken);    portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );    NVIC_ClearPendingIRQ(WIFI_UART_IRQ);  }

 

int main(void) {   vSemaphoreCreateBinary(xUartIRQSemaforo);    xTaskCreate(vWIFI_RBReceive_from_ESP,(const char *)"Recibe los datos" ,configMINIMAL_STACK_SIZE , NULL 1 , NULL ) ;  vTaskStartScheduler();  return 1; }

 

void WIFI_UART_Init(void) {   //Configuro los pines que voy a usar para la UART   Chip_IOCON_Init(WIFI_UART_IOCON);   Chip_IOCON_PinMux(WIFI_UART_IOCON,WIFI_RxTx_Port,WIFI_RX_PIN,IOCON_MODE_PULLUP,WIFI_UART_Pin_Func);   Chip_IOCON_PinMux(WIFI_UART_IOCON,WIFI_RxTx_Port,WIFI_TX_PIN,IOCON_MODE_PULLUP,WIFI_UART_Pin_Func);    //Ahora configuro la UART propiamente dicha    /* Setup UART for 115.2K8N1 */   Chip_UART_Init(WIFI_UART_LPC);   Chip_UART_SetBaud(WIFI_UART_LPC, 115200);   Chip_UART_ConfigData(WIFI_UART_LPC, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));   Chip_UART_SetupFIFOS(WIFI_UART_LPC, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));   Chip_UART_TXEnable(WIFI_UART_LPC);    /* Before using the ring buffers, initialize them using the ring     buffer init function */   RingBuffer_Init(&WIFI_RxRingBuffer, WIFI_RxBuff, 1, WIFI_UART_RxRB_SIZE);   RingBuffer_Init(&WIFI_TxRingBuffer, WIFI_TxBuff, 1, WIFI_UART_TxRB_SIZE);    /* Reset and enable FIFOs, FIFO trigger level 3 (14 chars) */   Chip_UART_SetupFIFOS(WIFI_UART_LPC, (UART_FCR_FIFO_EN | UART_FCR_RX_RS |UART_FCR_TX_RS | UART_FCR_TRG_LEV3));    /* Enable receive data and line status interrupt */   Chip_UART_IntEnable(WIFI_UART_LPC, (UART_IER_RBRINT | UART_IER_RLSINT));    /* preemption = 1, sub-priority = 1 */   NVIC_SetPriority(WIFI_UART_IRQ, 1);   NVIC_EnableIRQ(WIFI_UART_IRQ);  }

 

void vWIFI_RBReceive_from_ESP(void) {   xSemaphoreTakeFromISR(xUartIRQSemaforo, 0);    while(1)   {   if(xSemaphoreTakeFromISR(xUartIRQSemaforo, portMAX_DELAY))   {        Chip_UART_ReadRB(WIFI_UART_LPC, &WIFI_RxRingBuffer, &WIFI_RxBuff, 1);         Chip_UART_IntEnable(WIFI_UART_LPC,UART_IER_BITMASK);         NVIC_ClearPendingIRQ(WIFI_UART_IRQ); //Limpio la interrupcion del puerto serie.        NVIC_EnableIRQ(WIFI_UART_IRQ);    }    } }
Labels (2)
Tags (1)
0 Kudos
3 Replies

964 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi lucas fontan,

    For the usage of LPC1769 uart ring buff, you can refer to the LPCOPEN periph sample code, it has a project about it, names as: periph_uart_rb.

    Please refer to that project to configure your receive RB again, that code can work ok.

   After you download the LPCopen for LPC1769 :LPCOpen Software for LPC17XX|NXP

  You can find periph_uart_rb in folder:lpcopen_2_10_lpcxpresso_nxp_lpcxpresso_1769\periph_uart_rb

Wish it helps you!

If you still have question, please let me know!

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

964 Views
andrewcodd
Contributor I

Hi 

Am using the periph_uart_rb exactly as above.   In the example the rxring is passed to the txring in order to mirror the received data for the demo, I have that working well for any length of string being sent.

In a real application the received data needs to populate a string to be consumed by the application code.  My application requires about 64 bytes, over the 16bytes of the native UART buffer.   What is the recommended way to do this, as the example code does not make this step, and there are many choices one could make depending on the way things are coded.  So in this SDK example, the txring is populated from the rxring using Chip_UART_SENDRB() while while(key !=27).

Is it as simple as sampling unit(8) key into our own container as the rx function spins, and, depending on the start and end chars of interest, bringing it then into the application parser?    Or is there a more elegant way to pull our application data out of the rxring?

0 Kudos

964 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello Andrew Codd,

    If you have any LPC questions, please create the new question post in the LPC community.

   This original post already past a lot of years, and I am not support the LPC now.

     Thanks a lot for your understanding.

Wish it helps you!

If you still have questions, please let me know!

 

Have a great day,

Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos