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.

i2c bitbang library: could use some help

Other Parts Discussed in Thread: BQ27510, HALCOGEN

I'm implementing an i2c bitbang library for the TMS570LS04x. This device doesn't have i2c peripherals.

I'm using Vincent Himpe's framework.

I am testing the framework with the Fuel Tank Boosterpack charge monitoring IC bq27510.

Communication is failing. When sending the i2c address out, I don't get an ACK back (expecting data pin to get pulled low by the slave, but that doesn't hapen.

I have attached my source files, and screenprints from logic analyser.

For those of you that have spare time and i2c knowledge, it would be great if you could have a look at my code and help me further on my path.

My HALCoGen project has just enabled the GPIO library and all others disabled; no settings on any other tab.

Code:

4760.vh.h

8244.vh.c

1362.sys_main.c

5428.gioutils.h

3414.gioutils.c

My code fails on line 96 of sys_main.c.

In the call to i2c_write(), the code does not ack in file vh.c, line 223.

  • Jan,

    We assume you have pull-up's in place on the I2C lines.

    Based on your screen shot we believe you need to get your SCL from LO to HI where ACK is expected ONLY AFTER configuring the SDA pin to input mode (It will remain High since you have a pull-up). Something similar to the below code modified from your snippet,

    void i2c_getAck() {
    /*
    * SUBroutine GETACK
    * SDA=1
    * SCK=1
    * WAITFOR SDA=0
    * SCK=0
    * ENDSUB
    */
    gioutilsSetPin(_vh_sda, 1);

    vh_i2cDelayMicroSeconds(_i2c_wait);

    gioutilsSetPinDirection(_vh_sda, pinRead); 

    vh_i2cDelayMicroSeconds(_i2c_wait);

    gioutilsSetPin(_vh_scl, 1);

    while (gioutilsGetPin(_vh_sda)) {
    vh_i2cDelayMicroSeconds(_i2c_wait);
    // WAITFOR SDA=0
    }

    ...

    ...

    Let us know if it works.

  • Hey, thanks Karthik.

    Makes sense. I'll try and post back.

  • It didn't help.

    I moved the line to switch from output to input before changing the SCL change (like you suggested).

    And you are right. My SDA stays high when I flip to input mode because of the pull-up. But I still didn't get an ACk from the bq27510.

    My next step is to try to communicate with it using a processor with i2c peripheral, record the communication and compare that with my bitbang results...

  • It's definitely my code :)

    I've tried this with a µC that has i2c peripherals, and it works as expected:

    At least I have a starting point to compare behaviour now.

  • I'm getting there.

    I misinterpreted this pseudocode:

     Device_adress=Device_adress AND (1111.1110)b / This clears READ flag /

    I just replaced the LSB with 0.
    But you have to left shift and replace with 0

    	/*
    	 * SUBroutine WRITE(Device_address,Number_of_bytes)
    	 *       Device_adress=Device_adress AND (1111.1110)b / This clears READ flag /
    	 *       CALL START
    	 *       CALL PUTBYTE(Device_adress)
    	 *       CALL GETACK
    	 *       FOR x = 0 to Number_of_bytes
    	 *             CALL PUTBYTE (DATA(x))
    	 *             CALL GETACK
    	 *       NEXT x
    	 *       CALL STOP
    	 * ENDsub
    	 */
    	int i = 0;

    // the fix is to replace // address = address & 0xFE;
    // by address = address << 1;

  • I managed to get a working library using the n2het i2c emulator example posted on this forum.

    It is successfully talking to the TI Fuel Tank Booster Pack, getting the remaining charge from the bq27510 battery fuel gauge.

    I still have one issue to resolve. There is an unexpected i2c Read command for address 0x03 showing up in my logic analyzer, between my write and read commands to the bq27510. That issue may be in my testbed, or in the emulator library.

    Below a screen print of my results:

  • I've posted the results in the e2e Launch your Design area:

    http://e2e.ti.com/group/launchyourdesign/m/boosterpackcontest/665692.aspx