Anyway, just as blinking a LED, i2c is a must-have protocol. Several links helped me a lot, like this one explaining the whole theory, step-by-step, message-by-message. But the most helpful documentation still remains PIC 16F88 datasheet, and the Application Note AN734A which explains quite well how to implement an i2c slave as a state-machine. An interesting post is also explaining this very same App. note has a lot of bugs. I wouldn’t say “a lot”, still there’s a little bug about clock stretching: CKP must be set to high when receiving a NACK. Anyway…
So, this time, this is about setting an i2c communication bus between two PIC 16F88, using Jal v2. The first thing to note is 16F88 implements SSP (Synchronous Serial Port), but not MSSP (Master Synchronous Serial Port). This means 16F88 can’t be just configured to act as a i2c master, all of this must be done in software. Good news is jal v2 standard libraries come with an i2c module, which can handle all the i2c protocol subtleties, from a master point-of-view…
This jal v2 master implementation isn’t based on interrupts: since it’s the master which decides to take control of the bus, there’s no need to react to external event… except when using Multi-Master i2c bus. To help this, 16F88 can be configured to generate interrupts on START/STOP bits (which defines when the bus is available or not). A Multi-Master i2c bus seems great but I didn’t give a try, regarding all the debugging time it took me to set a “simple” 1-Master/1-Slave bus.
So, the master part is ok, now the slave part. This is where things are getting tough. Particularly without any oscilloscope or digital probe/analyzer. 16F88 can be configured as a hardware slave i2c. An IC address must be set, it must be the same as the one the master is using… This is what I’ve first thought, but it’s not actually exactly true ! Actually, SSP must be configured so SSPADD contains a 8-bit address, that is, with the 8th bit setting read/write address type. Whereas in Jal, IC address is coded on 7-bits. This means, for instance:
|
Jal slave i2c master
(declared slave address) |
Hardware i2c slave address |
| 0x2E = 0b00101110 | 0x5C = 0b1011100 |
Setting a i2c bus is quite easy, from a hardware point of view. SDA and SCL pins must be connected on each side, on a bus using pull-up resistors to +5V. Different values can be used, they’re determining the stability and the bus speed. I’ve successfully tried 2.2K and 3.3K, these are standard values.
| PIC 16F88 i2c Master | PIC 16F88 i2c Slave |
| simple_i2c_master.jal | simple_i2c_slave.jal |
-
Hi,
I need to set up a communication between a ECIO40P (matrix multimedia) as master, and about 5 PIC16F88 IC’s as slaves.
I already managed to write the master program (in Flowcode) and i’m shure that works. But the program ‘Flowcode’ does not support to make a slave program, so I have to white that in C wich I do not know well.Are you able to help me a little..?
Greetings,
Jef

1 comment
Comments feed for this article
Trackback link: http://sirloon.net/i2c-com-with-two-16f88-masterslave-using-jal-v2/trackback