PDA

View Full Version : I2CRead & I2CWrite not working as expected



Melanie
- 23rd July 2004, 16:04
I can't seem to Write properly to an I2C device
I can't seem to Read properly back from an I2C device
My I2C Serial EEPROM doesn't always save my data
I can't Write to the Registers on my I2C Real Time Clock, ADC etc


Check your I2CRead and IC2Write statements...

Do you have any CONSTANTS in the device address?

If so, your code is flawed... remove the constants and put in VARIABLES in their place...


Example: Write to location 8 on a 24LC32... these are NOT CORRECT...

I2CWrite SDA,SCL,$A0,$08,[DataA]
I2CWrite SDA,SCL,$A0,8,[DataA]
I2CWrite SDA,SCL,$A0,$0008,[DataA]
I2CWrite SDA,SCL,$A0,%00001000,[DataA]
I2CWrite SDA,SCL,$A0,%0000000000001000,[DataA]


Example: Write to location 8 on a 24LC32... this is CORRECT...

I2CAddress=8
I2CWrite SDA,SCL,I2CDevice,I2CAddress,[DataA]

where previously I2CAddress has been defined as a WORD, and I2CDevice has been defined as a BYTE and preloaded with $A0.

Remember that the type of VARIABLE I2CAddress must match the requirement for the device you are addressing... eg it's a WORD for devices like a 24LC32 or 24LC64, but it's a BYTE for other devices like a 24LC16 or DS1307 RTC. Check your device Datasheet.

F1CHF
- 13th April 2007, 22:53
Always and again Thanks Melanie for the support.
Just one question about the "label" at the end of a I2CWRITE command
I see in the help menu this sentence "If the optional Label is included, this label will be jumped to if an acknowledge is not received from the I2C device. "
My question :
Could we say this is a GOTO or a GOSUB command ?

I was "swimming" when I was building a prototype WITHOUT the I2C module
(TV RECEIVER MODULE) connected ....
Program was working ... let say 6 times ... and seems to go in a strange loop
... I would say a "dead loop" .... I use a Blinking led to follow the process !

I have removed this label, now it is working

Label is a sub routine with a return ...
I am sure I am wrong somewhere !
thanks in advance
Francois

skimask
- 13th April 2007, 23:00
My question :
Could we say this is a GOTO or a GOSUB command ?


It would be a GOTO command. I suppose it's a question of how you read the manual.
If the manual said 'If the optional Label is included, this label will be ----CALLED---- if an acknowledge is not received from the I2C device', then I would reasonably assume that it would be a goto...
But, the manual says 'this label will be ----JUMPED TO---- if an acknowledge....'. That tells me it's a GOTO.

If all else fails, check your .lst file and see what the compiler puts in there for you. Make a few 'special' labels so you can follow yourself thru the .lst file and search them in the file. You should be able to find what you need.

F1CHF
- 14th April 2007, 17:29
OK good, let assume this is a GOTO, that will explain my application
was going on a dead loop with a return ..
I must try to find a PBP Help File in FRENCH or read carrefully !
thanks for this help
Francois


It would be a GOTO command. I suppose it's a question of how you read the manual.
If the manual said 'If the optional Label is included, this label will be ----CALLED---- if an acknowledge is not received from the I2C device', then I would reasonably assume that it would be a goto...
But, the manual says 'this label will be ----JUMPED TO---- if an acknowledge....'. That tells me it's a GOTO.

If all else fails, check your .lst file and see what the compiler puts in there for you. Make a few 'special' labels so you can follow yourself thru the .lst file and search them in the file. You should be able to find what you need.

mister_e
- 14th April 2007, 17:37
good luck to find it in french... unless you want to try GooGLE or else on-line translator :eek: that will'nt be better ;)