Detecting I2C LCD address automatically

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Based on part number of PCF8574 , there are two default addresses possible for PCF8574 based serial module such as 0x7E or 0x4E. So I thought of detecting the address automatically. But the code I wrote below is not working. In both type of LCD serial modules, i2CTest() returns 0. However addresses 0x7E and 0x4E are correct and both the modules work if I set PCF8574_ADDR to respective address. I used Peter Fleury' I2C library and added small wrapper function i2CTest() to check the device address. I did not add complete code here and if needed I can add after some changes.

uint8_t PCF8574_ADDR = 0x7E;

void initializeLCD(void)
{

    	//After reset, data sheet suggests some delay.
	_delay_mS(2);

	/*
	In case of PCF8574, there could be two possible addresses by default.
	We are considering 0x7E as default address.
	In case we get NACK, we will use other address.
	*/

    if(!i2CTest(PCF8574_ADDR))
    {
        PCF8574_ADDR=0x4E;
    }

	i2c_start(PCF8574_ADDR + I2C_WRITE);

	// rest of the initialization code goes here.

}

uint8_t i2CTest(uint8_t address)
{
    uint8_t status=0;
    if(!i2c_start(address))
    {
        i2c_readNak();
        status=1;
    }
    i2c_stop();
    return(status);
}

 

* Changed "Serial" in the thread title to "I2C". Moderator *

 

Last Edited: Wed. Mar 14, 2018 - 12:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rather then doing a readNAK(), I would just do a start() stop() and save / test the status of the start, expecting the correct address to ACK.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In this thread:

 

https://www.avrfreaks.net/forum/...

 

David mentions a utility that might do what you are looking to do.  Will also give you the pin connections between the PCF and the LCD.

 

Another Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First: Can you change the title?

"Serial" is not a good alias for " I2C ".

 

Second:

In a pc there are a bunch of internal I2C busses ( & busses forked from I2C).

In linux there is a package called "i2c-tools" to send and read data from I2C busses from the command line.

There is also a function which tries to sniff all I2C addresses and generates a list of the hardware it thinks it found on the bus.

You might want to look into that code.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com