I2C Read and Write


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Posts
    5

    Default I2C Read and Write

    Hi I was wondering if anyone could give me a clue as to what's going wrong here, it's driving me nuts? Signals look ok as far as I can see, 4k7 pull ups fitted on both lines

    I've got a P18f252 interfaceing with a 24LC84 eeprom, it's in HS PLL mode, the eeprom is the only device on the bus...

    Any help would be appreciated.

    My code is sitting in a loop with the following code...

    'defines
    'DEFINE OSC 40 ' Operating frequency
    'DEFINE I2C_SLOW 1
    'I2C_CON CON %10100000 ' Memory I2c control byte
    'i2c_sda var PORTA.0 ' I2C serial data line
    'i2c_scl var PORTA.1 ' I2C serial clock line

    mem_off = 0;
    MyWordWr = MyWordWr+1
    i2cwrite i2c_sda, i2c_scl, I2C_CON, mem_off, [MyWordWr]
    i2cRead i2c_sda, i2c_scl, I2C_CON, mem_off, [MyWordRd]

    ram[F05_HI] = MyWordRd/256 'This register can be read over modbus
    ram[F05_LO] = MyWordRd

    ram[F10_HI] = MyWordWr/256 'This register can be read over modbus
    ram[F10_LO] = MyWordWr

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


    Did you find this post helpful? Yes | No

    Default

    'I2C_CON CON %10100000 ' Memory I2c control byte
    change this to a var, not con

    from the pbp manual:

    " Constants should not be used for the address as the size can vary dependent on the size of the constant. "
    Last edited by JD123; - 11th April 2008 at 15:04.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  3. #3
    Join Date
    Apr 2008
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Hi thanks for replying... though the 'I2C_CON CON %10100000 ' is my control byte, not the address which is 'mem_off' and declared as a word.

    I'll give it a shot though.

    Thanks again.

    Derek

  4. #4
    Join Date
    Apr 2008
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Defining the control byte as a var didn't help... so I need to keep looking (

    Also I've noticed that if I put a 10ms Pause between my write and read my serial coms stops responding, does the PAUSE command disable the interupts or something?

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


    Did you find this post helpful? Yes | No

    Default

    Make sure you have disabled all multiplexed Analog modules on the pin you're using. (ADCs and/or comparators)

    http://www.picbasic.co.uk/forum/showthread.php?t=561

    Could be interesting to see your config fuses setting... and the whole code.
    Last edited by mister_e; - 14th April 2008 at 20:28.
    Steve

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

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Well, I did a search for a 24LC84 and could not find a data sheet anywhere. What size is this part? If it is bigger than 32 kbits, then it probably needs a word size value for mem_off. For your ram_lo data I think you should mask off the upper byte by and'ing MyWordWrite and MyWordRead with 0xFF. Or use the .lowbyte and .highbyte modifiers. In fact, I don't see size definitions for any of your variables. Is mem_off a byte or word variable? Is ram a byte or word array? What are F05 and F10 defined as?
    Tim Barr

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DerekMacom View Post
    Also I've noticed that if I put a 10ms Pause between my write and read my serial coms stops responding, does the PAUSE command disable the interupts or something?
    Serial rate of 9600 baud is about 1 msec per character so a 10 msec pause could definately cause problems. The manual says this about HSERIN:

    "As the hardware serial port only has a 2 byte input buffer, it can easily overflow if characters are not read from it often enough."

    You might have to break up the pause into chunks and do a serial read in between. Maybe do 3-4 HSERIN or SERIN calls with a 2-3 msec timeout.
    Tim Barr

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


    Did you find this post helpful? Yes | No

    Default

    Tim, it doesn't look like he's using the HSERIN. Ports RA.0 and RA.1 aren't the serial ports on this PIC.
    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. write -read problem?
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th August 2009, 13:06
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  4. Write Onewire data toa I2C memory / read ASCI
    By Eugeniu in forum mel PIC BASIC Pro
    Replies: 67
    Last Post: - 16th November 2008, 19:19
  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 : 2

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