AnsweredAssumed Answered

LPC1769 receive string using ringbuffers

Question asked by lucas fontan on Jun 20, 2016
Latest reply on Jul 27, 2016 by Kerry Zhou

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);    }    } }

Outcomes