I had some i2c sensors hooked up to my zx-24n and zx-128ne. All was working fine, then at some point with no wiring or software changes they stopped working, i2c commands were not being sent and no data was being received.
After checking over the wiring, and code again and again, I thought that something must have happened to the sensors or the zx devices.
Today I received a replacement i2c sensor, so I hooked it up to the zx-128ne, still no joy, tried the zx-24n, no joy, tried another out of the box 24n, still nothing. I then tried a standard zx-24 (vm version), and hey presto it works.
So I either have 3 faulty native devices (which i doubt, as they are working in all other ways) or something else is going on. The only thing I do seem to remember is upgrading the IDE to version 1.62.
Could there be some problem with 1.62, I2C, and native devices?
Here is my test code
Code: Select all
'I2C
PUBLIC i2c_Result as INTEGER
PUBLIC i2c_OutData(1 to 3) as BYTE
PUBLIC i2c_InData(1 to 3) as BYTE
'I2C Channels and Sensors
PUBLIC Const i2c_Adr_Sonar as BYTE = &HE0
PUBLIC Const i2c_Chan as BYTE = 0
PUBLIC sonar_altitude(1 to 2) as INTEGER
Sub Main()
Call Putpin(11, zxInputPullUp)
Call Putpin(12, zxInputPullUp)
Call OpenI2C(0, 0, 0)
Do
Call Get_sonar_altitude()
Call Delay(0.50)
Loop
End Sub
PUBLIC SUB Get_sonar_altitude()
i2c_OutData(1) = &H00
i2c_OutData(2) = &H51
i2c_Result = I2CCmd(i2c_Chan, &He0, 2, i2c_OutData(1), 0, i2c_InData(1))
i2c_OutData(1) = &H03
i2c_Result = I2CCmd(i2c_Chan, &He0, 1, i2c_OutData(1), 1, i2c_InData(1))
sonar_altitude(1) = Cint(i2c_InData(1))
DEBUG.PRINT sonar_altitude(1)
END SUB
Ben