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 commands in uboot

Hi,

I am trying to completely understand what is 0.2 in the below i2c command executed in uboot prompt, I tried with i2c help command but i did'nt understand completely what is meant by [.0, .1, .2],

could anybody please help me what is meant by this  [.0, .1, .2] in i2c command executed in uboot prompt

i2c md 0x50 0.2 0x10

 

Kindly do the needful as early as possible

Thanks in advance

 

 

  • Hi Srini,

    If you issue i2c in u-boot, it gives you the usage of the command:

    i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device 

    Detailed explanation is given in cmd_i2c.c in u-boot sources, folder u-boot/common :

    "/*
     * I2C Functions similar to the standard memory functions.
     *
     * There are several parameters in many of the commands that bear further
     * explanations:
     *
     * {i2c_chip} is the I2C chip address (the first byte sent on the bus).
     *   Each I2C chip on the bus has a unique address.  On the I2C data bus,
     *   the address is the upper seven bits and the LSB is the "read/write"
     *   bit.  Note that the {i2c_chip} address specified on the command
     *   line is not shifted up: e.g. a typical EEPROM memory chip may have
     *   an I2C address of 0x50, but the data put on the bus will be 0xA0
     *   for write and 0xA1 for read.  This "non shifted" address notation
     *   matches at least half of the data sheets :-/.
     *
     * {addr} is the address (or offset) within the chip.  Small memory
     *   chips have 8 bit addresses.  Large memory chips have 16 bit
     *   addresses.  Other memory chips have 9, 10, or 11 bit addresses.
     *   Many non-memory chips have multiple registers and {addr} is used
     *   as the register index.  Some non-memory chips have only one register
     *   and therefore don't need any {addr} parameter.
     *
     *   The default {addr} parameter is one byte (.1) which works well for
     *   memories and registers with 8 bits of address space.
     *
     *   You can specify the length of the {addr} field with the optional .0,
     *   .1, or .2 modifier (similar to the .b, .w, .l modifier).  If you are
     *   manipulating a single register device which doesn't use an address
     *   field, use "0.0" for the address and the ".0" length field will
     *   suppress the address in the I2C data stream.  This also works for
     *   successive reads using the I2C auto-incrementing memory pointer.
     *
     *   If you are manipulating a large memory with 2-byte addresses, use
     *   the .2 address modifier, e.g. 210.2 addresses location 528 (decimal).
     *
     *   Then there are the unfortunate memory chips that spill the most
     *   significant 1, 2, or 3 bits of address into the chip address byte.
     *   This effectively makes one chip (logically) look like 2, 4, or
     *   8 chips.  This is handled (awkwardly) by #defining
     *   CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
     *   {addr} field (since .1 is the default, it doesn't actually have to
     *   be specified).  Examples: given a memory chip at I2C chip address
     *   0x50, the following would happen...
     *     i2c md 50 0 10   display 16 bytes starting at 0x000
     *                      On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
     *     i2c md 50 100 10 display 16 bytes starting at 0x100
     *                      On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
     *     i2c md 50 210 10 display 16 bytes starting at 0x210
     *                      On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd>
     *   This is awfully ugly.  It would be nice if someone would think up
     *   a better way of handling this.
     *
     * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
     */"

    Best Regards,

    Yordan

  • Hi Yordan,

    Thanks  a lot for your quick responses Yordan,

    This explanation is really helpful for me & to others as well

    And more doubt, in the command i2c md 0x50 0.2 0x10 what does this 0. indicates does this indicates the i2c bus number or what????.... please correct me i my understanding is wrong

    U-Boot# i2c md 0x50 0.2 0x10
    0000: aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 41 35    .U3.A335BNLT00A5

    Could you please clarify on this as early as possible, so everything would be clear for me for proceeding further

    Kindly do the needful

    Many Thanks in advance

  • Hi,

    As I said, this is explained in the comment in cmd_i2c.c.

    For your example:

    i2c md 0x50 0.2 0x10

    0x50 - address of the slave

    0.2 - memory display starts at address 0x000 (indicated by 0), the .2 specifies the length of the address field.

    0x10 - shows that the i2c md command will display 16 registers.

    So the command i2c md 0x50 0.2 0x10 states: Display 16 registers starting at address 0x000 (addr length is 2-bytes) from slave located at 0x50

    Hope this helps.

    Best Regards,

    Yordan