Rainbowduino V3: Serial communication vs. LED update interrupt

Hi all,

I'm trying to write a firmware for a Rainbowduino V3 board (www.seeedstudio.com/depot/rainbowduino-led-driver-platform-atmega-328-p-371.html) that should be able to stream 25fps via a serial connection over the build-in USB connection. The code for streaming 25 8x8 frames per second from a Java application works pretty reliable and also the stock-firmware of seeedstudio.com (http://www.seeedstudio.com/wiki/Rainbowduino_v3.0#Resources) which takes care of driving the 8x8 RGB LED matrix works fine.

But if I try to put both pieces together I do get a lot of data corruption over the serial connection. The serial connection runs with a 115200 baud rate. Slowing down to 57600 reduces the number of data corruptions but it doesn't solve my problem. From my understanding those issues are coming from conflicts between the internal interrupt used by the Arduino Serial library and the interrupt of the stock-firmware that is setup in the following way:

void Rainbowduino::init_timer1(void)        //initialize Timer1 to overflow every  100uS
{
    TCCR1A = 0;                       // clear control register A
    TCCR1B = _BV(WGM13);              // set mode as phase and frequency correct pwm, stop the timer
    ICR1 = 10000;                      //(XTAL * microseconds) / 2000000  1mS cycles
    TIMSK1 = _BV(TOIE1);
    TCNT1 = 0;
    TCCR1B |= _BV(CS10);
    sei();                             //enable global interrupt
}

Each to be transferred frame gets sliced into four fragments resulting in 56bytes per fragment (16LEDS * RGB + 8byte for header, footer and crc) resulting in 224bytes per frame and 5600bytes/sec at 25fps. If I enable the TIMER1 that updates the LEDs than I get data corruption in each of the 56bytes of a single frame fragment and for maybe ~5-10% of the frame fragments I'm even losing one or more bytes so that the frame fragment length doesn't match.

I'd like to ask for ideas / options to approach my problem since I'm not an expert at all when it comes to Arduinos Timers and Interrupts. I've also played around with the FlexiTimer2 Library but with the same data corruption results. Before trying out more stuff I currently ask myself:

  • Is it maybe to much what I try to archive with my Rainbowduino V3 board (streaming 5600bytes/sec & an interrupt triggered every 100us according to the seeedstudio.com firmware)? Am I already fighting against hardware limitations?

  • As an alternative for the USB serial connection: Will I face the same problems if I'd try to send the 5600bytes/sec via an I2C link from another Arduino? Does the Wire library also use an internal interrupt so that I'll have the same problem at the end? I haven't worked with the Wire library yet.

Any other ideas that might help solving my problem? Thanks a lot!

Greetings, Markus