Hello, first time poster. I'm creating and debugging a project for the LPC54113J256 in the MCUExpresso IDE (v11.6.1) on a PC. The USART0 FIFO keeps overflowing, and I can't figure out why. I'm new to both USART and interrupts (and to NXP MCUs in general), so I'm likely missing something simple.
I'm using an Interrupt Service Routine (ISR) to read data from the USART0 FIFO to ring buffer, which is called whenever the FIFO is not empty. In main(), I disable interrupts while extracting data from the ring buffer. The incoming data is at 9600 baud, so I expect to be receiving roughly 1 byte every 10 milliseconds, and so I figure I should be able to suspend interrupts for up to 150 milliseconds or so without overflowing the FIFO, which is 16 bytes long.
However, I found that even when I keep the ring buffer reading code extremely simple, I'm getting FIFO overflow. I then added some clock() commands to check before and after running the disabling the interrupts, and it seems that simply calling USART_DisableInterrupts() is taking around 300 milliseconds! Assuming that I'm applying clock() appropriately, this explains why the overflow error occurs, but I don't understand why this command takes so long to run? I tried replacing this function call with a straight write of 0xA to the FIFOINTENCLR register, and this similarly took around 300 milliseconds.
I believe I have the clock running at the default 12 MHz (clock diagram from IDE attached); but, I tried changing the clock source to the high frequency FRO at 48 MHz, and still saw that disabling the interrupts took roughly 300 milliseconds.
In the attached code, I have simplified things so that the code (I believe) behaves as follows:
1) In both ISR and main(), I check for FIFO overflow and reset things if error is detected.
2) In the ISR, as data is read from the FIFO, it is placed in the ring buffer as long as the ring buffer is not full; if the ring buffer is full, a flag is set and the data from the FIFO is discarded.
3) In main(), if the ring buffer full flag is set, the program disables interrupts, resets the ring buffer receive and transmit addresses, then re-enables interrupts. clock commands are used to check different timing. (I also issue two successive clock commands to check how long it takes clock() to execute (the output shows it takes roughly 60 milliseconds).
Here is typical output:
Hello World
ISR: USART0 Overflow and RX0 Buffer Full
Main: RX0 Buffer Full
Interrupt disable took 260 milliseconds
Commands plus Interrupt re-enable took 90 milliseconds
Call to clock() took 50 milliseconds
ISR: USART0 Overflow and RX0 Buffer Full
Main: RX0 Buffer Full
Interrupt disable took 300 milliseconds
Commands plus Interrupt re-enable took 60 milliseconds
Call to clock() took 90 milliseconds
ISR: USART0 Overflow and RX0 Buffer Full
Main: RX0 Buffer Full
Interrupt disable took 320 milliseconds
Commands plus Interrupt re-enable took 60 milliseconds
Call to clock() took 70 milliseconds
ISR: USART0 Overflow and RX0 Buffer Full
Main: RX0 Buffer Full
Interrupt disable took 310 milliseconds
Commands plus Interrupt re-enable took 60 milliseconds
Call to clock() took 60 milliseconds
Any advice would be appreciated. It seems odd to me that these commands take so long to run.
Attached are my code (in both plain .txt and in more readable .docx) plus an image of the clock configuration (.png).