

ELECTRONICS - [designs & projects] - [I²C board] - [page 4/8]
4. SOFTWARE DESIGN
:: 4.1 General?
The circuit has been tested on an experiment board before designing the PCB print. We
noticed we had to write 2 functions: a function for getting data, and a function for sending
data. These functions can be downloaded in the download section of this site.
:: 4.2 Function for Reading
The function for the reading of data will request for data from a specific PCF8574 IC. This
function also needs an extra parameter: the address of the slave the data should be retrieved
from. This data must be placed in the register R0 before starting the reading subroutine. To
make it easier for the programmer, only symbols will be used. The name "IADDR" equals here to
the register R0. This is done by placing the text "IADDR EQU R0" on top of the assembler program.
When calling the read function, it will retrieve the data from the PCF8574. This happens by creating an I²C start condition on the bus, followed by the wanted slave address. The LSB (Read/write) bit must be 1 here. The programmer doesn't have to set this bit, this happens automatically when calling the function. If the addresses slave is present, it will reply with an ACK (acknowledge).
Now the master has to generate clock pulses, this allows the slave to send data to the master. When 8 bits are received, the master has to answer with ACK. The read data will be put in the ACCU (Accumulator), and a stop condition will be generated. The read data is still available in the ACCU now.
:: 4.3 Function for Writing
With the function for writing data, a certain value can be sent to an I²C address. The PCF8574
needs 2 parameters here: the address where the data should be sent to, and the data itself.
The address must be placed in register R0 (equivalent to IADDR), while the data to send must
be placed in register R1 (equivalent with IBYTE).
Now, the function will place data on the bus. First a start condition will be generated, and the address of the slave will be placed on the bus. The read/write bit is "0" in this address. If the addressed slave is present, it will reply with ACK.
Now the master sends the data, bit per clock pulse, to toe slave. If 8 bits are received by the slave, it will generate an acknowledge bit. After sending the data, a stop condition is being generated. The function is now executed completely.