Whats wrong with this I2C code???? HELP?


Closed Thread
Results 1 to 8 of 8
  1. #1
    yourmomOS's Avatar
    yourmomOS Guest

    Angry Whats wrong with this I2C code???? HELP?

    Im using a 16f628 and a 24LC512 i2c eeprom. Im pretty sure I have the eeprom wired up correctly as per the datasheet. I put in some labels to jump to incase the i2cwrite or read didnt work, I never get to them so Im assuming I am writing correctly, When I read, I get weird junk. I cant figure it out, someone please look at the code below and tell me what is wrong!

    'set OSC freq
    Define OSC 20
    ' Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h
    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA 20h
    ' Set baud rate
    DEFINE HSER_BAUD 9600
    'clear flag automatically when serial hardware buffer overflows
    DEFINE HSER_CLROERR 1
    CMCON = 7 'Turn off comparator

    dpin var PORTA.0 'eeprom data pin
    cpin var PORTA.1 'eeprom clock pin
    eaddress var word 'eeprom address
    temp var byte

    MAIN:
    HSEROUT ["Working", 10, 13]

    temp = 40
    eaddress = 0
    i2cwrite dpin, cpin, $A0, eaddress, [temp], DIDNTWRITE
    pause 200
    temp = 41
    eaddress = 1
    i2cwrite dpin, cpin, $A0, eaddress, [temp], DIDNTWRITE
    pause 200
    temp = 42
    eaddress = 2
    i2cwrite dpin, cpin, $A0, eaddress, [temp], DIDNTWRITE
    pause 200
    temp = 43
    eaddress = 3
    i2cwrite dpin, cpin, $A0, eaddress, [temp], DIDNTWRITE
    pause 200

    hserout ["done writing to eeprom", 10, 13]

    eaddress = 0
    i2cread dpin, cpin, $A0, eaddress, [temp], DIDNTREAD
    pause 200
    hserout [temp]
    eaddress = 1
    i2cread dpin, cpin, $A0, eaddress, [temp], DIDNTREAD
    pause 200
    hserout [temp]
    eaddress = 2
    i2cread dpin, cpin, $A0, eaddress, [temp], DIDNTREAD
    pause 200
    hserout [temp]
    eaddress = 3
    i2cread dpin, cpin, $A0, eaddress, [temp], DIDNTREAD
    pause 200
    hserout [temp]

    hserout ["done reading", 10, 13]
    pause 2000
    goto main

    DIDNTWRITE:
    HSEROUT ["WRITE DIDNT HAPPEN"]
    PAUSE 1000
    GOTO MAIN

    DIDNTREAD:
    HSEROUT ["DIDNT READ"]
    PAUSE 1000
    GOTO MAIN

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


    Did you find this post helpful? Yes | No

    Default

    ......................... forget me, i didn't read correctly

    i need to sleep
    Steve

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

  3. #3
    yourmomOS's Avatar
    yourmomOS Guest


    Did you find this post helpful? Yes | No

    Thumbs down Anyone???

    Dont everyone help at once now!

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


    Did you find this post helpful? Yes | No

    Default Be calm, life is short

    something is wrong in your hardware and/or configuration fuses... it's working here. Be sure you have place 4.7K or lower on the scl and SDA line and it should work... unless you have reverted the SDA and SCL

    If at least you have serial communication, the PIC is working at the great and at the right speed wich reject the config fuses problem

    but i don't have the LC512, as now i didn't have any requirement for those... just the LC128 so it can exist some difference between... wich i doubt after a really fast datasheet reading.
    Steve

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

  5. #5
    yourmomOS's Avatar
    yourmomOS Guest


    Did you find this post helpful? Yes | No

    Question thanks for helping, but I found what appears to be the problem

    The DIDNTWRITE and DIDNTREAD are never jumped to when it does not read or write. I have even removed the cables going to the eeprom but it never goes to the label. I have a 24LC512 and a pic 16f628. Has anyone seen this before?

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


    Did you find this post helpful? Yes | No

    Default

    You have a hardware problem... OR you don't have pull-resistor as shown in the PBP manual and in the datasheet, OR your PIC is defect, OR you have some short circuit somewhere.

    EEprom with Pull up
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=968&stc=1&d=1152732703 ">

    EEPROM no pull-up
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=967&stc=1&d=1152732703 ">

    NoEEPROM With pul-ups
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=969&stc=1&d=1152732703 ">
    Attached Images Attached Images     
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    NoEEPROM No Pull ups
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=970&stc=1&d=1152732703 ">
    Steve

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

  8. #8
    yourmomOS's Avatar
    yourmomOS Guest


    Did you find this post helpful? Yes | No

    Default Problem Solved, Sort Of

    I started playing around and found out that if I disconnect the ground wire, the things start working. I tried different chips, different slots in my breadboard and different connector wires. Its the damndest thing. pin 4 should be connected to ground, but spits out garbage when I connect it, works when I disconnect it.

Similar Threads

  1. PIC18F4620 , what's wrong with my A/D converter code
    By Porcusoru in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd July 2009, 20:35
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. PIC16F877 I2C programme
    By cooqo in forum mel PIC BASIC
    Replies: 3
    Last Post: - 21st April 2008, 10:02
  4. Code for I2C Slave
    By Balachandar in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st November 2006, 19:14
  5. Anyone have ADS1100 I2C PicBasic Pro code example
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th March 2006, 22:13

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