PDA

View Full Version : I2C Write & Read



dallowgill
- 14th June 2011, 17:09
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

mister_e
- 14th June 2011, 17:25
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 ;)

Darrel Taylor
- 14th June 2011, 18:02
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.

dallowgill
- 14th June 2011, 22:40
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

dallowgill
- 14th June 2011, 23:06
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