This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Repeat start sequence in I2C interface - PCF8574.

Other Parts Discussed in Thread: PCF8574A, PCF8574, HALCOGEN

Hi

I am interfacing PCF8574A(I/O EXPANDER)  to HDK(I2C). I have been stuck with repeat start sequence. Its stuck in while loop when i use i2cSendByte function.Attaching the sample code for reference.

I want to write  slave_address+write_addr+data_to_port. 

Can you please guide me as am new to i2c, . or any settings to be made in halcogen?2705.I2C_PCF8574.zip4861.PCF8574 _ph.pdf

Thanks and Regards,

Shruthi

  • I am forwarding your question to someone with more I2C experience.
  • Hi Shruthi,

    Here is a link to a thread, which could be helpful:

    https://e2e.ti.com/support/microcontrollers/hercules/f/312/t/520353

    In the above thread, there is a link to a code that have repeated mode reading:

    /cfs-file/__key/communityserver-discussions-components-files/312/06636.sys_5F00_main.c

    Regards

    Fouad

  • Hi,

    Thanks for the link. I went through the link but was unable to read the value from register.

    here is the code snippet.

    uint8 i2cReadByte(uint8 memAddress)
    {
    control_word.mem_address=memAddress;
    uint8 data;
    uint8 byteData;

    delay2(1000);
    //i2cREG1->MDR=(0xEA0); // disable repeat mode
    i2cREG1->MDR |= I2C_REPEATMODE;

    /*....................Set as read function andSet memory address to read...................*/

    i2cSetSlaveAdd(i2cREG1, SC16lS740_ADDR);
    i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
    i2cSetCount(i2cREG1,0x01);
    i2cSetMode(i2cREG1, I2C_MASTER);
    i2cSetStart(i2cREG1);
    delay();
    i2cSendByte(i2cREG1,0x18); //register address of SC16lS740
    //i2cSendByte(i2cREG1,0x91);
    delay();
    //i2cSetStop(i2cREG1);
    //while(i2cIsBusBusy(i2cREG1) == true);
    //delay();
    //while(i2cIsStopDetected(i2cREG1) == 0);
    //i2cClearSCD(i2cREG1);


    /*....................Receive Data....................................*/

    i2cSetSlaveAdd(i2cREG1, SC16lS740_ADDR);
    i2cSetDirection(i2cREG1, I2C_RECEIVER);
    i2cSetCount(i2cREG1, 1);
    i2cSetMode(i2cREG1, I2C_MASTER);
    i2cSetStart(i2cREG1);
    delay();
    sciSendByte(scilinREG,'S');
    data = i2cReceiveByte(i2cREG1);
    //delay();
    sciSend_hexdata(scilinREG, (uint8)data);

    i2cSetStop(i2cREG1);
    while(i2cIsBusBusy(i2cREG1) == true);
    delay();
    while(i2cIsStopDetected(i2cREG1) == 0);
    i2cClearSCD(i2cREG1);

    /*......................stores data...........................*/

    byteData=data;
    return byteData;

    }

    SLAVE ADDRESS IS SET TO 0x48.
    its looping in the while loop inside i2cRecieveByte... BAUDRATE is 100KHz.,Can you please tell me where i am going wrong.

    Thanks and Regards
    Shruthi
  • Hi Shruthi,

    Few points while I will try to go through code snippet:

    1- Do you have an oscilloscope or some tool to spy on the electrical signals and have a snapshots?

    2- Are you using PCF8574A? As this one can't take 0x48 as slave address (it should be 0x78 unless you use PCF8574)

    3- I assume you meet I2C bus requirements by using the required pull up resistors!

    4- And I assume you match A0, A1 and A2 to the slave address you are using, by connecting those pins to GND and VCC -as needed-.

    5- Which HDK you are using (microcontroller), can you show your HALCoGen configurations in screen snapshots?

    6- Do you do any pin multiplexing?

    Regards

    Fouad

  • Hi Fouad,

    I m using PCF8574A and slave address is set to 0x38,sorry for wrong address as i was working on other I2C device in parallel.

    pull up resistors are there.(1K on both SDA and SCL)

    I am working on RM46L854ZWT which is interfaced with PCF8574A

    These are my settings.

        74A.

    Thanks and Regards

    Shruthi

  • Hi Shruthi,

    It seems the HW interface (assuming that A0, A1 and A2 connected correctly to GDN and VCC).

    HALCoGen configurations seem fine too.

    But the slave address doesn't look right, here is a snapshot of the datasheet for PCF8574A, the adreess needs to be 0x78 (lower four bits are configured as per A0, A1 and A2 connection).

    Please let me know if I am missing any point!

    Regards

    Fouad

  • Hi Fouad,

    AO,A1,A2 address pins are connected to ground..so the 7-bit slave address comes upto 0x38..

    In general how do i read the value from register?

    sequence goes as such SLAVE_ADDR + W+ START + REG_ADDR +SLAVE_ADDR+R+START+ VALUE. + STOP...

    Do i have to enable the RM bit in MDR before setting the start condition?

    Thanks and Regards,
    Shruthi
  • Hi Shuruthi,

    BTW I am not TI I2C expert, I am just trying to help.

    Looking at the datasheet I have, it seems it is not needed to provide registry address, all needed is to have the slave address (which I believe is 0x70) with "write" then the data to be written, then stop. When we want to read, it is the slave address with "read" then stop bit. I don't think you RM is needed.

    You mentioned in your thread that you want to write to (write_addr) where is it in the datasheet?

    So I think the sequence should be:

    1- To write:

    Mode: master

    Direction: transmitter

    Address: slave address

    byte to send: data to be written to the output port (if that is the functionality needed)

    Start bit: i2cSetStart

    Wait till transaction is finished.

    Stop bit

    2- To read:

     

    Mode: master

    Direction: receiver

    Address: slave address

    Start bit: i2cSetStart

    byte to be received: i2cReceiveByte

    wait till transaction is finished

    Stop bit

    I hope this help, unfortunately I don't have access to PCF8574 so I can do some test.

    regards

    Fouad

  • Sorry for jumping in here without really understanding,  but when I look at the datasheet for the PCF8574 I don't see where the repeated start comes from.

    Just to clarify, here is a picture of a read from the PCF8574 datasheet:

    If it were showing a repeated start, there would be an "S" between the A and the next byte, and the next byte would be the address again not the data...  Like it's shown below:

  • Hi ,

    I was able to read from data ports..of pcf8574a .by introducing some delay between start and sendbyte functions..

    I was parallel working on other I2C device (SC16IS740PW) I2C-UART with same controller which requires sequence as such.when i send the register address and change it to master---receiver---start---receivebyte its stuck in receivebyte function...

    Anyone worked on this device before?i could not find any links..

    Thanks and Regards,
    Shruthi