Quote:
So it is fairly easy to interface an I2C through a 65C22 then?
Absolutely, but you'll have to bit-bang, ie, not use the VIA's serial port. Pick two I/O bits you want to use, and write your tiny building blocks more or less in this order (these are the names I gave the routines):
Code:
INIT_I²C
I²C_CLK_UP
I²C_CLK_DN
I²C_DATA_UP
I²C_DATA_DN
I²C_DATA_IN ; for data direction
I²C_DATA_OUT ; for data direction
I²C_START ; to produce the I²C "start" condition
I²C_STOP ; to produce the I²C "stop" condition
I²C_ACK ; to produce the "acknowledge" bit at the end of a frame
I²C_NAK ; to produce the "not-acknowledge" bit at the end of a frame
I²C_ACK? ; to check the ACK bit sent by a slave device
RD_I²C_BIT
SEND_I²C_BIT
RCV_I²C_BYTE
SEND_I²C_BYTE
then write the building blocks that are particular to the devices you want to interface, for example for the 24256 EEPROM:
Code:
POLL_EEPROM
WAIT_TIL_EEPROM_RDY
SEND_EEPROM_ADR
WR_EEPROM_BYTE
WR_EEPROM_ADR
WR_EEPROM_PAGE
RD_EEPROM_BYTE
RD_EEPROM_STREAM
For the bi-directional data (and possibly clock too, but it's not always necessary), you can leave the output bit on the VIA a zero, then just change the bit in the data direction register so it's an input to let the pull-up resistor pull it up if neither the master nor the device is pulling it down. If you want to output a 1, just leave it in input mode, and if you want to output a 0, make it an output so the 0 in the output bit will pull the line down.