Interrupt routine not updating volatile variable

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can anybody tell me why my state won't update to stNEW. I know it is getting through that point because if I reset it to stHDR0, it works the way it is supposed to, but when I set it to stNEW and try to reset RxState in my main method, it doesn't catch that the state has been updated. I am using an ATMEGA8.

volatile unsigned char iTemp;
volatile unsigned char RxState;
volatile unsigned char RxCount;
volatile unsigned char count;
int main()
{
	Init();

	for (;;)
	{
		if(RxState == stNEW)						// Have received a complete packet
		{
			RxState = stHDR0;
			count = 0;
         PORTB &= ~(1<<PB1);
		}
    }
}
		

ISR (USART_RXC_vect)
{
	iTemp = UDR;
	switch (RxState)
	{
		case stHDR0:						// Header 0
			if(iTemp == 0x41)
			{
				RxState++; 
				PORTB |= 1<<PB1;
			}
			break;
		case stHDR1:						// Header 1
			if(iTemp == 0x61 || iTemp == 0x41)
			{ RxState++; }
			else
			{ RxState = stHDR0; }
			break;
		case stCMD:							// Command
			Packet[count] = iTemp;
			RxState++;
			count++;
			break;
		case stCNT:							// Count
			Packet[count] = iTemp;
			RxCount = iTemp + 1;			// Add one for Checksum
			RxState++;
			count++;
			break;
		case stDATA:						// Data Bytes
			Packet[count] = iTemp;
			RxCount--;
			count++;
			if(RxCount == 0)
			{
				RxState = stNEW;
				
			}
			break;
		default:
			RxState = stHDR0;
			break;
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nevermind, it was a problem with another routine