I’m using the I2C interface to communicate with a Microchip PIC controller. The PIC is the master and the Photon is the slave. The master (PIC uController) is doing both writes to the Photon (handled with onReceive()) and reads (handled with onRequest()).
Here’s the problem: If I do a read request from the photon slave the photon sends the Photons Slave address, not the data it should be sending. I am requesting 3 bytes of data in the request and all three bytes sent by the Photon are the address of the photon.
Now for the interesting part If I do a Write from the master to the slave Photon before the read request everything works just fine. As long as I proceed each read request with a write first, then the Photon sends the data I am expecting.
I’ve looked at the situation on my oscilloscope and I see in the failed read that the Photon Slave is sending an ACK but not doing a clock stretch while it goes off to retrieve the data from the handler. However when the read is successful (i.e.- it was proceeded by a write first) then I see the clock stretch occur after the ACK as one would expect because it has to execute the handler before it can respond with the data.
Is there a higher level protocol that the Wire library is expecting? Is it assumed that a write from the master must occur before a read request? My Photon code is exactly like the example shown in the API Docs.
I doubt if the user community uses the Photon as a slave very often as most applications the Photon would be the master talking to peripherals whereas i’m using the photon as a slave. So maybe I’m the first to see this.
My problem seems very basic. It seems clock stretching is not enabled or initialized correctly since I see no evidence of the clock stretch on my scope when the failed read requests were made. But like I said above, as long as the read is proceeded by a write from the master the read will work and I see the clock stretch holding off the transfer while the handler retrieves the data to be sent.
Anybody else encounter this problem? I think it’s actually a bug in the Photon Firmware. I have pdf’s of the oscilloscope plots if anyone is interested.