Connect an RS232 via a resistor to a PIC16F819, with SDA and SCL pulled up and you can explore IIC.
Connect other IIC 7 bit devices and send and receive bytes from them.
It is possible to get the chip to talk to itself.
http://www.dougrice.plus.com/dev/iic001/iicrs001.ASM
; Uses PIC16F819 ; ; Pull up SDA and SCL pins with 4k7 resistors, ; ; SERIAL PORT CONTROL: ; ; PORT A0 is Serial input ; PORT A0 is serial output ; ; usb gmus-03 USB Serial Adapter ; ; TX D9 Pin 3 -[4k7]----+-----PA0 ; RX D9 Pin 2 ----------/ ; ; GND D9 Pin 5 ---------------- 0V ; ; ; Serial Commands:- ; ; ; w,p,r,g,f,a ; ; ; File Regiters ; <CR>wAADD; write DD to register AA ; <CR>rAA; read AA and output to serial port ; ; EEPROM ; <CR>pAADD; write DD to EEPROM register AA ; <CR>gAA; read EEPROM register AA and output to serial port ; ; PRIPHERALS ; ; IIC master commands to set to slave and master. ; Master is done by code. EEPROM ; ; <CR>iAA; IIC init set Addr = AA ; ; <CR><AA; IIC START , ADDR , set lsb for R/W ; <CR>>; IIC STOP ; <CR>/DD; IIC master writeByte ; <CR>?; IIC master readByte & ACK. If you get ~, SCL is being held low and read has timed out. ; <CR>~; IIC master readByte & NACK. If you get ~, SCL is being held low and read has timed out. ;
This is some code to demo i2c slave on the PIC16F886 and some C code to run on the Raspberry Pi to use the IIC bus.
I brought the Microchip Serial Analyser that has two boards with PIC16F886 chips.
I can connect the board to the Raspberry Pi using a level shifter.
Code for the PIC16F886 to set it up as I2C slave at address 0x08. http://www.dougrice.plus.com/dev/iic001/test16f886.c
This seems to work, but the i2cdump gets read errors
Code for the Raspberry Pi. http://www.dougrice.plus.com/dev/iic001/rppic.c
The PIC16F886 has a slave address 0f 0x08 or SSPADD = 0x10;
ADDR: 0 0 0 1 0 0 0 RW
This sends bytes. The lower nibble are displayed on the LEDs and reads a counter that increments for each read to check if it is working.
The Microchip I2C slave is a challenge to get to work.
The firmware polls the SSPIF flag and does not use interrupts. It uses clock stretching.
The signals from the Microchip IIC slave hardware:-
START DA address or data BF buffer full RW Read / Write CKP used for clock stretching and read ACK / NACK STOP
This is demo i2c slave code to try out setting the PIC16F886 as a I2C slave, to try it out.
The C code to run on the Raspberry Pi is debug code.
Raspberry Pi code for LCD display driven with IIC module sold on ebay.
http://www.dougrice.plus.com/dev/iic001/rpcf.c