Thanks for the suggestion on the fast GPIO mode.
I've done some additional tests with the logic analyzer.
I was able to generate the 2.93 MHz waveform using:
void loop() { fastGpioDigitalWriteDestructive(0x0); fastGpioDigitalWriteDestructive(0xff); }
Alternatively, I was also able to generate the 683 kHz waveform using:
void loop() { fastGpioDigitalWrite(GPIO_FAST_IO3,LOW); fastGpioDigitalWrite(GPIO_FAST_IO3,HIGH); }
The intent on the above two tests is to see if I can use it as my SPI chip select. As such, I did two additional tests using the following SPI settings:
void setup() { pinMode(3, OUTPUT_FAST); SPI.begin(); SPI.setBitOrder(MSBFIRST); SPI.setClockDivider(SPI_CLOCK_DIV2); SPI.setDataMode(SPI_MODE0); }
The two test is as follows:
void loop() { fastGpioDigitalWriteDestructive(0x0); SPI.transfer(0x00); fastGpioDigitalWriteDestructive(0xff); }
and
void loop() { fastGpioDigitalWrite(GPIO_FAST_IO3,0x0); SPI.transfer(0x00); fastGpioDigitalWrite(GPIO_FAST_IO3,HIGH); }
Once I added the SPI.transfer(0x00) line, I noticed that there is a delay of 0.54 and 0.56 ms between Pin3 going from LOW and back to HIGH. As such, it suggests the delay is not due to the slow GPIO being used as a chip select but rather the SPI.transfer() and SPI.transferBuffer() for that matter.
I did two other follow on test to verify that it is indeed the SPI.transfer() and SPI.transferBuffer() functions that cause the delay by using:
void loop() { SPI.transfer(0x00); }
and
void loop() { SPI.transferBuffer(theBuffer, NULL, 1); // where theBuffer consists of: byte theBuffer[1]; theBuffer[0] = 0; }
The result of the above two tests resulted in a 0.54 and 0.55 ms delay between each byte transfer on the SPI clock line. This pretty much confirms that the vast majority of the delay (~0.54 ms) is caused by the SPI.transfer() and SPI.transferBuffer() functions.
Based on the timing diagram from my logic analyzer, from the time I pull the chip select pin down using Fast GPIO to the first clock of the SPI, it takes about 30 ms. From the last clock of the SPI transfer to the chip select pin going back up, there is an additional 25 ms.
Does anyone know if there is a way to reduce the delay caused by the SPI.transfer()?