- Joined
- Jul 4, 2009
- Messages
- 16,520
- Helped
- 5,157
- Reputation
- 10,347
- Reaction score
- 5,211
- Trophy points
- 1,393
- Location
- Aberdyfi, West Wales, UK
- Activity points
- 139,690
The problem was a mix of register names and configuring interrupts but then polling the interrupt flag to see if data was available instead of doing it in the ISR.
There is a modification you can try which might overcome a problem if something else slows the ISR down:
Instead of using "if(DataRdy1USART()" to see if the USART holds data, use "if(PIR1bits.RC1IF == 1)" instead. You already know something triggered the interrupt because you have entered the ISR but if you expand your code so the ISR is used to service other interrupts as well, you need to be able to distinguish one source from the other. The interrupt flags are the best way to do that. In your code, you know the USART is 'ready' already because you would not have reached that place in code if it wasn't.
A better ISR structure would be like this (pseudo coded):
Brian.
There is a modification you can try which might overcome a problem if something else slows the ISR down:
Instead of using "if(DataRdy1USART()" to see if the USART holds data, use "if(PIR1bits.RC1IF == 1)" instead. You already know something triggered the interrupt because you have entered the ISR but if you expand your code so the ISR is used to service other interrupts as well, you need to be able to distinguish one source from the other. The interrupt flags are the best way to do that. In your code, you know the USART is 'ready' already because you would not have reached that place in code if it wasn't.
A better ISR structure would be like this (pseudo coded):
Code:
void interrupt ISR()
{
if(interrupt flag xxx == 1)
{
do the xxx service routines
clear xxx flag
}
if(interrupt flag yyy == 1)
{
do the yyy service routines
clear yyy flag
}
if(interrupt flag zzz == 1)
{
do the zzz service routines
clear zzz flag
}
} // end of ISR
Brian.