I2CRead & I2CWrite not working as expected


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358

    Default I2CRead & I2CWrite not working as expected

    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.

  2. #2
    Join Date
    Jan 2005
    Location
    France
    Posts
    97


    Did you find this post helpful? Yes | No

    Default Use of the last label at the end of a I2CWRITE

    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

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by F1CHF View Post
    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.

  4. #4
    Join Date
    Jan 2005
    Location
    France
    Posts
    97


    Did you find this post helpful? Yes | No

    Thumbs up I2Cwrite error label

    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

    Quote Originally Posted by skimask View Post
    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.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    good luck to find it in french... unless you want to try GooGLE or else on-line translator that will'nt be better
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    Code:
    SDA var PORTA.1
    SCL var PORTA.2 
    T1 var byte
    T1=15
    I2CAddress var word 'I2C address
    I2CDevice var byte 'I2C device add
    i2CDevice=$A0
    I2CAddress=8
    I2CWrite SDA,SCL,I2CDevice,I2CAddress,127
    pause 100
    i2cread SDA,SCL,I2CDevice,I2CAddress,T1
    LCDOUT $FE,$c0, "value ", dEC T1
    pause 1000 
    stop
    Ports are set to digital, analog and comparators turned off. 4.7K resistors in place, 24C32 chip is brand new and authentic.
    Only VDD/VSS and SDA/SCL pins are used, others are left floating, according to datasheet.
    The interesting thing is, that i2cread returns nothing - I mean, I added T1=15 just for test, so that 15 is displayed, instead of 127
    whole i2croutine doing nothing?

  7. #7
    Join Date
    Nov 2019
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Re: I2CRead & I2CWrite not working as expected

    I have experienced an I2CREAD problem that might be related to this one. Coincidentally, I was using the DS3231 RTC device also, and it works fine with the PBP I2CREAD and I2CWRITE commands. My design also includes the Everset ES100 time code receiver (Canaduino), which responded correctly to I2CWRITE commands, but not to the I2CREAD command. I was able to enable the ES100 by writing to it, but when I tried to read its interrupt status, the ES100 clamped the I2C clock line after the I2CREAD's 3rd (read) byte.

    Referring to the lower scope screen in post #16 in this thread, it can be seen the PBP's I2CREAD command does not execute a full stop and start sequence between bytes 3 and 4 of the I2CREAD command. The ES100 requires (at the end of its 2nd byte) that the clock line be released high followed by the data line being released high (this is the stop sequence). Then, the 3rd byte starts with the data line being pulled low followed by the clock line being pulled low (the start sequence).

    In the traces below, it can be seen that start sequence at the beginning of the 4th byte is correct with the data going low followed by the clock going low, but it was not preceded by stop sequence. The data is released high followed by the clock released high rather than the reverse order.

    To solve the incompatibility of the PBP I2CREAD command with the ES100, I wrote a bit-banger routine that manipulates the clock and data lines in the proper sequences for start, stop, ack and nak, and combined these with the SHIFTOUT and SHIFTIN commands to send and receive data bytes.

    My interpretation of the I2C standard is that either a full start/stop or a restart sequence is permitted, with the restart having a slight speed advantage in time critical applications.

    The 24Cxx data sheet I checked seems to spec that only a restart sequence (that is, not a complete stop/start sequence) is required which the scope trace fulfills, but if you're really stumped on this, you might try implementing a full start/stop to see if this makes it act correctly.

    An alternate I2CREAD command addition to PBP that provides this full start/stop sequence would be nice to have.

    http://www.picbasic.co.uk/forum/atta...8&d=1633766449

Similar Threads

  1. I2cwrite - I2cread
    By savnik in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th July 2006, 01:12
  2. Problem with I2Cread and I2CWRITE function
    By Tony85 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th June 2006, 20:03
  3. Problem with I2Cread and I2CWRITE function
    By Tony85 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th June 2006, 18:32
  4. PFC8583 Connection and I2Cwrite I2cread!
    By uludere72 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 27th February 2006, 13:32
  5. I2CWRITE and I2CREAD
    By Tomas in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd April 2004, 02:30

Members who have read this thread : 8

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts