As a part of my current experiment, I’m running following piece of code:
if (digitalRead(pinDeviceReadReady) == HIGH) { Serial.println("DATA READY"); spiSend(0x20); // command "read request" readBuffer.deviceId = spiReceive(); Serial.println(readBuffer.deviceId); readBuffer.wireId = spiReceive(); Serial.println(readBuffer.wireId); readBuffer.length = spiReceive(); Serial.println(readBuffer.length); for (int i = 0; i <= readBuffer.length; ++i) { readBuffer.data[i] = spiReceive(); Serial.println(readBuffer.data[i]); } } where inline void spiSend(uint8_t data) { // wait for device ready to write while (digitalRead(pinDeviceWriteReady) == LOW); SPI.transfer(data); } inline uint8_t spiReceive() { while (digitalRead(pinDeviceReadReady) == LOW); uint8_t data = SPI.transfer(0); return data; }
The picture below shows the “pinDeviceReadReady (DATA_READY)” indicator value (red) and SPI clock (blue). There are significant delays after DATA READY indicator is up until the UNO executes SPI transfer.
This is due to Serial.println() debug prints inserted between SPI transfers. I’ve not read the Serial.println() implementation, but the delay looks to be ranging from 100 to 150 micro seconds.
The large delay disappeared when I removed the Serial.println() lines.
However, you still see delay when you close up a little more.
This is possibly caused by digitalRead() for the indicator or invoking SPI.transfer(). I don’t have to remove this delay for this experiment, but may need to do so later. The delay is about 3 micro seconds.
Hi Gan !!!! I just saw your Optigan DIY … ITs REALLY BRILLIANT !!!!!
CONGRATS!!!!
Lets keep in touch please !!! whats your email ???
Thanks. My address is naoki.iwakami*nospam*gmail.com.
Replace *nospam* by atmark.