main returns with 0

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

main returns with 0

111 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ppx on Mon Jan 06 05:21:27 MST 2014
I have downloaded from LPCopen an example for interrupt driven routines using the built in ROM functions for LPC812. It is called "nxp_lpcxpresso_812_periph_uart_rom_int"
I was very surprised to see that the main ends with a return 0;
Is this an error or is the program designed to run once and than crash?
0 Kudos
1 Reply

99 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wellsk on Mon Jan 06 10:12:31 MST 2014
It looks like that example was written to only reads 16 bytes in interrupt context and then drops out

/* A (inefficient) ring buffer can be emulated in interrupt
   mode using the uart_get_line() with a buffer size of 1. Read
   16 bytes into the ring buffer and then exit.*/
indexIn = 0;
while (indexIn < 16) {


Normally, when a simple LPCOpen example exits main(), it goes into sysexit() which is a dead loop. It sounds like the UART is still operating once it enters sysexit() and crashes on receive?
It sounds like we should disable the UART interrupt and shutdown the UART correctly for this example prior to return.

I would say this is considered and error. Maybe something like this fix might work?
/* Transmit the message for byte/character part of the example */
putLineUART("\r\nData in ring buffer: ");
putLineUART(recv_buf);

/* Need to delay a bit here to allow UART to finish sending current bytes */
SomeTypeOfDelayHere();

NVIC_DisableIRQ(UART0_IRQn); /* Disable UART interrupt */
Chip_UART_DeInit(LPC_USART0); /* Shutdown UART and clocking */

0 Kudos