AnsweredAssumed Answered

connect MC9S08QG8  to a lcd with an 8 bit I/O expander I2C bus

Question asked by Maria Mor on Apr 29, 2014
Latest reply on Jul 11, 2014 by Maria Mor

hello.
I want to communicate the MC9S08QG8  microcontrolle to a lcd with an 8 bit I/O expander I2C bus(PCF8574A).


I have doubts about the i2c protocol.
assuming that the direction of the 8 bit I/O expander I2C bus(PCF8574A) is 0x38 ( 00111000 )
If I want to send data from the microcontroller ( master) to the lcd (slave ) the steps would be:
1. The start signal is sent
2. Slave address is sent along with the RW bit ( RW = read or write bit .) which will be the LSB bit of the byte to be sent , This bit will be 0 for be a write process. So i place it in the i2c module data register (IICD ) 0x70 ( 01110000 )
3. Expect the acknowledgment signal sent by the slave
4. Sent a data byte
5. Expect the acknowledgment signal sent by the slave
6. Sent a data byte
.....
9. Expect the acknowledgment signal sent by the slave
10. The stop signal is sent


If I want the microcontroller ( master) read data from  lcd (slave ) the steps would be the following :

1. The start signal is sent
2. Slave address is sent along with the RW bit ( RW = read or write bit .) which will be the LSB bit of the byte to be sent , This bit will be 1 for be a read  process. So i place it in the i2c module data register(  IICD) 0x71 ( 01110001 )
3. Ex pect the acknowledgment signal sent by the slave
4 . Read the data byte sent by the slave. This byte is in IICD, so we need to read this register.
5. The master sends an acknowledge signal
6. Read the data byte sent by the slave. This byte is in IICD, so we need to read this register.

7. The master sends an acknowledge signal
....
10. The stop signal is sent


is this right?

 

 

This is the code i've written. it's right?

 

#define PCF8574A_ADDR_FIXED 0x40

#define  RW_READ 0x01

#define  RW_WRITE 0x00

 

void IIC_write_byte(char data,char dir){

 

IICC|=0x30; // MST=1 TX=1 

set_address(dir,RW_WRITE); 

while(IICS_IICIF!=1);

while(IICS_RXAK!=0);     

IICD=data;              

while(IICS_IICIF!=1);   

IICC_MST=0;            

 

}

 

char IIC_read_byte(char dir){

 

char aux_data;

IICC|=0x28; // MST=1 TX=0 TXAK=1

set_address(dir,RW_READ); 

while(IICS_IICIF!=1);    

IICD=data;              

while(IICS_IICIF!=1);  

IICC_MST=0;

}

 

 

void set_address(char dir,char RW){

char aux_dir= dir<<1;        

aux_dir&=0x0F;               

IICD=aux_dir|PCF8574A_ADDR_FIXED|RW;

}


 

MC9S08QG8 datasheet: http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08QG8.pdf

 

PCF8574A datasheet :http://www.nxp.com/documents/data_sheet/PCF8574_PCF8574A.pdf

 

 

This would be the connection between the 8 bit I/O expander I2C bus and the lcd. In the picture refers to a Arduino instead of a MC9S08QG8 microcontroller, but the scheme is the same.

 

Schematic_diagram.jpg

Outcomes