I2C LK204-25 EDIT: WinAVR example code

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

Moderators: Henry, Mods

Post Reply
chupa
LCD?
Posts: 4
Joined: Fri Apr 25, 2008 10:22 am

I2C LK204-25 EDIT: WinAVR example code

Post by chupa »

Having problems trying to use an atmega88 to communicate with my Lk204-25.

I have cleared the jumpers off the 232 pads on the back LCD and moved 2 over to the i2c pads. This is a read of the i2c bus. the LCD is unresponsive. It should be ACKing if i read the LCD documentation correctly, which it is not. As you can see the SCL is running slow, ~500Hz, as im just trying to get some response from the LCD before I put it up to 100KHz. Any help anyone could provide to this would be helpful. Thanks. Is there any code out there someone else has developed to run on an AVR already?[/code]
Attachments
mega88_lk204.PNG
mega88_lk204.PNG (74.49 KiB) Viewed 9959 times
Last edited by chupa on Sat Apr 26, 2008 4:36 pm, edited 1 time in total.
lol wut?
Raquel
Matrix Orbital
Matrix Orbital
Posts: 834
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hello,

Thanks for your post.

Are you able to successfully write to the display?

From the scope capture, it looks like the slave address is 0x84 (its indicated as 45, but I do not think this is right); did you change the slave address from the default 0x50 to this address?

I wonder if we set aside the read transactions for now, and focus on the write transactions to keep things simple.

Best Regards,
Raquel Malinis
Design and Development
Matrix Orbital
chupa
LCD?
Posts: 4
Joined: Fri Apr 25, 2008 10:22 am

Post by chupa »

I just did a manual reset of the device, so if the default address is in fact 0x45 (or 0X8A when talking about all 8 bits) as the data sheet says, I should be seeing a successful ACK on the line after its addressed, correct? After reseting the LCD I still did not get a successful ACK.

I try sending a 0xFE, 0x52 to clear the display but with no success.

The scope capture above is a write command. S indicates a Start event, the 45 is the 7 bit address, the W indicates that its a Write command (otherwise it would be an R, for read). The N indicates a NACK (this SHOULD be an ACK according to the data sheet for the LCD) and i think the E is an error, then it turns to garbage because of that.

I am kind of at wall here, I cant think of anything else to try.
lol wut?
Raquel
Matrix Orbital
Matrix Orbital
Posts: 834
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hi,

Please have a look at this post.

I am not sure how you will need to program your MCU to produce a 0x50, but the way you have it right now looks like a 0x8A, not a 0x50.

You will hopefully see what I mean when you read through that post.

Thanks,
Raquel Malinis
Design and Development
Matrix Orbital
chupa
LCD?
Posts: 4
Joined: Fri Apr 25, 2008 10:22 am

Post by chupa »

ahh! i was reading the example of how you guys include the W/R bit in the slave adress, and i was using the example address which is 8A. gerrr. my fault.

how does this look? It looks like I have successful communication now. FE, 52 SHOULD clear the display correct?

I also realize theres no stop after the transmission, im working on fixing that.

EDIT: FE, 58! not FE,52 to clear the display! and yes it works now. yay.
Attachments
avr_matrixorbitali2c.PNG
avr_matrixorbitali2c.PNG (76.93 KiB) Viewed 9933 times
lol wut?
Raquel
Matrix Orbital
Matrix Orbital
Posts: 834
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Glad to hear that things are working now.
Raquel Malinis
Design and Development
Matrix Orbital
chupa
LCD?
Posts: 4
Joined: Fri Apr 25, 2008 10:22 am

Post by chupa »

for those others who are using TWI on an AVR to interface with a MO LCD:
i just quickly threw this together, and tested it successfully. You may need to change TWBR and TWSR, as these two registers set the data rate of the TWI (i2c) interface. Spelling in comments not guaranteed :-)

This example was basically pulled straight from the TWI section of the data sheets for my part, which was an ATmega88. Thanks for the help Raquel!

Code: Select all

#define F_CPU 20000000UL  //20MHz Clock

#include <avr/io.h>
#include <util/twi.h>
#include <avr/pgmspace.h>

#define LCD_ADDY 0x50	//Write addy for LCD

const char MSG_1[] PROGMEM = "PROGMEM test\0";  //stores the string in ROM

void send_twi(char xyz){
	TWDR = xyz;  // LOAD SLA_W into TWDR reg,
	TWCR = (1<<TWINT) | (1<<TWEN); // CLEAR TWINT bit in TWCR to start transmission
	while (!(TWCR & (1<<TWINT))){ //wait for TWINT flag set. this indicated that SLA+W was transmitted and ACK was received
		; //wait
		}
	if ((TWSR & 0xF8) != TW_MT_DATA_ACK){ //check value of TWI status reg, mask presacaer buts, if diffrent from MT_DATA_ACK error
		; //error
		}
}

void string_twi_P(const char *ptr){		//send string to LCD
	while (pgm_read_byte(ptr) != 0x00)
		send_twi(pgm_read_byte(ptr++));
}

void LCD_int(void){
	TWBR=10;
	TWSR=((0<<TWPS0)|(0<<TWPS1));
	TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); //send start cond
	while (!(TWCR & (1<<TWINT))){ //wait for TWINT flag set, which indicates that START was transmited
		; //wait
		}
	if ((TWSR & 0xF8) != TW_START){ // check value of TWI status, mask prescaler bits,  if diffrent from START error
		; //error
		}
	send_twi(LCD_ADDY);
	send_twi(0xFE);	//0xFE, 0x58 clears LCD
	send_twi(0x58);
}

void LCD_stop(void){
	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO); //trans stop cond
}
	

int main (void){
	LCD_int();
	string_twi_P(MSG_1);
	send_twi(0xFE);		//select coloum/row
	send_twi(0x47);
	send_twi(0x01);
	send_twi(0x02);
	string_twi_P(PSTR("Hi mom!"));
	send_twi(0xFE);
	send_twi(0x47);
	send_twi(0x01);
	send_twi(0x03);
	string_twi_P(PSTR("It works!"));
	send_twi(0xFE);
	send_twi(0x47);
	send_twi(0x01);
	send_twi(0x04);
	string_twi_P(PSTR("Last row"));
	LCD_stop();
}
lol wut?
Post Reply