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?
I've found the problem!
In LPC_chip_11uxx_lib, in chip.h it's defined:
/* Family specific IRQ handler alias list */
#if (defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX))
#define UART_IRQHandler USART_IRQHandler
#define USART0_IRQHandler USART_IRQHandler
#endif
/* Common IRQ Handler Alias list */
#define UART0_IRQHanlder UART_IRQHandler
In the vectors definition in cr_startup_lpc11uxx.c:
UART_IRQHandler, // 21 - UART0
So the handler defined in the vectors table, will never be invoqued.
The solution is to comment the define-> */ || defined(CHIP_LPC11UXX) */
Update:
I've pasted my code into the uart project example and the IRQ is triggering.
In the opposite way (pasting example code into my project), doesn't work.
It's seems to be something into my project setup... but I haven't idea what it's happening.
You copy part of uart demo code to your own project but uart interrupt doesn't work.
Thus I suggest you check:
1. check if you define uart interrupt function in vector table.
2. check if uart clock source is well defined.
3. check if the uart pin is well defined
You can compare the related registers value in your code and demo code.
Hi Jun!
I've got running the example properly, you can find it here:
https://www.nxp.com/webapp/Download?colCode=LPCOPEN_V2_03_LPCXPRESSO_11U37H
However, i've pasted the code into my project and doesn't work. I think there is a problem with de IRQ because it seems not being triggered.
I have interrupts for TIMERS (32 &16) for PWM and WWDT and they are working fine.
Hi Jun,
I've done many tests with different options. Let me explain my findings.
I have a LPC11u34 and a LPC1337 boards, so I've downloaded this libraries:
https://www.nxp.com/webapp/Download?colCode=LPCOPEN_V2_00A_LPCXPRESSO_11U14
https://www.nxp.com/webapp/Download?colCode=LPCOPEN_V2_03_LPCXPRESSO_11U37H
My findings:
11u34 and LPC1337 are very similar and most of the functions are compatible.
- 11u14_periph_uart example runs into the 11u34 and into the 1337. The problem here is the console output. The message printed is only "LP".
- Periph_uart_rb (1337 library examples ) runs only in the LPC1337 but the output is OK, printing the entire "LPC13xx UART example using ring buffers\n\rPress a key to echo it back or ESC to quit\r\n" message.
My though is that the IRQ in the 11u14 example is not triggering.
HI emimad
I don't have LPC11u34 but I have a LPC11u37 demo board. under my lpcopen package I didn't find UART_RB demo.
Could you please send me your LPCOpen package download link thus I can test it directly on my side?
Thanks
Jun Zhang