I'm working on a PK202-25 PCB rev3.0 in I2C Mode at 350Kbps and I have (another) some problem.
Please take a look a this code :
LcdClearScreen();
pause(HUNDRED_MS);
LcdLocate(5,1); // set cursor to col 5 row 1
pause(HUNDRED_MS);
LcdPrintStr("Hello");
It works correctly .
If I remove the pauses , it doesn't work (in fact it prints 'Hello' at the beginning of the screen) .
It looks like the clearscreen doesn't have time to be executed when it already executes the locate function. An it's the same for the last PrintStr ...
I am not as familiar with I2C communication as Raquel. However I am aware that I2C involves a form of flow control with NAK and AK that you may want to pay attention to.
I cannot only send commands to the lcd, I have to keep attention to the NACK bit ?
So , the lcds'buffer is only a 'char' buffer , not a command buffer ?
You need to pay particular attention to the acknowledge bit (specially the NAK). This indicates if the buffer is full and therefore you will need to hold off sending data. This part of the I2C transaction is there for handshaking and is necessary to make sure that data are being received properly.
The module's buffer is a plain data buffer, not a full command buffer which can entail anything from 2 to 162 bytes. The module's buffer is 128-byte big.
Raquel Malinis
Design and Development
Matrix Orbital
Raquel wrote:You need to pay particular attention to the acknowledge bit (specially the NAK). This indicates if the buffer is full and therefore you will need to hold off sending data."
That's what I mean , the nak is only there to prevent a buffer overflow.
But this isn't the case with the exemple . With the source code I send what ? 15 ?20 chars ? Not enough chars for a buffer overflow, especially with a empty buffer when the code is started.
What I mean is that I suspect the commands are streamed to the screen as soon as they're decoded without keeping attention to the right timing needed by the lcd.
Really , I cannot see another explanation
Hi, I was going to post right away that you must give the LCD time to initialize, but I removed it because I thought it was a I2C related issue. The solution that to this problem that you are having may just be that you will will need to give the display an extra second or two to initialize on startup before beginning the transmission.
I tried a 3s pause before the first command and it isn't working
Moreover, I guess the screen is initalized as soon the bootscreen is displayed (quasi immediatly in fact)...
And after some test , it seems the lcd need differents pauses according to the commands. But it's the work of the atmega8535, not mine
Hi,
I am having a similar problem with the LK204-25. I am using a Freescale HC08AP64 to communicate via the I2C.
Everything is happy, including the ACK.
The first test I am running is to send the clear screen command and to turn off the backlight.
I have a few questions:
- Is there a spec on how long the delay should be per command? specially the backlight off command?
- I am assuming the arguments for some of the functions (minutes, gpo #) are all hex equivalent. Is it correct?
I am monitoring all communication with a scope.
The problem I am having is the LCD locks up when I send the backlight off command. It turns the backlight off, and pulls down the SDA and SCL lines.
Here is the sample code I have:
void LcdSendData(unsigned int data){
MMDTR=data;
while (MMSR_MMTXBE==0){}; wait for buffer in HC08 to be empty
while (MMSR_MMTXIF==0){}; wait for data transfer to be done
MMSR_MMTXIF=0; clears the data transfer complete flag
}
// LcdInit
// Sends initialization data to the LCD.
void LcdInitTX(void) {
LcdClrDisp();
LcdBackLight(0,0);
}
this is where the LCD hangs up. I do not get an ACK bit, and the SDA and SCL lines are pulled low. Looking at the scope, the last data sent is 0x46
//Send byte to turn off backlight
void LcdBackLight(unsigned int OnOff, unsigned int minutes) {
StartTXMaster();
LcdSendData(0xFE);
//LcdSendData(BackLightOff);
switch (OnOff){
case 0x00:
LcdSendData(BackLightOff);
break;
case 0x01:
LcdSendData(BackLightOn);
LcdSendData(minutes);
break;
default:
LcdSendData(BackLightOff);
break;
}
StopTXMaster();
}
Is it something I am missing? Is it due to timing also?
I am trying to read up more about the HC08 to make sure it is not related to any I2C code I have written.
Hi again,
Thanks for the reply.
Regarding the arguments for some of the functions, like the GPO#, minutes, etc...are they purely HEX or are they the hex equivalent of the ASCII numbers?
As for the LCD itself, this is where I am now,
I was able to get the I2C working with the LCD, I can clear, send data, and shut off the back light, BUT, the last command/data I send, hangs up the bus.
Here are the details of the code with some comments:
// Function Definitions
This one works. It sends the start and slave address, and waits for the ACK bit.
void StartTXMaster(void){
MMSR_MMTXBE=0;
MMCR2_MMRW=0;
MMCR2_MMAST=1;
}
I believe thisis where my problem is. Not sure if this is the correct sequence of register writes.
void StopTXMaster(void){
MMCR2_MMNAKIF=0;
MMCR2_MMAST=0;
}
This also works. I can monitor all data sent on the bus.
void LcdSendData(unsigned int data){
MMDTR=data;
while (MMSR_MMTXBE==0){};
while (MMSR_MMTXIF==0){};
MMSR_MMTXIF=0;
}
// LcdInit
// Sends initialization data to the LCD. I am using this to debug my code. It all works, but the problem is I do not get the ASCII 5 on the LCD. So the following code executes, It clears the display, it shuts off the back light, it sends 1 2 3 and 4, but it does not send the 5. It hangs up on the last write and the Stop signal.
I can't find clear information in the HC08AP64 to explain exactly how to proceed with the last data write on the I2C, or how to generate a STOP bit. The STOP bit is defined as the Low to High transition of the SDA while SCL is high. At the end of this code, the SCL is high, but the SDA is tied low.
I am trying to find out from Freescale the details of this.
It is weird because the Stop signal seems to work in the void LcdClrDisp routine described below. It is only the last Data packet I send which causes the problem.
My question is, for the LCD, is there a terminating data byte which should be sent? or does it follow the I2C STOP Signal from the master?
I did a quick search for HC08AP64 and could not find a datasheet. Can you post a link to it, or maybe email me the datasheet at rmalinis@matrixorbital.ca
Raquel Malinis
Design and Development
Matrix Orbital