Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finite State Machine & PIC-C I2C Communication. I2C Basics I2C is a Bus. Serial is point-to-point Master and Slave pair – Master must start the communication.

Similar presentations


Presentation on theme: "Finite State Machine & PIC-C I2C Communication. I2C Basics I2C is a Bus. Serial is point-to-point Master and Slave pair – Master must start the communication."— Presentation transcript:

1 Finite State Machine & PIC-C I2C Communication

2 I2C Basics I2C is a Bus. Serial is point-to-point Master and Slave pair – Master must start the communication – Slave can only respond Slave has a 8-bit address – Bit 0 is reserved for direction control

3 Basic I2C Bus Setup MASTERSLAVE 1SLAVE 2 5V Pull-up Resistors SCL SDA

4 i2C Commands in PIC-C Master Only – I2c_start() – I2c_stop() Slave Only – I2c_isr_state() Master & Slave – I2c_read() – I2c_write() Master Only – I2c_start() – I2c_stop() Slave Only – I2c_isr_state() Master & Slave – I2c_read() – I2c_write()

5 Communication example I2c_start() I2c_write(slave addr | 0) I2c_write(data) I2c_stop() i2c_read() Data = i2c_read() interrupt state = 0 interrupt state = 1 MASTERSLAVE

6 A slave->master read example I2c_start() I2c_write(slave addr | 0) I2c_write(command) I2c_start() I2c_write(slave addr | 1) Data1 = I2c_read() Data2 = I2c_read(0) I2c_stop() i2c_read() Cmd = i2c_read() I2c_read() I2c_write(data1) I2c_write(data2) interrupt state = 0x80 interrupt state = 0 interrupt state = 1 interrupt state = 0x81 No Interrupt No i2c_stop() MASTERSLAVE

7 Data flow and slave ISR state 0xB00x010xB10x110x22 010x800x81 Slave ISR State Data Transmission (Green = Slave -> Master)

8 Download examples via SVN from http://svn.e-cpe.org/svn/i2c

9 Finite State Machine

10 Finite State Machine 2

11 Dual-I2C Sensor 1 PIC GoGo Board Sensor 2 I2c 1 (Software Based) I2c 2 (Hardware Based) Serial

12 Creating dual i2c ports // i2c1 - Master #use i2c(MASTER, SDA=PIN_B1, SCL=PIN_B2, stream=i2c_sensor) // i2c 2 - SLAVE #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xB0, FORCE_HW, stream=i2c_gogo) // Example of use I2c_start(i2c_sensor); I2c_read(i2c_gogo); …


Download ppt "Finite State Machine & PIC-C I2C Communication. I2C Basics I2C is a Bus. Serial is point-to-point Master and Slave pair – Master must start the communication."

Similar presentations


Ads by Google