1 / 12

Finite State Machine & PIC-C I2C Communication

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 Slave can only respond Slave has a 8-bit address Bit 0 is reserved for direction control. Basic I2C Bus Setup. 5V. MASTER.

mohawk
Download Presentation

Finite State Machine & PIC-C I2C Communication

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 5V MASTER SLAVE 1 SLAVE 2 Pull-up Resistors SDA SCL

  4. i2C Commands in PIC-C Master Only • 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 MASTER SLAVE 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 = 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) Slave ISR State

  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 PIC Sensor 1 Sensor 2 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); …

More Related