I'm currently using an Arduino Mega as a SPI slave.
I want it to continuously write on MISO while the master is managing the clock. As the master doesn't pause between each byte, I need to be able to prepare the new value of SPDR register as the previous one is being sent.
My SPI interrupt is pretty simple:
where my_tab is a 256 char table and idx_rd_tab is a byte.
When I execute this code, I get only the first element of the table. Then, I get only 0.
I'm wondering if the Arduino Mega is able to process data fast enough for this kind of application? Or is there something I'm doing wrong?
void setup(void)
{
Serial.begin(57600);
Serial1.begin(115200);
Serial1.println("------------------------------");
// Have to send on master in, *slave out*
pinMode(MISO, OUTPUT);
pinMode(MOSI, INPUT);
pinMode(SS, INPUT);
pinMode(Attention, OUTPUT);
digitalWrite(Attention, HIGH);
pinMode(Reset, INPUT);
pinMode(testPin, OUTPUT);
digitalWrite(testPin, LOW);
pinMode(SS_detect, INPUT);
// Turn on SPI in slave mode
SPCR |= _BV(SPE);
// Turn on interrupt for Reset line
attachInterrupt(digitalPinToInterrupt(Reset), m_reset, RISING);
// Turn in interrupt on slave select
// (Attached a second input for SS as we can't fix an IT on basic one)
attachInterrupt(digitalPinToInterrupt(SS_detect), SS_detect_IT, RISING);
// Delay a bit to let some time for initialization
delay(1000);
// Turn on interrupts for SPI
SPI.attachInterrupt();
}
Then, most of the work of the main loop is filling "my_tab". I've checked that the table is fill fast enough by printing the values of each cell of my_tab right before sending it to SPDR.
Yes, at least the variable definitions and the interrupt handlers. And I repeat: without having seen the complete code I cannot tell in which part of the code the error lies.