PDA

View Full Version : Beginner I2C Questions



rocket_troy
- 14th May 2013, 07:33
I have a PIC18F13K50 (Master) which I'm trying to transmit some I2C commands to a DTMF chip (PCD3312 - Slave).
The processor has an inbuilt 16Mhz oscillator so I assume I include a "DEFINE I2C_SLOW 1" declaration to operate the I2C in standard 100KHz mode? Do I need to set any additional I2C timing registers directly through the processor or does PBP look after that?
What are the suggested resistance values for the data and clock lines for I2C?
Do I need to set these pins to digital inputs or just inputs?

Thanks for any help,

Troy

rocket_troy
- 14th May 2013, 07:36
Oops:
What are the suggested resistance values for the data and clock lines for I2C?

should read: What are the suggested pull up resistance values I should use for the data and clock lines for I2C?

Thanks,

Troy

andywpg
- 14th May 2013, 14:43
Oops:
What are the suggested pull up resistance values I should use for the data and clock lines for I2C?


4.7K There's a good diagram in the manual - look at the I2CREAD command.

I've never bothered with I2CSLOW - PBP seems to set up all the registers by itself and it works fine.

Good luck!

HenrikOlsson
- 14th May 2013, 17:56
Hi,
I've never actually done anything with I2C so I'm no expert - by far.
But, in case there's some confusion, the I2READ / I2CWRITE commands are both bit-banged routines meaning they do not use the I2C peripheral (the MSSP-module) built into several PICs. This means that there really are no registers to setup except enabling the pin to work as a digital I/O, ie. make sure any analog functions are turned off on the pins in question. It also means that you can use "any" pins for the I2C-lines, not only those designated SDA and SDL in the datasheet - those are for the MSSP module which I2CREAD/I2CWRITE doesn't use.

/Henrik.

rocket_troy
- 15th May 2013, 00:33
Thanks for that guys! I'm really glad I asked! Your intuition was spot on Henrik, I was under the naive impression PBP used the MSSP module of the PIC.

Cheers,

Troy

rocket_troy
- 22nd May 2013, 00:30
Henrik and co,
Just to clarify, do I need a port with digital I/O capabilities to function for PBP's I2C communications or can I use a digital input only port? I'm using the PIC micro as the master only.

Thanks,

Troy

rocket_troy
- 22nd May 2013, 04:33
Ok, I'm really confused regarding Pic Basic and i2c at the moment. I've experimented with a simple circuit with a PIC18f13k50 using the Pic's official i2c data and clock pins and the thing worked (eventually). I've kinda transferred that same Pic(micro) and code to an established circuit that only had 2 different pins/ports available ie. not the MSSP module's i2c data & clock pins. It doesn't work. Can I gather some clarification on what pins are available for i2c use in general?

Thanks,

Troy

HenrikOlsson
- 22nd May 2013, 06:11
Hi,
Like I said earlier, I've got no experience with I2C but as far as I understand both signal pins must be digital outputs. I think that it should work on pins with open drain output (ie, pins which can only switch to GND). Pins that are input only won't work as far as I understand.

So, any two pins which can function as digital outputs should work. Make sure any analog functions on these two pins are disabled. If you need help, tell us which chip it is and post the code.

/Henrik.

rocket_troy
- 22nd May 2013, 06:29
Henrik,
The only reference I can see to "open-drain" within my PIC18f14K50 datasheet is specifically in reference to the Data and Clock pins for the MSSP module *when set to* i2c mode. I guess I'll find out tonight when I whack the PIC back into the development board and try to run i2c through other (non MSSP module) ports/pins. Worst case scenario I can butcher the circuit board to accommodate the use of the correct i2c pins, but it would be nice to be able to avoid that.

Troy

rocket_troy
- 22nd May 2013, 07:04
Okay, I just found this on a Microchip forum (to quote):
"Any PIC I/O pin can be open drain.

Let's say you are using PORTD bit 2. COnfigure this bit as an input (initially). Set the output PORTD bit 2 = 0 (or port for a 16F). When you want the output to be active low then instead of writing to the lat or port register, you write the corresponding tris big. But toggling tris you are switching the pin to input (open drain) or output low."

So, it's basically suggesting that any port with I/O functionality can be "simulated" to be open-drain. I'm guessing this is what Pic Basic does ie. toggle the TRIS register to pull a port low?

Cheers,

Troy

HenrikOlsson
- 22nd May 2013, 10:18
Hi Troy,
Yes, any pin can "simulate" open drain but an open drain pin can not "simulate" a totem-pole / push-pull output. But, after some further reading on my behalf it seems like I2C is driven in open drain mode (hence the external pullup resistors) which means that pretty much ANY output pin on your PIC should work with the PBP I2C commands.

And, the data pin is obviously switched between input and output by the I2C commands depending on if data is being sent or received.

/Henrik.

rocket_troy
- 23rd May 2013, 00:03
Henrik,
Last night I experimented some more back on the development board with other pins to check this out. Turns out that all the pins for the "B" ports worked for either the clock or the data line for i2c communication. However, I also tried port C.3 on the development board as using this pin on the main board didn't work and sure enough it didn't work on the development board either. Dunno why not. It has digital I/O functionality like all the pins/ports I tested on the *B* port; the only difference that I can see between my B and C ports is that all the digital I/Os on B ports are listed as TTL whilst all the digital inputs on the C ports are listed as Schmitt Trigger.

Thanks,

Troy

Demon
- 23rd May 2013, 00:58
Is there any Analog feature enabled on port C?

Robert

rocket_troy
- 23rd May 2013, 02:08
Demon,
That PortC.3 does have an analog input option, but I'm pretty sure I initialised everything as digital.

ANSEL = 0 'All ports digital
ANSELH = 0 'All ports digital

Of course, there's an awful lot of functionality on one of these micros so it's entirely possible I've overlooked something.

Regards,

Troy