I2C Write & Read


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2011
    Posts
    3

    Smile I2C Write & Read

    Hi I am new to this Forum so will say hello to all firstly. I have a question regarding the PBP commands I2CWRITE & I2CREAD and hope someone can shine some light on it. I am successfully writing and reading to/from a 24C01 EEprom, with a Pic 18F2620 chip and am using bits 3 and 4 of PORTA. My question is do the PBP commands used handle the setting up of PORTA, regarding them being digital and not analogue? Having used pics before I am aware of commands like ADCON1 = 7 and CMCON = 7. But have found they make no difference to the operation of the I2C commands. Do I presume right thinking PBP handles the setting of PORTA from analogue default to digital usage. I am asking this to be sure things are working correctly, as this is a security lock application.

    Many thanks in anticipation of any replies
    Last edited by dallowgill; - 14th June 2011 at 17:16. Reason: Typo

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


    Did you find this post helpful? Yes | No

    Default Re: I2C Write & Read

    Welcome !
    None PBP command take care of the mutliplexed analog stuff. The only thing it take care of is set the pin as input/output (TRISA, TRISB, etc)

    Sure sometimes it may work, call yourself lucky then
    Steve

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

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: I2C Write & Read

    True, PBP does not automatically enable Digital Inputs on Analog pins.

    But I'll take a guess and say that you are using PORTA.3 for the clock (SCL), and PORTA.4 for (SDA).
    If they were the other way around it would not work.

    PORTA.4 doesn't have an "AN?" input on that pin.
    So it can be used for DIGITAL I/O without setting an ADCON1, ANSEL or other registers.

    PORTA.3 does have an "AN?" input.
    But it's the Digital Input that's disabled, so the CLK output will still work.

    If you were using any of the other PORTA pins as digital output, it could have a BAD effect on the I2CREAD/WRITE commands due to the R-M-W problem, so it will be best if you Enable the Digital Input on that pin using the ADCON1 register.
    DT

  4. #4
    Join Date
    Jun 2011
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: I2C Write & Read

    Hi Steve
    Thanks for the reply that is very helpful I had a sneaky feeling that what you say, is the case with I/O on PORTA and the PBP commands in question. At least I know a little bit more about PBP and pics in general. Hey I got lucky ? By Heck then I better do the Lottery this week. I will enjoy this Forum I am sure very informative.

    Cheers Alan

  5. #5
    Join Date
    Jun 2011
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: I2C Write & Read

    Hi Darrel
    Thanks also to you for a timely reply and very thorough as well. Very impressed with your telephathic powers, indeed PORTA.3 is (SCL) and PORTA.4 is (SDA). Nice explanation I see what is going on now, sounds like you have wrestled a bit with I2C and PORTA, can see how PORTA.3 functions as the clk and of course as you say there is no Analogue in on PORTA.4.
    Will do as you say and apply what you have said and in light of the read-modify-write issue I may move (SCL) & (SDA) to a couple of bits on PORTB, then I know for sure that the software will be able to decode the entry code recovered from eeprom, to enable opening of the door on my electronics den. Which if the lock did not actuate would, probably have me howling at the moon or resorting to an impression of Jack Nicholson with the Axe in The Shining. many thanks and a great Forum.
    Regards Alan

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