NEW! RS-232 / I²C-Adapter & Parallel I/O Module
IIC can be implimented by onboard hardware (in the PIC's which contain such) or by "bit banging" or simulating in software the functions of the interface hardware.
Software methods are somewhat generic and can be ported from one system to another with minor adjustments. Unfortunatly, they do require that the controller process instructions much faster than would be required with a hardware implementation, so they may not be ideal for all applications
Harware solutions are specific to the processor used and seem to have been confusing for many people to use. Luckily, there are some working examples to start from:
I'm having trouble getting my I2C code to run consistently. I'm new to this site and haven't quite figured it all out, but I have posted a detailed description of my problem and code here...+
If anyone can help me get this debugged I would be very grateful! If you can help please email me (email@example.com).
I'd like to have transmit and receive subroutines for I2C that are not interrupt driven. I'd like to poll for I/O periodically, at less of an interval than a byte takes to come through.
Ref: Microchip Application note AN554, Software implementation of I2C bus master. "On initialization, these I/O lines are configured as input pins (tri-state) and their respective latchs are loaded with 0's. To emulate the high (passive), these lines are configured as inputs. To emulate the active low state, the pins are configured as outputs"Testing bcf STATUS,RP0 bcf PORTB,7 ;<- "was" the only place I set B7 bcf STATUS,RP0 ActiveLow bsf STATUS,RP0 bcf TRISB,7 bcf STATUS,RP0 bcf PORTB,7 ;<- this line is required, why? goto Done SetPassive bsf STATUS,RP0 bsf TRISB,7 bcf STATUS,RP0 Done
Why does the Data Latch need to be reset each time?
Since you're effectively trying to simulate open-collector operation on those pins, it would be assumed that you're using pullup resistors to keep the lines high when configured as inputs. You need to reset the data latch each time since when configured as an input, the pin reads high and that state goes into the PORTB register as a '1'. When you change it to an output, it's still set to a '1' so it just drives the pin high instead of sinking it like you were expecting. It's another one of those Read-Modify-Write gotchas... well, sort of.+
|file: /Techref/microchip/i2c.htm, 7KB, , updated: 2008/2/19 18:35, local time: 2018/8/21 01:18,
|©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.sxlist.com/techref/microchip/i2c.htm"> PIC Microcontoller Input / Output Methods for I2C</A>
|Did you find what you needed?|
We sell a few items to support this site
& kind contributors
just like you!
Please don't rip/copy
Copies of the site on CD
are available at minimal cost.
Welcome to www.sxlist.com!