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 communication at u-boot level



Hello all,

I am working on beagle board uboot  and i connected a device which i need to communicate with I2C and iam in confuse how to use the I2C functions.Should i have to

write the I2C function or i have to use the pre defined functions which are defined in uboot package .

THANKS in Advance ...

Ranjith

  • At the u-boot prompt there are i2c commands you can run, do a 'help i2c' to see them all.  You can use this to see if things are visible as you would expect them.  From there, the next steps depend on what you've attached to the i2c bus...

  • Hello Tom,

    Thanks for ur suggestion...Can you help me in the Below query

    Actually in my uboot beagle board i.e in  omap3 processor there are four I2C are present and first one(I2C) is used as I2C_BASE1 0x48070000 for PMIC(power management IC). so, in this my device is connected to I2C2 with the I2C_BASE2  0x48072000 .For communication from processor to my device how to write to the  device and read from the device

    should i have to initialize any thing to read from device or to write .

    could you please help me out in what to initialize and hoe to communicate with the device Using I2C2

    Thanks,

    Ranjith.

  • So again, there's two ways to go about this.  In writing a driver for U-Boot for the device, see board/ti/beagle/beagle.c and what's done for the various expansion board today. But before you go down this route you can interactively check things:

    Texas Instruments X-Loader 1.5.0 (Jul  5 2011 - 23:22:25)
    Beagle Rev C5
    Reading boot sector
    Loading u-boot.bin from mmc


    U-Boot 2011.06-rc3 (Jul 05 2011 - 23:22:46)

    OMAP3530-GP ES3.1, CPU-OPP2, L3-165MHz, Max CPU Clock 720 mHz
    OMAP3 Beagle board + LPDDR/NAND
    I2C:   ready
    DRAM:  256 MiB
    NAND:  512 MiB
    MMC:   OMAP SD/MMC: 0
    In:    serial
    Out:   serial
    Err:   serial
    Beagle Rev C4
    timed out in wait_for_pin: I2C_STAT=0
    I2C read: I/O error
    Unrecognized expansion board: 0
    Die ID #2b420004000000000403951c0900200e
    Net:   Net Initialization Skipped
    No ethernet found.
    Hit any key to stop autoboot:  0
    OMAP3 beagleboard.org # i2c probe
    Valid chip addresses: 48 49 4A 4B
    OMAP3 beagleboard.org # help i2c
    i2c - I2C sub-system

    Usage:
    i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum
    i2c dev [dev] - show or set current I2C bus
    i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device
    i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device
    i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)
    i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)
    i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)
    i2c probe - show devices on the I2C bus
    i2c read chip address[.0, .1, .2] length memaddress - read to memory
    i2c reset - re-init the I2C Controller
    i2c speed [speed] - show or set I2C bus speed
    OMAP3 beagleboard.org # i2c dev
    Current bus is 0
    OMAP3 beagleboard.org # i2c dev 2
    Setting bus to 2
    OMAP3 beagleboard.org # i2c probe
    Valid chip addresses:
    OMAP3 beagleboard.org #

    In my case, nothing is attached to i2c2 so probe found nothing.  But in your case, assuming everything is correct at the hardware side, you should see the address you put your device at.  And you can use the other i2c commands to poke it, as you would in code.  By which I mean, 'i2c dev 2' is like writing i2c_set_bus_num(1).

  • Hey Tom,

    I did as u explained but when i tried to do

    OMAP3 beagleboard.org # i2c dev
    i2c - I2C sub-system

    Usage:
    i2c speed [speed] - show or set I2C bus speed
    i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device
    i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)
    i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)
    i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)
    i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum
    i2c probe - show devices on the I2C bus
    i2c reset - re-init the I2C Controller
    i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device
    OMAP3 beagleboard.org # i2c dev 2
    i2c - I2C sub-system

    Usage:
    i2c speed [speed] - show or set I2C bus speed
    i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device
    i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)
    i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)
    i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)
    i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum
    i2c probe - show devices on the I2C bus
    i2c reset - re-init the I2C Controller

    so, can you help me in this and one more thing is should i have to initialize the I2C2 in my code or else  i can directly call write or read function with their parameters?i mean using the device address which i have connected ...

    thanks,

    Ranjith .

  • Hello Tom,

    Can you please help me in writing a I2C driver code for beagleboard   u-boot ,As i have explained you regarding a device connected to I2C2  and i want to communicate with that.

    can help me out .how to write driver code ?

     

    Thanks

    Ranjith

     

  • Ranjith Kumar Akaram said:

    Hey Tom,

    I did as u explained but when i tried to do

    OMAP3 beagleboard.org # i2c dev

    What binaries did you use?

  • Ranjith Kumar Akaram said:

    Hello Tom,

    Can you please help me in writing a I2C driver code for beagleboard   u-boot ,As i have explained you regarding a device connected to I2C2  and i want to communicate with that.

    can help me out .how to write driver code ?

    If you take a look around in the u-boot sources you should see a number of examples there already.  If you have a specific problem I can try and help, however.

  • Hey TOM,

    Thanks for your reply...,

    I have placed my code in board/ti/beagle/mycode.c  in the iam directly calling the i2c_write by passing the parameters as

    chip= slave address of my device ,0x23;

    addr=slave address +offset for write ,0x52; //this is from the datasheet of my device for writing the data.

    alen=1;

    buffer=mydata;

    len=number of bytes;

    this are the thing am using to write data through the i2c2.

    do i need to initialize the i2c2 .please let me know the procedure or steps how to do from the starting.

    As you said there are many examples used in source code ..but its not that clear .how to use the i2c2 and all .

    please suggest me with an answer.i have only two day to solve this module.

    thanks,

    Ranjith

  • Ranjith Kumar Akaram said:

    do i need to initialize the i2c2 .please let me know the procedure or steps how to do from the starting.

    As you said there are many examples used in source code ..but its not that clear .how to use the i2c2 and all .

    Based on get_expansion_id I think you just need to call i2c_set_bus_num:

    board/ti/beagle/beagle.c::get_expansion_id said:

            i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);


            /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
            if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
                    i2c_set_bus_num(TWL4030_I2C_BUS);
                    return BEAGLE_NO_EEPROM;
            }

            /* read configuration data */
            i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
                     sizeof(expansion_config));

            i2c_set_bus_num(TWL4030_I2C_BUS);

  • Hello Tom ,

    As u said am doing the same thing in place of (EXPANSION_EEPROM_I2C_ADDRESS i gave the I2c2 address and in the place of 0 i.e its a addr(memory register address location ) .so i am confused to give this value could you please suggest me what value should i have to give .

    Thanks

    ranjith

  • Ranjith Kumar Akaram said:

    As u said am doing the same thing in place of (EXPANSION_EEPROM_I2C_ADDRESS i gave the I2c2 address and in the place of 0 i.e its a addr(memory register address location ) .so i am confused to give this value could you please suggest me what value should i have to give .

    It sounds like you're giving the correct values.  Again, if the hardware is properly attached to the board you can use the i2c commands to simulate the code and do probes to see what addresses are showing up.

  • Hello Tom, can suggest me what are the parameter i need to send in I2C_write function.

    I know only few..

    chip = device address .

    addr= ?

    alen-number of bytes of addr

    *buffer= data

    len= length of the buffer .

    can u please tell me about addr?

    because its saying about the memory(register)address in the chip. what does it mean? about the address in the device or i2c address .please suggest me i am confused a lot in this .

    Thanks,

    Ranjith.

  • Hello all,

    Can any one please suggest me on the I2C protocol. I am working at u-boot level on beagleboard and am facing proble in the i2c write protocol in i2c_write_byte

    ARDY bit is not setting actually i am very confused in sending the memory(register)address of the chip with that am unable to get success in the write call .my XRDY that is

    transmit ready IRQ bit is not setting so it s not writing the data to the data register .can any one please suggest me.

    Thanks ,

    Ranjith.

  • Hello tom, > As i have discussed with you about the I2C Problem on OMAP3 at u-boot level > .my device that is a crypto device(TPM) which am unable to communicate with > it > because TPM chip dont have an any internal address to store the values. it > will directly give response for the default bytes. so when i am trying to > send the data with > i2c_write(0x29(chip addr),0x00(addr),1,data,numbytes); > here data is nothing but a 12 bytes which is used to get all variable of TPM > into default place and here i am using the i2c_driver code > i.e.,omap24xx_i2c.c > so can you please suggest me what to do to get the response from the TPM > CHIP.whether to change any clock because the TPM CHIP works with the 100 and > 400 khz and 3.3v u-boot package U-Boot 2010.06. thanks ranjith
  • Hello tom, As i have discussed with you about the I2C Problem on OMAP3 at u-boot level .my device that is a crypto device(TPM) which am unable to communicate with it because TPM chip dont have an any internal address to store the values. it will directly give response for the default bytes. so when i am trying to send the data with i2c_write(0x29(chip addr),0x00(addr),1,data,numbytes); here data is nothing but a 12 bytes which is used to get all variable of TPM into default place and here i am using the i2c_driver code i.e.,omap24xx_i2c.c so can you please suggest me what to do to get the response from the TPM CHIP.whether to change any clock because the TPM CHIP works with the 100 and 400 khz and 3.3v u-boot package U-Boot 2010.06. Thanks, Ranjith