12F629 I2C problems


Closed Thread
Results 1 to 4 of 4
  1. #1
    AIW128ProGuy's Avatar
    AIW128ProGuy Guest

    Default 12F629 I2C problems

    Hi everyone. I am trying to simply interface a 12F629 with an external eeprom (24AA00) using PicBasic Pro's I2CWrite and I2CRead commands. However, it never seems to interface correctly. My circuit looks like this:

    .................................................. ................
    .................+5V.....1...8.....GND............ ....... 12F629
    ..................LED.....2...7.....--------------|......
    ..................LED.....3...6.....----------|....|......
    .....+5V-->1k-->.....4...5...................|....|......
    .................................................. ...|....|.....
    .................GND.....1...8.....+5V.........|.. ..|..... 24AA00
    .................GND.....2...7.....GND.........|.. ..|......
    .................GND.....3...6.....----------|....|......
    .................GND.....4...5.....--------------|......
    .................................................. ................

    Where SDA Pin7-->Pin5 and SCL Pin6-->Pin6
    Also, I have a 4.7k resistor connected from +5V-->Pin6 on the 24AA00 to act as a pullup. Same thing for Pin5 on the 24AA00.

    My code is very simple too. It is below:

    value var byte
    I2CWrite GPIO.0,GPIO.1,$A0,1,[3]
    pause 20
    I2CRead GPIO.0,GPIO.1,$A1,1,[value]
    pause 20
    if value=3 then
    high 5
    else
    high 4
    endif
    End

    This will simply write to the eeprom and read back from it. If it reads back the value it wrote, then the LED5 should turn on, if not, the LED4 should turn on. It only ever turns on LED4. I am not sure what the problem is. I have tried many many things, but nothing has worked. Please let me know what your thoughts are. Thankyou very much.



    Chris

    P.S. - Miscellaneous Information:
    Programmer: IC-Prog 1.05C
    Fuses: WDT, PWRT, MCLR, BODEN
    Bandgap: Default
    Oscillator: IntOSC GP4
    Adding CMCON=7 doesn't seem to matter
    Sending a word instead of a byte doesn't seem to matter

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


    Did you find this post helpful? Yes | No

    Default

    Try this one and post result
    Code:
    CMCON=7 ;disable internal comparator
    TRISIO=0  ;set pins to outputs
    
    LED1 VAR GPIO.5 ;define GP5 as LED1
    LED2 VAR GPIO.4 ;define GP4 as LED2
    
    cont  var byte ;variable for control word of eeprom
    value var byte 
    
    cont=$A0 ;control word of eeprom
    
    value=3
    I2CWrite GPIO.0,GPIO.1,cont,1,[value]
    pause 20
    I2CRead GPIO.0,GPIO.1,cont,1,[value]
    pause 20
    if value=3 then
        LED1=1
        LED2=0
    else
        LED2=1
        LED1=0
    endif
    End
    regards
    Steve

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

  3. #3
    AIW128ProGuy's Avatar
    AIW128ProGuy Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Steve, Good news. I tried your program and it works! I guess it just wanted me to use variables instead of hard coding the I2C statements. Or, maybe I just needed to add the TRISIO to set the pins as outputs. There is a weird anomaly going on though. Most of the time when I power it on, other leds flash on for a second then are off. To debug this, I put a pause right under the TRISIO statement. The leds stayed on much longer, then started dropping out one by one. Also, if I have GPIO.0 and GPIO.1 connected to a led, as well as the SDA and SCL lines, the program doesn't work. Any ideas on this? Other than that, the program works great!


    Thanks for your help.
    Chris

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


    Did you find this post helpful? Yes | No

    Default

    > I tried your program and it works! I guess it just wanted me to use variables instead of hard coding the I2C statements. Or, maybe I just needed to add the TRISIO to set the pins as outputs. There is a weird anomaly going on though. Most of the time when I power it on, other leds flash on for a second then are off.

    For sure you must use variable in I2Cread/I2Cwrite statement. It's always safe to assign pin to TRIS statement. Looks in some case on 12Fxxx, if you don't set TRISIO, the output don't work properly .


    > There is a weird anomaly going on though. Most of the time when I power it on, other leds flash on for a second then are off.

    it can be safe to set LED output on a specific state at the begining.

    GPIO.0=0
    GPIO.1=0
    GPIO......

    Be sure to pull down/up unsused pin with resistor <10K. Also i see often an noisy PSU who screw the PIC when starting. Safe if you add 0.1uF + 10uF (tantal or 47uF electrolytic)


    >Also, if I have GPIO.0 and GPIO.1 connected to a led, as well as the SDA and SCL lines, the program doesn't work. Any ideas on this? Other than that,

    Do you place led to monitor pins of EEPROM? in this case it's absolutely normal, EEPROM may not provide enough current to drive/sink LED.

    regards
    Steve

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

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. I2C Read/Write problems
    By Dispersion123 in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 5th April 2008, 16:11
  4. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 20:33
  5. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 14:55

Members who have read this thread : 1

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