I2C write - value too big


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Ruijc,

    I did not check the code in detail but at first look there is something that should not be done.

    Code:
    ....
            goto timing
            goto startmenu
            endif
            NEXT
            red=1
            return

    1. You have two "goto" s one after the other. When the first one runs, the second one will not run!

    2. When the first one runs, then you will have a return address on stack; Thus, the next time you hit a return, where ever it is, it will ruin your logic flow. You must organize a logic flow that will clear the return address of the subroutine you are in. Example: set a flag and then exit the subroutine with "return".
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    i'm a bit surprised you don't have any compilation errors...
    a) 2 mistyped IF statements,
    b) it miss Readmenu, recordmenu, timing section,
    c) and as Sayzer point-out.. those goto are a bit weird... and in case you remove Goto timing... it will branch to the startMenu indeed... but you will always add 1 on the Stack.. shortly it will overflow...

    Code:
    OSCTUNE=0
    why? You don't need to do it unless you want to calibrate the internal OSC, just remove it. Almost sure your Serial comm wasn't working really well huh? (DEFINES aren't in caps either.. but it can be a paste error)

    Code:
    I2CREAD SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[tempe]
    Why do you split addr in 2 ?
    Code:
    I2CREAD SDA,SCL,CTW,ADDR,[tempe]
    This have to be changed in ALL I2CREAD AND I2CWRITE lines

    This must be written the right way.. unless YOU will have problem indeed.
    Last edited by mister_e; - 6th April 2008 at 11:23.
    Steve

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

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi,

    I wonder the '675 was running @ 4Mhz , the '88 is running @ 8Mhz ... which is the limit for using " I2C SLOW" ...

    Did you try that DEFINE ???

    Just an idea ...
    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Not a problem for the 24LC512 unless the pull-up resistor are way to high... it can run up to 400KHz, 1MHz for FC version.

    But there's few mistakes in the code.... sure i missed a few
    Last edited by mister_e; - 6th April 2008 at 11:34.
    Steve

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

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Hello sayzer, Mister-e and Acetronics

    1. You have two "goto" s one after the other. When the first one runs, the second one will not run!
    this is true. I sampled this section from the hole code to test your help but there are some " ' " missing there.

    However, removing the missing links and compiling errors the final result is the same.


    Code:

    I2CREAD SDA,SCL,CTW,ADDR.highbyte,addr.lowbyte,[tempe]

    Why do you split addr in 2 ?
    Code:

    I2CREAD SDA,SCL,CTW,ADDR,[tempe]

    This have to be changed in ALL I2CREAD AND I2CWRITE lines
    This is my biggest problem. What you suggested was my first written code and it didnt worked.

    This was my problem in the past and resolved with the help of Skimask.
    (see post...)
    http://www.picbasic.co.uk/forum/showthread.php?t=8153

    Frankly,i didnt understood then as i still dont now, but it worked.

    The problem now is that it's not returning good values after the 127 mark and i believe that it's related with 1111111 going to 10000000 since that i read nothing but 000.x from there.

    ( see attached pic )

    .
    Attached Images Attached Images  

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Well, i think i just fixed one problem and found a new one

    I have sucessfuly use the code " I2CREAD SDA,SCL,CTW,ADDR,[tempe] ".

    After several changes i tryed Mister-e's suggestion and removed the OSCTUNE=0 line.

    It doesnt make sense to me ( or does it ? ), but it's working this way now.

    The new problem that i found is that while debugging i found out that the problem related with getting low values passed the 120'ich mark IS NOT related with the eeprom/low-highbytes.

    I got a variable resistor to simulate the LM35 and was changing the value while recording, and i could see that the value captured dropped after the conversion and before recording to the eeprom.

    this is the capture while increasing the variable resistor
    Code:
    111,3
    111,3
    111,8
    112,3
    112,3
    112,7
    112,7
    113,2
    113,7
    114,2
    114,7
    115,2
    115,7
    116,2
    117,6
    118,1
    118,6
    118,6
    118,6
    118,6
    119,1
    121
    121,5
    122
    122,5
    122,5
    122,5
    122,5
    0,4
    0,9
    0,4
    0,9
    0,4
    0,9
    0,4
    0,9
    0,4
    0,9
    now i'm lost

    .
    Last edited by ruijc; - 6th April 2008 at 13:37.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi, Ruicj

    Can you tell us how you get those values :

    ( 122.5 is NOT a PbP value ...)

    - Input value range ( volts ? ) / ref voltage
    - Math used ( in PbP )
    - Values you want to to output

    It's "not so clear" ...

    Alain

    PS : ANSEL doesn't match the ADCIN PORT !!! Check it !!!
    Last edited by Acetronics2; - 6th April 2008 at 13:51.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Hello Acetronics,

    these values i get from:

    Code:
    FOR ADDR=st TO ed
         
       		adcin temp,va
     
    tempe=(va*/5000 )>>2
    
            toggle red
            toggle green
            pause   418    ' calibration to get  1200  readings  ( 2 per second ) in 10 minutes   - 
            debug " recorded value: ", dec tempe," position  ", dec ADDR, 13,10
    the debug line gave these values after the adcin conversion.
    I'm colecting the voltage directly from the variable resistor which is simulating the voltage from a LM35 ( 0,2v - 1,5V )
    I'm not using any reference value, just VDD and VSS( i know...it's lame...but i'm not looking for the best resolution for now )

    .

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    seen it ???

    : ANSEL doesn't match the ADCIN PORT !!! Check it !!!

    ANSEL select A1 and A2
    ADCIN select A0 ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

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