Page 1 of 1

LK 202-25 Poll keypad with I2C doesn't work???

Posted: Tue Dec 02, 2008 4:48 am
by jbsystems
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
}
***********************************************************

Posted: Thu Mar 12, 2009 10:24 am
by chrisaaaaa
Did you get anywhere or get any reply, I am in the same situation.

Posted: Thu Mar 12, 2009 3:02 pm
by Clark
Hi Chrisaaaaa,

If you are having trouble reading from your display in I2C mode, I would suggest making sure events are no longer being reported in RS232 mode and that auto transmission of those events is off. Check out our I2C FAQ section for more info.

If you have any further questions during your development, please don't hesitate to post.

Thanks,
~Troy

Posted: Thu Mar 12, 2009 4:52 pm
by chrisaaaaa
The FAQ mentions a command to route codes to I2C, 254/160/0, this is not mentioned in the manual I recently downloaded.

Does this apply, is it possible that I ask on I2C for the code and it gets served up on a different interface?

Chris

Posted: Fri Mar 13, 2009 9:47 am
by Clark
Hi Chris,

The transmission in RS232 mode off, 254/160/0, does indeed apply in your case. You'll want to make sure it is off so your data can be read in I2C rather than going to the RS232 bus. You'll also want to make sure the display is not auto transmitting the values as you'll need them to stay in the buffer so you can poll them out.

If you could, please let me know which manual you had a look at; if need be I'd like to update it.

Thanks,
~Troy

Posted: Fri Mar 13, 2009 10:08 am
by chrisaaaaa
Thanks that worked, I was using the LK402-25 manual rev 2.0 which does not mention this.

I looked in the manual for one of the others display types and found the information there.

Chris

Posted: Fri Mar 13, 2009 3:25 pm
by Clark
Hi Chris,

No worries, good to hear you've got the I2C read functionality working on your LK402-25. We've recently added in much of the I2C App Note info to our manuals and the change is still rolling through the line. The LK402-25 has not been updated but it is scheduled for the update shortly.

If you have any further questions or concerns as you continue to develop your application, please just put up another post.

Thanks,
~Troy