View previous topic :: View next topic |
Author |
Message |
SQR-1
Joined: 28 Mar 2019 Posts: 10
|
LCD I2C address |
Posted: Mon Apr 08, 2019 2:32 pm |
|
|
Good morning, today my problem revolves around i2c communication; this is my problem:
I have a pic18f67k40 connected to a lcd i2c screen that works well but when buying another screen (apparently the same) I discovered that the address is different. Since I do not want to change the code depending on the manufacturer, I am thinking of performing a function that scans the address of the i2c screen to automatically incorporate it. The problem is that if I indicate the address inside the main function it does not work ... what can I do? |
|
![](templates/subSilver/images/spacer.gif) |
MarkchchPIC
Joined: 14 Jan 2015 Posts: 18 Location: Christchurch New Zealand
|
I2C Address |
Posted: Mon Apr 08, 2019 2:41 pm |
|
|
Hi there we will need a lot more info to be able to assist you.
There is a wonderful piece of code from PCM in the library that can detect I2c devices and give their addresses.
This may be a way to sort your problem. |
|
![](templates/subSilver/images/spacer.gif) |
SQR-1
Joined: 28 Mar 2019 Posts: 10
|
|
Posted: Mon Apr 08, 2019 2:51 pm |
|
|
Thank you very much for the quick reply. I have already tried several functions that detect the i2c address and show it by serial port and they work ... but what I need is that it is automatic once it is detected, the address is assigned to the screen. If I assign the address at the beginning of the code everything works but I do not know how to assign it once the program is started. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 08, 2019 3:27 pm |
|
|
What driver are you using for your i2c lcd ? It is this one in the CCS code library:
"Flexible I2C LCD driver (PCF8574T) by Hugo Silva" -
http://www.ccsinfo.com/forum/viewtopic.php?t=54063
Notice that he sets the lcd slave address here:
Code: | #define LCD_ADDR 0x4E //I2C slave address for LCD module |
You need to comment out the line above.
Then add this line:
Code: | int8 LCD_ADDR = 0x4E; // Default lcd i2c addr
|
Then you need to modify the i2c bus scanner code so you take the address
that is found and put it into the 'LCD_ADDR' variable. Normally we don't
use all caps for variables, but it would make it easier if left it that way.
Then you only need to add the int8 LCD_ADDR line shown above and
comment the #define. You don't have to do anymore edits.
If you have more than one i2c device attached to that bus, I suggest that
you use a separate bus for the lcd, with only the lcd on it. Then running
the i2c scanner program on that bus will only find the lcd. |
|
![](templates/subSilver/images/spacer.gif) |
empty
Joined: 13 Jan 2018 Posts: 15
|
|
Posted: Tue Apr 09, 2019 2:05 am |
|
|
You should give us some details so we can help you!
If your LCD is connected to PCF8574/PCF8574A then the address will depend
on the connection of A2, A1, A0 pins (read device datasheet for more information).
PCF8574 address = 0 1 0 0 A2 A1 A0 0
PCF8574A address = 0 1 1 1 A2 A1 A0 0 |
|
![](templates/subSilver/images/spacer.gif) |
|