I2C Read and Write


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1


    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

  2. #2
    Join Date
    Apr 2008
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    First of all sorry it was a typo.... it trying to talk to a 24LC64.

    I am switching the ADC off with ADCON1 = $07, been caught with this one before. Though in this project I'm reading one of the ADC channels, so this might be worth a look.

    Fuse setting's are all default apart from HS PLL enabled.

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


    Did you find this post helpful? Yes | No

    Default

    Is the "mem_off" variable word size? The 24C64 uses a word sized address. Your variable "mem_off" is being sent as the address. Also, just asking, but you do have the A0:A2 pins on the IC grounded for the device address "1010000", right?

    Your lines:
    Code:
    ram[F05_HI] = MyWordRd/256 'This register can be read over modbus
    ram[F05_LO] = MyWordRd
    are a bit odd and are going to run up a lot of code space. I'd use:
    Code:
    ram[F05_HI] = MyWordRd.Highbyte
    ram[F05_LO] = MyWordRd.Lowbyte
    Last edited by JD123; - 15th April 2008 at 17:07.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Alright let's try some simple things. Are the A0, A1,and A2 pins are tied to ground or VCC? These address pins also need to be correctly selected in the control byte. For the control byte you are using they should be all grounded. Is the WP pin floating or connected to gnd?

    You definately need some way of waiting 10 msec between writing and reading or you will get a NACK from the part and no read data. Also, if you want to use interrupts to manage the serial port, you will probably have to write your own serial port interrupt routine. The PB code is not really interrupt driven itself. From the PBP manual:

    "Since PBP statements are not re-entrant (PBP must finish the statement that is being executed before it can begin a new one) there could be considerable delay (latency) before the interrupt is handled."

    edit: Like minds, eh JD??
    Tim Barr

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


    Did you find this post helpful? Yes | No

    Default

    Seems so, Tim. I didn't notice the lack of a 10ms pause though. Good catch.
    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, 23:31
  2. write -read problem?
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th August 2009, 14:06
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 22: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, 20:19
  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