Hi,
I have the following issues with the Serial communication.
My program receives a protocol with a certain specification. Hence I am able to detect some errors in the transmission.
In particular, I am controlling a LED Strip by means of the Fast_SPI Library. The protocol contains the RGB data, is approx 30 bytes in length. The processing of the protocol is started as soon as the if(Serial.available>0) in my while(true) is true. The processing itself mainly consists of several if-clauses and the transfer of the Serial buffer (using Serial.read()) into an array.
To smoothen the colour transition I included a time triggered function. Specifically, every 30 ms a volatile boolean is set to true
ISR(TIMER1_COMPA_vect)
{
Trigger1=true;
}
Another if-clause in the while(true) loop checks if this flag is true and begins to calculate the final colour by mixing the current colour with the data last received
for (int i=0; i<NUM_LEDS; i++)
{
ledDataStruct1[i].r=((MIX_COEFFICIENT*ledDataStruct1[i].r)+(1-MIX_COEFFICIENT)*ledDataStruct2[i].r);
ledDataStruct1[i].g=((MIX_COEFFICIENT*ledDataStruct1[i].g)+(1-MIX_COEFFICIENT)*ledDataStruct2[i].g);
ledDataStruct1[i].b=((MIX_COEFFICIENT*ledDataStruct1[i].b)+(1-MIX_COEFFICIENT)*ledDataStruct2[i].b);
}
FastSPI_LED.show();
Trigger1=false;
Now, what strikes me, is that the implemented check on transmission errors often returns that the last byte had not been received. This only occurs if I have turned on the timer interrupt and the subsequent colour mixture.
Imho, the time-trigger should not affect the reception of the Serial data since it only changes one flag. And the colour mixture can be interrupted by the Serial interrupt anyways...
Thank you in advance!