More on I2C
|Top Previous Next|
This topic a continuation of the discussion started in Sending and Receiving Data.
I2C (and many existing variations on it) relies on a single data line (called "SDA") for data transmission in both directions. DO and DI lines of the SSI channel must be joined together. On devices with unidirectional I/O lines, the ssi.zmode property must be set to 1- PL_SSI_ZMODE_ENABLED_ON_ZERO (not required on devices with bidirectional I/O lines). The DO line will then operate in the following manner:
It follows then, that if your DO and DI lines are joined together, and you want to receive data from the slave device, you should keep your own output at "all 1s" while the slave device is supposed to send data, like this:
Each I2C transaction requires so-called start and stop sequences — the ssi. object won't handle this so you need to implement this in code. Below is a snippet from a real application. Notice how necessary transitions on the SDA line are performed by setting the DO line LOW and then enabling/disabling its output buffer.