LK204 and an MC9S102

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

Post Reply
Ryan_nmt
LCD?
Posts: 2
Joined: Sun Aug 29, 2010 3:24 pm

LK204 and an MC9S102

Post by Ryan_nmt » Sun Aug 29, 2010 3:54 pm

Hi all,

I am using an LK204 with a 4x4 keypad interfaced with a freescale MC9S12. For ease of use I am using the IIC bus to communicate between the controller and the screen. I have observed some strange behavior between the screen and the controller. When one repeatedly writes to the display and then reads from the display to see the keybuffer the master looses control of the bus even after a stop condition is set. When power to the display is pulled this condition goes away and SDA returns to +5V.

Has anyone else observed strange behavior like this?

I have also noticed that it sometimes takes 2-3 key presses to actually fill the buffer so it recognizes a key was pressed. Is this a debounce issue?

I would be happy to attach code / L.A. outputs if that would help.

Thanks guys!

Clark
Matrix Orbital
Matrix Orbital
Posts: 881
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Post by Clark » Mon Aug 30, 2010 12:25 pm

Hi Ryan,

We'll start with code first, but it's good to know an analyzer output may be available; it is especially handy for I2C. I'll go over the basics here, if you have a step done, check it off and move to the next one.

When setting up I2C, you'll want to make sure auto transmit is turned off and the protocol is I2C (rather than serial). Please consult your manual to confirm the commands but I believe 254 79 will keep information in the buffer, and 254 160 0, will stop data from being sent out the serial port by default.

In your hardware, make sure the SCL and SDA lines are pulled up to +5v using a resistance between 1 and 10 kilo ohms.

You have successfully communicated to your display, which would be the next step. Finally we come to reading, for which I would recommend testing with a command such as read module or version (default read address 0x51). This is not susceptible to bouncing or any other keypad issues that may hamper reading ability. If reading is working, move on to pressing a key and simply reading.

If everything above checks out, let us know if you are able to send any info to the display after the it hangs. If you continue to have trouble with the key presses, investigate a change in the debounce setting.

Thanks,
~Troy
Troy Clark
Design & Development
Matrix Orbital

Ryan_nmt
LCD?
Posts: 2
Joined: Sun Aug 29, 2010 3:24 pm

Post by Ryan_nmt » Tue Aug 31, 2010 4:05 pm

Clark,

Right after initializing the IIC bus I run the following commands:

void setup_screen(void)
{
iic_start(WDisplay);
iic_transmit(0xFE); // Turn autoscroll off
iic_transmit(0x52); // Turn autoscroll off
iic_transmit(0xFE); // Turn autotransmit key off
iic_transmit(0x4F); // Turn autotransmit key off
iic_transmit(0xFE); // Turn poll key press on
iic_transmit(0x26); // Turn poll key press on

//The following fixes the keypad map.
iic_transmit(0xFE); // Re-mapping keypad
iic_transmit(0xD5); //Re-mapping keypad
iic_transmit(0x00); //R1C1
iic_transmit(0x00); //R1C2
iic_transmit(0x00); //R1C3
iic_transmit(0x00); //R1C4
iic_transmit(0x00); //R1C5
iic_transmit(0x30); //R2C1 0
iic_transmit(0x2D); //R2C2 -
iic_transmit(0x44); //R2C3 B
iic_transmit(0x2B); //R2C4 +
iic_transmit(0x00); //R2C5
iic_transmit(0x38); //R3C1 8
iic_transmit(0x39); //R3C2 9
iic_transmit(0x43); //R3C3 C
iic_transmit(0x37); //R3C4 7
iic_transmit(0x00); //R3C5
iic_transmit(0x35); //R4C1 5
iic_transmit(0x36); //R4C2 6
iic_transmit(0x42); //R4C3 B
iic_transmit(0x34); //R4C4 4
iic_transmit(0x00); //R4C5
iic_transmit(0x32); //R5C1 2
iic_transmit(0x33); //R5C2 3
iic_transmit(0x41); //R5C3 A
iic_transmit(0x31); //R5C4 1
iic_transmit(0x00); //R5C5

//Codes for keys not depressed
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_transmit(0x00);
iic_stop();
}

The bus at startup is at 5.24V for SDA and SCL. I am using the internal pull up resistors on the MC9S12. When external pull up resistors are added (1.5Kohm) the bus becomes completely un-responsive.


When I do a read from the display to see the keys the following code is executed. Perhaps there is a more efficient way of doing this?

void key_press()
{
iic_start(RDisplay);
iic_swrcv(); // Switch to recieve
keydata[1]= slavedata - 0x80;
iic_recieve_m1();
keydata[0]= slavedata - 0x80;
iic_recieve_last(); // RX
keydata[2]= slavedata - 0x80;
iic_stop();
clear_keys();
return;
}

The first read always returns garbage ranging from -128 to 47 according to the MCU as I step through the program. The second read is always the actual value... hence 2 button presses for a single valid output.

Clark
Matrix Orbital
Matrix Orbital
Posts: 881
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Post by Clark » Thu Sep 02, 2010 10:45 am

Hi Ryan,

I have asked our resident I2C expert to take a look at your code, she has been busy working on some code for our displays and is away today, but I'm sure she'll respond as soon as she can.

While we're waiting, I can let you know that Poll Key Press will not be available in I2C mode, so you won't need that in your initialization. If you will be reading the module or firmware number at any time, you may want to add the 0xFE 0xA0 0x00 command to ensure these responses make it to the I2C buffer.

Also, it looks like you subtract 0x80 (128) from all information received. Please note the display will only add 128 to a press if there is another piece of information in the buffer to be read. This may be why you require 2 presses to get one intelligent response.

Finally, when reading, you'll simply preform a read from one address higher than your write, which looks good in your code. Again, I'd recommend starting with the module or firmware as this will let you eliminate keypad mechanics and focus on the integrity of the I2C line and your reading algorithm.

If you note any further developments with the display today, please post, and I'm sure Raquel will have a look tomorrow if need be.

Thanks,
~Troy
Troy Clark
Design & Development
Matrix Orbital

Raquel
Matrix Orbital
Matrix Orbital
Posts: 692
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel » Fri Sep 03, 2010 9:10 am

Hi Ryan,

Troy has good suggestions in his last post. Pleas give them a try.

Also, if you want to keep things simple to start, try reading the display without pressing any keys, you should receive 0x00 as a reply. This then is in conflict with the other keys you set as 0x00. Unless those combination (eg R1C1) will not be mapped out to actual keys, then it should be fine.
Raquel Malinis
Design and Development
Matrix Orbital

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 20 guests