Beginner I2C Questions


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Beginner I2C Questions

    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

  2. #2
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Re: Beginner I2C Questions

    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

  3. #3
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159

    Default Re: Beginner I2C Questions

    Quote Originally Posted by rocket_troy View Post
    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!
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default Re: Beginner I2C Questions

    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.

  5. #5
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Re: Beginner I2C Questions

    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

  6. #6
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Re: Beginner I2C Questions

    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

  7. #7
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Re: Beginner I2C Questions

    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

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default Re: Beginner I2C Questions

    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.

  9. #9
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Re: Beginner I2C Questions

    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

  10. #10
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Re: Beginner I2C Questions

    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

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default Re: Beginner I2C Questions

    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.

  12. #12
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Re: Beginner I2C Questions

    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

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598

    Default Re: Beginner I2C Questions

    Is there any Analog feature enabled on port C?

    Robert

  14. #14
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    132

    Default Re: Beginner I2C Questions

    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

Similar Threads

  1. Beginner help!
    By Recognize in forum General
    Replies: 14
    Last Post: - 26th April 2012, 14:55
  2. I2C howto questions
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 27th May 2010, 18:39
  3. i2c PBP questions
    By TimV in forum General
    Replies: 14
    Last Post: - 5th February 2007, 17:58
  4. Questions about i2C EEPROM
    By RunningMan in forum General
    Replies: 3
    Last Post: - 29th January 2007, 04:09
  5. Still new to PicBasic - i2c questions
    By cometboy in forum mel PIC BASIC
    Replies: 4
    Last Post: - 13th November 2006, 18:27

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