I2C write - value too big


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1

    Default I2C write - value too big

    Hi all,

    i have found a bug in my temperature logger (16F88 + 24LC512+LM35).
    I works pretty well until it reaches temp values of 124șC, for values above it are displayed as 0șC or 0,5șC.

    I've looked at my code and i think a know what the problem is: I need to separate the variable into lowbyte and highbyte.

    The problem is that i'm not being able to get this working that way. Here's why :


    This way does not work:
    Code:
    I2CWRITE SDA,SCL,CTW,ADDR,[tempe.highbyte]
    pause 10
    ADDR=ADDR+1
    I2CWRITE SDA,SCL,CTW,ADDR,[tempe.lowbyte]
    This way does not work:
    Code:
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[tempe.highbyte]
    pause 10    
    ADDR=ADDR+1
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[tempe.LOWBYTE]
    Only this way one works:
    Code:
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[tempe]
    pause 10    
    ADDR=ADDR+1
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[tempe]
    Long story short:
    I can make it work with the eeprom BUT only with Address high and low. If i try to separate the variable tempe into high and low it doesnt work

    Any ideas ?
    Thanks
    .
    Last edited by ruijc; - 5th April 2008 at 15:43.

  2. #2
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Use a word size variable. PBP will read the two bytes. Check PBP manual for the loading order. You may have to flip .highbyte and .lowbyte outside the I2CREAD statement.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help JD123,

    The variable is already a word sized.

    You may have to flip .highbyte and .lowbyte outside the I2CREAD statement
    Outside ? How is this done ?

    .

  4. #4


    Did you find this post helpful? Yes | No

    Default

    checked the PBP manual and did some changes to the code but did not worked ( not sure this is what you mean ):

    what i did:

    Added alias
    Code:
    tempe   var  word
    
    temp1   var tempe.highbyte
    temp2   var tempe.lowbyte
    saving data to eeprom
    Code:
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[temp1]
    pause 10    
    ADDR=ADDR+1
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[temp2]
    .

  5. #5
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ruijc View Post
    checked the PBP manual and did some changes to the code but did not worked ( not sure this is what you mean ):

    what i did:

    Added alias
    Code:
    tempe   var  word
    
    temp1   var tempe.highbyte
    temp2   var tempe.lowbyte
    saving data to eeprom
    Code:
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[temp1]
    pause 10    
    ADDR=ADDR+1
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[temp2]
    .
    Just use:

    I2CWRITE SDA,SCL,CTW,ADDR,[TEMP]

    In both ADDR and TEMP they are word size and PBP will send each byte out for the word - no need to bust them up and send them individually.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Just use:
    I2CWRITE SDA,SCL,CTW,ADDR,[TEMP]
    This was my first option, but for some reason the eeprom does not store the data this way.

    Actually, with the 12F675 chip this eeprom works well with :
    Code:
    I2CWRITE SDA,SCL,CTW,ADDR,[temp.highbyte]
    pause 10
    ADDR=ADDR+1
    I2CWRITE SDA,SCL,CTW,ADDR,[temp.lowbyte]

    But not with the 16F88.

    I got it working with :
    Code:
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[tempe]
    pause 10    
    ADDR=ADDR+1
    I2CWRITE SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[tempe]
    The problem now is for the lenght of the tempe value when over 125șC

    .

  7. #7
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Just the use of a word size variable, invokes PBP to read two bytes. It places the first byte in the var.highbyte and the second in the var.lowbyte. EDIT: Sorry, I didn't see that you were not writing, not reading - this is for reading)

    If this is not the order you want, you'll have to exchange the two bytes outside the I2C instruction. I'm not sure of all the techniques (like using PBP SWAP) will work, but it's a standard process that can be done using a temporary 'working' word size variable.

    temp.highbyte = var.lowbyte
    temp.lowbyte = var.highbyte
    var = temp
    Last edited by JD123; - 5th April 2008 at 16:41.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. Replies: 5
    Last Post: - 29th May 2008, 18:03
  4. PIC16F877 I2C programme
    By cooqo in forum mel PIC BASIC
    Replies: 3
    Last Post: - 21st April 2008, 10:02
  5. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33

Members who have read this thread : 0

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