Hi,
I am using three SPI chips with Arduino Mega. Right now i am using SPI.transfer to communicate with the chips. It is taking 12-16usecs for transferring two bytes. is there a faster way to do this?
Hi,
I am using three SPI chips with Arduino Mega. Right now i am using SPI.transfer to communicate with the chips. It is taking 12-16usecs for transferring two bytes. is there a faster way to do this?
It looks like you are running SPI at 1 MHz. See SPI - Arduino Reference and check the data sheets for your devices to see if you can go any faster.
Thank you. I will check the devices spec.
Just to be clear: SPI_CLOCK_DIV2 is 8Mhz right. So imy devices should be able to operate at 8Mhz.? Am I correct?
Ok that worked. Thank you.
Yes, 8 MHz is the fastest you can go.
You can gain a little more speed by using direct control vs SPI.transfer:
SPDR = dataArray[0]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
SPDR = dataArray[1]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
SPDR = dataArray[2]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
SPDR = dataArray[3]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
SPDR = dataArray[4]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
SPDR = dataArray[5]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
SPDR = dataArray[6]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
SPDR = dataArray[7]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
Not using for loop saves about 12uS/byte, not waiting for SPI interrupt but just timing it out saves some time too - I have achieved 45 bytes in about 47uS doing this.
(17 clock cycles per transfer I think it works to).
Need some assembler thing at the top of the sketch, I don't recall what it is, have to look at a sketch to see.