I2C woes (native devices)

Discussion of issues related specifically to writing code for native mode devices. This includes ZBasic code as well as assembly language code and C code, both inline and standalone.
Post Reply
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

I2C woes (native devices)

Post by sturgessb »

Something strange is going on guys....

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
Any ideas?

Ben
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: I2C woes (native devices)

Post by dkinzer »

sturgessb wrote:Could there be some problem with 1.62, I2C, and native devices?
Well, it took a while to reproduce the problem but we finally got it to happen here. The recent changes to support slave mode contained an error that could cause cmdSPI() to fail. We've devised a solution and, so far, it appears to have solved the problem.

An experimental version of the ZX Library v2.5.4 is available that should resolve the problem. The contents of the .zip file should be extracted to the zxlib subdirectory of the ZBasic installation directory.
- Don Kinzer
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Hurrah I'm not mad, that's fixed it!

It's nice for me to make a post that actually useful for a change :)

Ben
Post Reply