If you have ever had the problem of i2c commands not working when starting a program (particularly after a hardware reset without a power on/off) then I may have a solution. This issue has been annoying me for some time until I finally put the effort in to understand and track down a solution.
The issue arises if an i2c slave is writing at the time of the master reset and happens to be holding SDA low at the instant the master (picaxe) is reset. In this case the normal i2c command for resetting the internal state of the i2c slave (master issuing a start command which includes pulling SDA low) may not work.
The solution is as follows:
Before initialising the picaxe i2c hardware set SDA as an input and test for SDA low.
If it is low then set the SCL (SCK) pin as an output
Using a frequency not more that the i2c bus speed the slowest peripheral can handle, toggle the SCK pin low and then high until SDA goes high (i.e. clock out any remaining bits of the write from the peripheral). This cannot take more than 8 clock cycles - if it does then there is some other issue.
Once SDA is high then issue the hi2csetup command and all should work perfectly.
I've now installed this fix in all my programs and had no further lockups.
Hope this helps
Best regards
Peter
The issue arises if an i2c slave is writing at the time of the master reset and happens to be holding SDA low at the instant the master (picaxe) is reset. In this case the normal i2c command for resetting the internal state of the i2c slave (master issuing a start command which includes pulling SDA low) may not work.
The solution is as follows:
Before initialising the picaxe i2c hardware set SDA as an input and test for SDA low.
If it is low then set the SCL (SCK) pin as an output
Using a frequency not more that the i2c bus speed the slowest peripheral can handle, toggle the SCK pin low and then high until SDA goes high (i.e. clock out any remaining bits of the write from the peripheral). This cannot take more than 8 clock cycles - if it does then there is some other issue.
Once SDA is high then issue the hi2csetup command and all should work perfectly.
I've now installed this fix in all my programs and had no further lockups.
Hope this helps
Best regards
Peter