I've built a frequency/counting device with an ATTiny85.. It seems to be working, but after a handful of reads from the Master device, the ATTiny start to send junk.. I think this is because the byte ordering is getting mixed up...
SendCount is initialized to 0 in the Setup() Method.
Here's my Request method:
volatile unsigned long Data1;//this is the data from the frequency method
volatile byte SendCount;
volatile uint8_t sendByte;
void requestEvent()
{
SendCount++; //increment this
switch (SendCount)
{
case 1:
Data1 = TinyFrequencyCounter.GetHz();
sendByte = Data1 & 0xFF;
break;
case 2:
sendByte = Data1 >> 8;
break;
case 3:
sendByte = Data1 >> 16;
break;
case 4:
sendByte = Data1 >> 24;
SendCount=0;
break;
}
TinyWireS.send(sendByte);
}
I've tried a few different ways to count frequency I am counting interrupts until I get a timer 1 overflow. it's accurate enough for my purpose at this point
ISR(PCINT_VECTOR)
{
PulseCount++;
}
ISR(TIMER1_OVF_vect) //Core Build Options.H line:112 - change from 1 to 0
{
//The timer have overflowed get the pulse count;
GatePulseCount = PulseCount;
PulseCount=0;
}
Are the ISRs affecting the Request Event? How can I fix this?