LK 202-25 Poll keypad with I2C doesn't work???
Posted: Tue Dec 02, 2008 4:48 am
Hello,
I have bought a few BLK202A-BK-WB displays with a PC bay.
On the PCB there is a sticker that says: 08M11-2008. The PCB revision is 3.0.
I have tested the display and keypad with uProject (RS232) witch works fine. I can send text to the display and I can read the buttons from the keypad.
In uProject I have set the I2C adress to 0x50. Next, i soldered the two I2C jumpers and removed the three RS232 jumpers.
Via I2C i can send text to the display. The only thing I could not do is, polling the keypad to see if there are some keys pressed.
When I press some keys on the keypad and when I poll the keypad the only thing I get is 0x00. This 0x00 means that there are no keys pressed, but i have still pressed them for serveral times. I send the 1byte variable 'data' to the UART via PRINTF but the only thing I can see is 0x00???
I don't know what i'm doing wrong. Are there maybe some firmware changes?
I spend a lot of hours to solve this problem so I hope that you can help me.
With this code I try to poll the keypad:
Send_start();
Send_adr(0x51); //0x50 is the write adress so 0x51 is the read adress isn't it?
Get_byte(&data ,0);
Send_stop();
Greetings, Bert E.
p.s. For your convience I have put 'all' the subroutines on an attachment.
This are the subroutines:
***********************************************************
char Send_start(void)
{
TWCR = ((1<<TWINT)+(1<<TWSTA)+(1<<TWEN));//Send START
Wait_TWI_int(); //Wait for TWI interrupt flag set
if((TWSR != START)&&(TWSR != REP_START))//If status other than START
return TWSR; //transmitted(0x08) or Repeated
return SUCCESS; //START transmitted(0x10)
//-> error and return TWSR.
//If success return SUCCESS
}
***********************************************************
***********************************************************
char Send_adr(char adr)
{
Wait_TWI_int(); //Wait for TWI interrupt flag set
TWDR = adr;
TWCR = ((1<<TWINT)+(1<<TWEN)); //Clear int flag to send byte
Wait_TWI_int(); //Wait for TWI interrupt flag set
if((TWSR != MTX_ADR_ACK)&&(TWSR != MRX_ADR_ACK))//If NACK received return
//TWSR
return TWSR;
return SUCCESS; //Else return SUCCESS
}
***********************************************************
***********************************************************
char Get_byte(uint8_t *rx_ptr,char last_byte)
{
Wait_TWI_int(); //Wait for TWI interrupt flag set
/*When receiving the last byte from the slave it will be sent a NACK to
make the slave stop transmitting, all bits before the last will get
a ACK*/
if(last_byte) //Not the last byte
//Clear int flag and enable acknowledge to receive data.
TWCR = ((1<<TWINT)+(1<<TWEA)+(1<<TWEN));
else //Last byte
/*Clear int flag to and do not enable acknowledge to tell the slave
to stop transmitting*/
TWCR = ((1<<TWINT)+(1<<TWEN));
Wait_TWI_int(); //Wait for TWI interrupt flag set
*rx_ptr = TWDR; //Save received byte
/*If ACK has been transmitted or this was the last byte and NACK has been
sent -> return SUCCESS, else return TWSR*/
if(((TWSR == MRX_DATA_NACK)&&(last_byte == 0))||(TWSR == MRX_DATA_ACK))
return SUCCESS;
return TWSR;
}
***********************************************************
***********************************************************
void Send_stop(void)
{
TWCR = ((1<<TWEN)+(1<<TWINT)+(1<<TWSTO));//Send STOP condition
_delay_us (10); //DELAY
}
***********************************************************
I have bought a few BLK202A-BK-WB displays with a PC bay.
On the PCB there is a sticker that says: 08M11-2008. The PCB revision is 3.0.
I have tested the display and keypad with uProject (RS232) witch works fine. I can send text to the display and I can read the buttons from the keypad.
In uProject I have set the I2C adress to 0x50. Next, i soldered the two I2C jumpers and removed the three RS232 jumpers.
Via I2C i can send text to the display. The only thing I could not do is, polling the keypad to see if there are some keys pressed.
When I press some keys on the keypad and when I poll the keypad the only thing I get is 0x00. This 0x00 means that there are no keys pressed, but i have still pressed them for serveral times. I send the 1byte variable 'data' to the UART via PRINTF but the only thing I can see is 0x00???
I don't know what i'm doing wrong. Are there maybe some firmware changes?
I spend a lot of hours to solve this problem so I hope that you can help me.
With this code I try to poll the keypad:
Send_start();
Send_adr(0x51); //0x50 is the write adress so 0x51 is the read adress isn't it?
Get_byte(&data ,0);
Send_stop();
Greetings, Bert E.
p.s. For your convience I have put 'all' the subroutines on an attachment.
This are the subroutines:
***********************************************************
char Send_start(void)
{
TWCR = ((1<<TWINT)+(1<<TWSTA)+(1<<TWEN));//Send START
Wait_TWI_int(); //Wait for TWI interrupt flag set
if((TWSR != START)&&(TWSR != REP_START))//If status other than START
return TWSR; //transmitted(0x08) or Repeated
return SUCCESS; //START transmitted(0x10)
//-> error and return TWSR.
//If success return SUCCESS
}
***********************************************************
***********************************************************
char Send_adr(char adr)
{
Wait_TWI_int(); //Wait for TWI interrupt flag set
TWDR = adr;
TWCR = ((1<<TWINT)+(1<<TWEN)); //Clear int flag to send byte
Wait_TWI_int(); //Wait for TWI interrupt flag set
if((TWSR != MTX_ADR_ACK)&&(TWSR != MRX_ADR_ACK))//If NACK received return
//TWSR
return TWSR;
return SUCCESS; //Else return SUCCESS
}
***********************************************************
***********************************************************
char Get_byte(uint8_t *rx_ptr,char last_byte)
{
Wait_TWI_int(); //Wait for TWI interrupt flag set
/*When receiving the last byte from the slave it will be sent a NACK to
make the slave stop transmitting, all bits before the last will get
a ACK*/
if(last_byte) //Not the last byte
//Clear int flag and enable acknowledge to receive data.
TWCR = ((1<<TWINT)+(1<<TWEA)+(1<<TWEN));
else //Last byte
/*Clear int flag to and do not enable acknowledge to tell the slave
to stop transmitting*/
TWCR = ((1<<TWINT)+(1<<TWEN));
Wait_TWI_int(); //Wait for TWI interrupt flag set
*rx_ptr = TWDR; //Save received byte
/*If ACK has been transmitted or this was the last byte and NACK has been
sent -> return SUCCESS, else return TWSR*/
if(((TWSR == MRX_DATA_NACK)&&(last_byte == 0))||(TWSR == MRX_DATA_ACK))
return SUCCESS;
return TWSR;
}
***********************************************************
***********************************************************
void Send_stop(void)
{
TWCR = ((1<<TWEN)+(1<<TWINT)+(1<<TWSTO));//Send STOP condition
_delay_us (10); //DELAY
}
***********************************************************