In my project, if I press a lot of buttons (which causes a lot of SPI communication), the code hangs and GDB shows me it's getting stuck in the below while loop from SPI.h (starting line 1237).
According the to RT1060 manual (page 2826), those bits in the FSR register are the number of words currently stored in the receive FIFO. I think writing to the TDR automatically starts the SPI transfer, and then the code loops until it receives something in the FIFO register. In some cases, and I don't know why, fifo stays as 0 and so the code doesn't leave the while loop.
Am I right in thinking that's how it works? Could there be an interference problem? Or maybe interrupts are getting involved?
My code is here: https://github.com/StagBeetle/Buttseqs but to compile I changed the audio library to reference SDFat, I think.
The actual code that calls the transfer in buttons.cpp is
Maybe some delays would help?
Code:
uint8_t transfer(uint8_t data) {
port().TDR = data;
while (1) {
uint32_t fifo = (port().FSR >> 16) & 0x1F;
if (fifo > 0) return port().RDR;
}
}
According the to RT1060 manual (page 2826), those bits in the FSR register are the number of words currently stored in the receive FIFO. I think writing to the TDR automatically starts the SPI transfer, and then the code loops until it receives something in the FIFO register. In some cases, and I don't know why, fifo stays as 0 and so the code doesn't leave the while loop.
Am I right in thinking that's how it works? Could there be an interference problem? Or maybe interrupts are getting involved?
My code is here: https://github.com/StagBeetle/Buttseqs but to compile I changed the audio library to reference SDFat, I think.
The actual code that calls the transfer in buttons.cpp is
Code:
digitalWrite(BUTTONCS, 1);
AUXSPIBUS.beginTransaction(shiftreg);
for(int i = 0; i < numberOfShiftRegisters; i++){
buttonShiftArray[i] = AUXSPIBUS.transfer(0);
}
AUXSPIBUS.endTransaction();
digitalWrite(BUTTONCS, 0);