Hello.
I modified the code I put in the previous post. I have tried this programobserving the SDA line with an oscilloscope and no signal has not appeared. Does anyone know why?
does anyone know how I can check the SDA line with the simulator codewarrior (True -Time simulator & real-time debugger)?
The void set_address (char dir, char RW) function is the same, and is responsible for placing in the IICD register a byte that consists of the slave address shifted one position to the left plus the read or write bit being this the LSB.
void set_address(char dir,char RW){
aux_dir= dir<<1;
aux_dir&=0x0F;
IICD=aux_dir|PCF8574A_ADDR_FIXED|RW;
}
The IIC_write_byte function (char data, char dir) is also the same and is responsible for sending a data byte (char data) from master to slave. First send a start signal (MS = 1), then a byte containing the slave address shifted one position to the left,plus the write bit being this the LSB. We waited for the byte transmit and receive the ACK from slave and then we send the data byte placing it in the IICD register .Wait for the byte is transmitted and receive the ACK from the slave and ended the communication by sending the stop signal (MS = 0).
void IIC_write_byte(char data,char dir){
while(IICS_BUSY!=0);
IICC|=0x30;
set_address(dir,RW_WRITE);
while(IICS_TCF!=1);
while(IICS_RXAK!=0);
IICD=data;
while(IICS_TCF!=1);
while(IICS_RXAK!=0);
IICC_MST=0;
}
The IIC_read_byte function (char dir) has changes . First we set the master as transmitter (TX = 1) and send a start signal (MS = 1) then send a byte containing the slave address shifted one position to the left,the reading bit being this the LSB . We waited for the byte transmit and receive the ACK from the slave and we set master as a receiver (TX = 0) and the ACK sending by the master is canceled( TXAK = 1). We wait until the slave transmit one byte of data and we copy the contents of IICD register in an auxiliary variable ( char_aux ) . We send a stop signal to terminate the communication. Finally we return the value of the auxiliary variable.
char IIC_read_byte(char dir){
char aux_data;
while(IICS_BUSY!=0);
IICC|=0x30; // MST=1 TX=1 TXACK=0
set_address(dir,RW_READ);
while(IICS_TCF!=1);
while(IICS_RXAK!=0);
IICC_TX=0;
IICC_TXAK=1;
while(IICS_TCF!=1);
aux_data=IICD;
while(IICS_TCF!=1);
IICC_MST=0;
return aux_data;
}
The module initialization function is as follows
void IIC_init() {
IICF=0x0B; // SCL = 100kps
IICC_IICEN=1; // Enable IIC
IICC_IICIE=1; // Enable interrupts
IICC_MST=0; // Slave mode. STOP
IICC_TXAK=0; // Enable ACK bit.
}
thanks for reading.
regards