Content originally posted in LPCWare by anburaj on Wed Aug 14 00:35:53 MST 2013
Dear All,
I'm trying to implement UART transmission based on THRE interrupt.
Operation(from LPC23xx UART sample code): Initially empty flag is set. In Main loop, if empty flag is set, Data Buffer is assigned to U0THR and empty flag is cleared. if THRE interrupt is occurred then empty flag is set in ISR.
Issue is System gets hanging after some time.
Can anyone give some idea to resolve this issue?
Code:
//Main function
main()
{
UART0TxEmpty = 1;
ByteToSend = 0;
ByteSent = 0;
while(1)
{
if(ByteToSend == 0)
{
memcpy(DumpBuff,DataBuff,12);
ByteToSend = 12; ByteSent = 0;
}
if(UART0TxEmpty)
if(ByteToSend != 0)
{
UART0TxEmpty = 0;
U0THR = DumpBuff[ByteSent++];
if(ByteSent >= ByteToSend)
{
ByteToSend = 0;
ByteSent = 0;
}
}
}
}
//ISR
irq void UART0_IRQHandler (void)
{
unsigned char IIRValue;
unsigned char LSRValue;
IENABLE;/* handles nested interrupt */
IIRValue = U0IIR;
IIRValue >>= SKIP_IIR_BIT;/* skip pending bit in IIR */
IIRValue &= INT_IDENTIFICATION;/* check bit 1~3, interrupt identification */
if(IIRValue == IIR_THRE)
{
LSRValue = U0LSR;
if(LSRValue & LSR_THRE)
{
UART0TxEmpty = 1;
}
else
{
UART0TxEmpty = 0;
}
}
IDISABLE;
VICVectAddr = 0;//ACK_INTERRUPT;
}