|
|
View previous topic :: View next topic |
Author |
Message |
coellen_d
Joined: 10 Apr 2007 Posts: 5 Location: Germany/Bonn
|
problems with IIC on PIC18F252 |
Posted: Tue Apr 10, 2007 6:40 am |
|
|
Hello everyone,
I am a new CCS-user and I have a problem with the IIC-functions.
Now I hope to get help in this Forum.
I built a system of 2 PICs which comunicate over IIC.
The System is working well, but now im standing in front of an error I don`t know to solve.
In my system a PIC18F252 is sending Data over IIC to a PIC16F88, wich shows the data on a LCD-Module.
Now i need to send a string over IIC, so I created a function to send each character with write_i2c(string[i]); here is the Code of this Function:
Code: |
void LCD_sendstring(byte address, char *LCD_string) {
byte i = 0, j =0;
j = Strlen(LCD_string) -1 ;
i2c_start();
i2c_write(address & 0xfe); // address is the PIC16F88-address
i2c_write('C'); // 'C' is the Keyword for PIC16F88
while (i<= j) {
i2C_write(LCD_string[i]);
putc(LCD_string[i]; // this is to control the output on PC
i++;
}
i2C_write(13); // transmit finished
i2c_stop();
}
|
On the PC I get the right characters, but on IIC I dont.
To catch the Problem (I was not shure if I used the pointers on the right way) I changed the Funktion to the following:
Code: |
void LCD_sendstring(byte address, char *LCD_string) {
byte i = 0, j =0;
//j = Strlen(LCD_string) -1 ; // I ignore the Pointer
i2c_start();
i2c_write(address & 0xfe);
i2c_write('C');
while (i<= 15) { // fix output of 15 chars
i2C_write(LCD_text[i]); // LCD_text is a global string of 20chars
putc(LCD_text[i]); // this is to control the output on PC
i++;
}
i2C_write(13);
i2c_stop();
}
|
It happend the same, the output over RS232 was correct, but not on IIC.
After hours of searching on the PIC16F88-Part and reading references about C and Pointers I did the following:
Code: |
void LCD_sendstring(byte address, char *LCD_string) {
byte i = 0, j =0;
char characters[20];
strcpy(characters,"hello_world"); // load the local string
//j = Strlen(LCD_string) -1 ;
i2c_start();
i2c_write(address & 0xfe);
i2c_write('C');
while (i<= 15) {
i2C_write(characters[i]); // and use the local string
putc(characters[i]); // this is to control the output on PC
i++;
}
i2C_write(13);
i2c_stop();
}
|
Now both, the IIC-transmission and the RS232-transmission worked well!
But this Code was not useable for my System, So I tried the following to understand whats going on :
Code: |
void LCD_sendstring(byte address, char *LCD_string) {
byte i = 0, j =0;
char characters[20];
strcpy(characters,LCD_text); // here I use the global string again
//j = Strlen(LCD_string) -1 ;
i2c_start();
i2c_write(address & 0xfe);
i2c_write('C');
while (i<= 15) {
i2C_write(characters[i]); // LCD_text is a global string of 20chars
putc(characters[i]); // this is to control the output on PC
i++;
}
i2C_write(13);
i2c_stop();
}
|
And there the Problem was again! The Output on IIC was not correct.
in all cases i Loaded the global String with strcpy(LCD_text,"test1234");
before calling LCD_sendstring.
Can anyone help me with this Problem?
I don`t know what is wrong on my code.
Or is it another Problem?
Thanks for all your answers
(and excuse my terrible english...)
Dirk |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 10, 2007 12:13 pm |
|
|
You have posted block after block of largely identical code, that is
poorly formatted with wrap-around comments.
Can you re-post the code that works, and the code that fails,
and use the preview button to check that no line-wrapping occurs
on the comments (or just delete the comments). Also, show very
clearly what line you changed, that caused the problem. |
|
|
coellen_d
Joined: 10 Apr 2007 Posts: 5 Location: Germany/Bonn
|
|
Posted: Tue Apr 10, 2007 4:00 pm |
|
|
Hi PCM programmer
at firs thanks for your answer.
You are right, the 4 blocks lock very identical, I did this to show exactly what i changed on the code while searching the error.
take a look at the code and you will see that there are no wrap-arounds.
If you like the short way here it is:
If I try to get data out of an global string to send it on IIC everything seems all right when stepping trough the code with the ICD or sending the same data over RS232, but the Data which comes out of the PIC over IIC is not correct!
If I change the source of data to a constant the IIC-output is ok.
You can see this in the last 2 blocks of code.
I only changed the source for the Data by
a: copy "hello_world" in string characters -> everything ok
b: copy from string LCD_text to string characters -> wrong output on IIC
BUT correct output on RS232!?
I hope you understand my Problem where to search for this error?
Many Thanks!
Dirk |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|