Hi all!
I'm trying to use the ring buffer in a LPC11u34 and I'm testing the LPCOpen example without good results.
#include "chip.h"
//#include "board.h"
#include "string.h"
#include "delay.h"
STATIC RINGBUFF_T txring, rxring;
#define UART_SRB_SIZE 128 /* Send */
#define UART_RRB_SIZE 128 /* Receive */
#define UART_SPEED 9600
static uint8_t rxbuff[UART_RRB_SIZE], txbuff[UART_SRB_SIZE];
const char inst1[] = "LPC13xx UART example using ring buffers\r\n";
const char inst2[] = "Press a key to echo it back or ESC to quit\r\n";
static void Init_UART_PinMux(void)
{
Chip_IOCON_PinMux(LPC_IOCON,_portRXD,_pinRXD,IOCON_MODE_INACT, FUNC1); // RXD
Chip_IOCON_PinMux(LPC_IOCON,_portTXD,_pinTXD,IOCON_MODE_INACT, FUNC1); // TXD
Chip_UART_Init(LPC_USART);
Chip_UART_SetBaud(LPC_USART, UART_SPEED);
Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS)); // | UART_LCR_PARITY_DIS
Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2)); /*!< UART FIFO trigger level 0: 1 character */
Chip_UART_TXEnable(LPC_USART);
}
void UART_IRQHandler(void)
{
Chip_UART_Send(LPC_USART, "INTERRUPTED!\n\r", 15); //never printed
Chip_UART_IRQRBHandler(LPC_USART, &rxring, &txring);
}
int main(void)
{
uint8_t key;
int bytes;
SystemCoreClockUpdate();
setSYSTICK();
//Board_Init();
Chip_GPIO_Init(LPC_GPIO);
Init_UART_PinMux();
RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE);
RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE);
//RingBuffer_Flush(&rxring);
//RingBuffer_Flush(&txring);
Chip_UART_IntEnable(LPC_USART, (UART_IER_RBRINT | UART_IER_RLSINT));
/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(UART0_IRQn, 1);
NVIC_EnableIRQ(UART0_IRQn);
for(uint8_t i = 0; i<5; i++){
Chip_UART_Send(LPC_USART, "TEST BUFFER\n\r", 15);
_delay_ms(1000);
}
// -> until here, transmission is OK
/* Send initial messages */
Chip_UART_SendRB(LPC_USART, &txring, inst1, sizeof(inst1) - 1); // here, only prints "L" (first char of the array)
Chip_UART_SendRB(LPC_USART, &txring, inst2, sizeof(inst2) - 1); // nothing printed anymore
Chip_UART_Send(LPC_USART, "\n\rGO!\n\r", 15);
/* Poll the receive ring buffer for the ESC (ASCII 27) key */
key = 0;
while (key != 27) {
bytes = Chip_UART_ReadRB(LPC_USART, &rxring, &key, 1);
if (bytes > 0) {
Chip_UART_Send(LPC_USART, "key pressed\n\r", 15); // -> enters here without pressing any key and the string is cut, only prints "key pre"
/* Wrap value back around */
if (Chip_UART_SendRB(LPC_USART, &txring, (const uint8_t *) &key, 1) != 1) {
Chip_UART_Send(LPC_USART, "error\n\r", 15);
}
}
}
/* DeInitialize UART0 peripheral */
NVIC_DisableIRQ(UART0_IRQn);
Chip_UART_DeInit(LPC_USART);
return 1;
}
The output:

I can see few errors:
- UART IRQ seems not to be fired.
- First Chip_UART_SendRB instance, only prints the first character "L".
- Second Chip_UART_SendRB prints nothing.
- Although no key is pressed, program enters into if(byte > 0). And there, only "key pre" is printed.
I've modified LPCOpen function as seen in this forum because the original one, only prints the first byte:
int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes)
{
int sent = 0;
uint8_t *p8 = (uint8_t *) data;
/* Send until the transmit FIFO is full or out of bytes */
/* while ((sent < numBytes) &&
((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0)) {
Chip_UART_SendByte(pUART, *p8);
p8++;
sent++;
}
*/
while ((sent < numBytes) ) { // FUNCION CORREGIDA DE LA LIBRERIA LPCOPEN
while((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) == 0);
Chip_UART_SendByte(pUART, *p8);
p8++;
sent++;
}
return sent;
}
Could anyone light my way, please?