View previous topic :: View next topic |
Author |
Message |
Pets
Joined: 06 May 2019 Posts: 6
|
Disable Open-Drain on SW I2C using PIC18F46K22 |
Posted: Fri May 31, 2019 10:45 am |
|
|
I am implementing a software I2C bus on a PIC18F46K22.
- Single Master Network
- SCL is on PIN_A2
- SDA is on PIN_D3
The problem is that the I2C clock and data pins are open-drain which causes an issue with EMI filters.
I would like to force these pins to push-pull.
The PIC18F46K22 datasheet does not show a register (ODCONx) for push-pull / open-drain configuration.
How can a software implementation of a I2C network force a GPIO pin to use open-drain if there is no configuration register for open-drain? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri May 31, 2019 11:03 am |
|
|
I2C is not push-pull. It _relies_ on the slave device being able to send
on the same data wire as the master, and the slave being able to suspend
operation for a moment while preparing it's reply, by holding the clock
low. Also controlling the clock is how ACK/NACk is signalled.
<https://www.silabs.com/community/mcu/8-bit/knowledge-base.entry.html/2015/10/19/why_do_i2c_pins_have-w3JL>
You cannot use push-pull driving with an I2C device. It won't work.
The PIC achieves open collector driving, by having the pin set 'low',
and then setting the pin to drive, or float as an input. Result drive low
only.
Describe your 'EMI filters.
I2C is only a 'local' bus. Designed for a few inches of transmission on
a board, or between close boards. If you need longer distances, then
you need to look at using a signalling standard designed for this, not
I2C. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
Re: Disable Open-Drain on SW I2C using PIC18F46K22 |
Posted: Fri May 31, 2019 11:07 am |
|
|
Pets wrote: | I am implementing a software I2C bus on a PIC18F46K22.
- Single Master Network
- SCL is on PIN_A2
- SDA is on PIN_D3
The problem is that the I2C clock and data pins are open-drain which causes an issue with EMI filters.
I would like to force these pins to push-pull.
The PIC18F46K22 datasheet does not show a register (ODCONx) for push-pull / open-drain configuration.
How can a software implementation of a I2C network force a GPIO pin to use open-drain if there is no configuration register for open-drain? |
The open drain is not a problem, it is fundamental to how the I2C bus works. It is up to the implementer to incorporate pull up resistors on the I2C bus. These are typically 4.7K resistors although commonly you will see 10K resistors used especially when you have multiple I2C modules on the bus.
To use a SW I2C is straight forward. Define the port as fast I/O, set it as an input and write a 0 to the port latch. Now to use it to be active high you simply set the port bit as an input. To write a logic 0 you set the port as on output. Because you have previously written a 0 to the output latch, changing the pin to an output will set the output pin low. Setting the port bit again as input lets the external pull-up resistors pull the bus high. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Fri May 31, 2019 11:14 am |
|
|
Ttelmah wrote: | I2C is only a 'local' bus. Designed for a few inches of transmission on a board, or between close boards. If you need longer distances, then you need to look at using a signalling standard designed for this, not
I2C. |
Naturally there are exceptions. There are standard I2C line drivers from multiple vendors designed to extend the I2C bus over much longer distances. An example, which I use, is to have remote data acquisition modules connected back to a central logger. Previously this would have required a processor on the remote modules to interrogate the sensors on the remote module and then interface to the centralized logger via some other bus such as RS422, RS485 etc. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri May 31, 2019 11:33 am |
|
|
Agreed. However using this requires buffers at both ends of the bus,
not 'standard' I2C, with it's normal 3mA drive capability.
I have done I2C at 12v to a sensor head using P82B96 transceivers.
Big advantage also is that this type of configuration also supports
higher bus capacitances, which I suspect will be the problem with his
'EMI filters'.
However it is also worth realising that if the slave device supports higher
drive currents than 'standard', he might well be able to solve the
problem by simply using lower pull up resistor values. The standard
drive merrily supports 1500R at 5v, and if he is only using resistors
like 10K, this may be the whole problem... |
|
|
Pets
Joined: 06 May 2019 Posts: 6
|
|
Posted: Fri May 31, 2019 12:55 pm |
|
|
Thanks All...
Ttelmah - I agree with a different type bus... problem is this is not my hardware. I am in the process of requesting the MFG to change it to an RS485 bus.
As a temp fix I used the NOFLOAT_HIGH in the #use I2C statement |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri May 31, 2019 1:35 pm |
|
|
This only affects the transition from low to high when the master is
driving the line. When the slave device is driving the bus still floats.
Try reducing the pull up resistors. What value has been used?. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri May 31, 2019 2:46 pm |
|
|
I'd like to know more about these 'EMI filters' ! MFR, make, model, etc....
If there is an EMI problem then EVERY pin of the PIC might be affected as well as ALL peripheral devices.
My energy control system can run on 15 miles (yes MILES) of copper wire and even near lightning strikes don't affect communications.
Jay |
|
|
Pets
Joined: 06 May 2019 Posts: 6
|
|
Posted: Fri May 31, 2019 2:52 pm |
|
|
Thanks All
Problem is this is not my hardware. I am in the process of requesting the MFG to change it to an RS485 bus. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sat Jun 01, 2019 5:01 am |
|
|
I'm curious, what is the distance between PIC and the I2C peripheral ?
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sat Jun 01, 2019 7:40 am |
|
|
and what is the value of the pullups. |
|
|
|