Download presentation
Published byRodolfo Chatham Modified over 10 years ago
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 SDA SCL MASTER SLAVE 1 SLAVE 2 5V
Pull-up Resistors SDA SCL
4
i2C Commands in PIC-C Master Only Slave Only Master & Slave
I2c_start() I2c_stop() Slave Only I2c_isr_state() Master & Slave I2c_read() I2c_write()
5
Communication example
MASTER SLAVE I2c_start() I2c_write(slave addr | 0) I2c_write(data) I2c_stop() i2c_read() Data = i2c_read() interrupt state = 0 interrupt state = 1
6
A slave->master read example
I2c_start() I2c_write(slave addr | 0) I2c_write(command) 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 = 0 interrupt state = 1 No i2c_stop() interrupt state = 0x80 No Interrupt interrupt state = 0x81
7
Data flow and slave ISR state
Data Transmission (Green = Slave -> Master) 0xB0 0x01 0xB1 0x11 0x22 Slave ISR State 1 0x80 0x81
8
Download examples via SVN from
9
Finite State Machine
10
Finite State Machine 2
11
Dual-I2C PIC I2c 1 Serial I2c 2 Sensor 1 Sensor 2 (Software Based)
GoGo Board I2c 1 (Software Based) Serial I2c 2 (Hardware Based)
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); …
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.