Unfortunately your chosen PIC does not have hardware implementation of i2c Master. If you want to use h/w i2c, you'll have to change PICs.
For start/stop, etc, you have to read the datasheet of the slave. They usually show graphical timing charts that show when the individual pins must be driven high or low. For a typical eeprom, like the 24LC08b for instance, a START is this...
eeprom_start:
high data
high clock
low data
Now those are states, not commands. While you can use the command, it is not recommended for several reasons. First, i2c should have pullups, and you are supposed to turn the pin into an input to let it get pulled high. Second, you have to wait for the pin to get pulled high, and third, my preference is to avoid PBP's High and Low commands because they turn the pin into an output then set it high...and that takes too many instructions. I like to manually set the Tris register myself, and manually set the port pins--but that is personal preference.
...and eeprom_stop is this...
low data
high clock
high data
Ack is the slave acknowledging the data; usually it is pulling the data line low...
Eeprom_Ack:
repeat
until SDA_Pin = 0
After you get that worked out, you look at the byte write (for instance) timing chart. My eeprom d/s shows this timing...
Eeprom_Start
i2cout Control
Ack
i2cout Address
ack
LoopStart:
i2cout YourData
ack
If NotDoneSendingData goto LoopStart
Eeprom_Stop
If sticking with the s/w commands, you'd probably want to make your own i2c command, too. The ones built in to PBP are painfully slow because they are designed to be idiot-proof. You can see the timing charts of the d/s to learn when to pull the clock and data pins low.
It can be done and is easy for the experienced...but this is not a trivial undertaking for a newbie. TIming charts in datasheets may be initially intimidating, but once you get it it's simple.
Bookmarks