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.

am1808 i2c failure to write

Other Parts Discussed in Thread: AM1808, OMAPL138, DA8XX

i am working firs time in i2c..  i am using am1808 custom board . using oled 128*64 for display 

i am usin i2c0

i configured board file and if i run application dev is opened and found slave addres

 but error occureing failed to write i2c bus

what are the steps i need to follow to power on oled .

thanks in advance

  • Hi,

    Thanks for your post.

    Kindly share your appropriate board configuration file.

    What are the steps you have followed to reproduce the error posted above? Please elloborate in brief.

    Regards,

    Sivaraj K

  • in this i didnt add any driver file for oled

    static struct i2c_board_info __initdata omapl138_hawk_i2c_devices[] = {

    {


    I2C_BOARD_INFO("wm8974", 0x1a), .... my audio file also in i2c
    },
    };

    static struct davinci_i2c_platform_data omapl138_hawk_i2c_0_pdata = {

    .bus_freq = 100, /* kHz */
    .bus_delay = 0, /* usec */
    };


    static struct i2c_gpio_platform_data da850_gpio_i2c_pdata = {
    .sda_pin = GPIO_TO_PIN(1, 4),
    .scl_pin = GPIO_TO_PIN(1, 5),
    .udelay = 2, /* 250 KHz */
    };

    static struct platform_device da850_gpio_i2c = {
    .name = "i2c-gpio",
    .id = 0, 
    .dev = {
    .platform_data = &da850_gpio_i2c_pdata,

    },
    };


    static void omapl138_hawk_i2c_init(void)
    {
    int ret;

    platform_device_register(&da850_gpio_i2c);
    ret = davinci_cfg_reg_list(da850_i2c0_pins);
    if (ret)
    pr_warning("omapl138_hawk_init: i2c0 mux setup failed: %d\n",
    ret);
    printk("\n... audio i2c");


    ret = da8xx_register_i2c(0, &omapl138_hawk_i2c_0_pdata);
    if (ret)
    pr_warning("omapl138_hawk_init: i2c0 registration failed: %d\n",
    ret);
    i2c_register_board_info(1, omapl138_hawk_i2c_devices,
    ARRAY_SIZE(omapl138_hawk_i2c_devices));
    }

    already i fonfigured pinmux for i2c in da850 and mux.h file

    kindly help me out.. i don know where i have stucked

  • Hi Meena,

    i am usin i2c0

    i configured board file and if i run application dev is opened and found slave addres

     but error occureing failed to write i2c bus

    what are the steps i need to follow to power on oled .

    You have to read the OLED data sheet and understand the commands to initialize the display and displaying letters, images etc.,

    What is your OLED part number ?

    Please refer to the following links for OLED interfacing.

    http://wiki.openpicus.com/index.php?title=GROVE_-_OLED_display_128x64

    http://www.geekonfire.com/wiki/index.php?title=I2C_OLED_Panel%28128x64%29

    Please refer to the following link which could help on i2c programming.

    http://elinux.org/Interfacing_with_I2C_Devices

    https://www.kernel.org/doc/Documentation/i2c/dev-interface

    http://www.acmesystems.it/i2c

  • sorry for not mentioning part number

    i am using Densitron  oled.

    DD-12864WE-6B

    its is not at all switch on first.. 

    this is my application code

    Write_Command(0xFD,0x12,2); 
    Write_Command(OLED_Display_Off,0,1);  
    Write_Command(OLED_SETDISPLAYCLOCKDIV, 0xA0,2); 
    Write_Command(OLED_SETMULTIPLEX, 0x3F,2);
    Write_Command(OLED_SETDISPLAYOFFSET, 0x00,2); 
    Write_Command(OLED_SETSTARTLINE | 0x0,0,1);
    Write_Command(OLED_MEMORYMODE, 0x02,2);

    Write_Command(OLED_SEGREMAP | 0x1,0,1);
    Write_Command(OLED_COMSCANDEC,0,1);
    Write_Command(OLED_SETCOMPINS, 0x12,2); 
    Write_Command(OLED_ContrastLevel, 0xE3,2); 
    Write_Command(OLED_SETPRECHARGE, 0x19,2);
    Write_Command(OLED_SETVCOMDETECT, 0x34,2);
    Write_Command(OLED_DISPLAYALLON_RESUME,0,1); 
    Write_Command(OLED_Normal_Display,0,1);
    Fill_RAM(0x00);
    Write_Command(OLED_Display_On,0,1); 

    void Write_Command(uint8_t c0, uint8_t c1, uint8_t arg)
    {
    uint8_t *buff;

    if(arg==1)
    {
    buff=(uint8_t*)malloc(2);
    if(buff==NULL)
    printf("malloc failed");
    buff[1] = c0;
    buff[0] = OLED_Command_Mode;

    }
    else if(arg==2)
    {
    buff=(uint8_t*)malloc(3);
    if(buff==NULL)
    printf("malloc failed");
    buff[1] = c0;
    buff[2] = c1;
    buff[0] = OLED_Command_Mode;
    }

    I2Cwrite(buff, sizeof(buff),arg);

    }

    int I2Cwrite(const char * buf, uint32_t len, uint8_t arg)
    {
    int reason = -1,i;
    //printf("transfering %d bytes buf[0]:%0X, buf[1]:%0X\n",buf[0],buf[1]);

    if (!fd)
    return (-1);

    if(arg==1)
    {
    // printf("transfering %d bytes buf[0]:%0X, buf[1]:%0X\n",arg,buf[0],buf[1]);
    if (write(fd,buf,2) != 2)
    {
    printf("Failed to write to the i2c bus.\n");
    //buffer = g_strerror(errno);
    }
    }
    if(arg==2)
    {
    //printf("transfering %d bytes buf[0]:%0X, buf[1]:%0X,buf[2]:%0X\n",arg,buf[0],buf[1],buf[2]);
    if (write(fd,buf,3) != 3)
    printf("Failed to write to the i2c bus.\n");
    }

    if(arg==17)
    {
    //printf("transfering %d bytes\n",arg);
    for(i=0;i<17;i++)
    //printf("buf[%d]:%0X\n",i,buf[i]);// buf[1]:%0X,buf[2]:%0X\n",arg,buf[0],buf[1],buf[2]);
    if (write(fd,buf,arg) != arg)
    printf("Failed to write to the i2c bus.\n");
    }
    }

    .thanks 

  • what is meant by

    initializing i2c bus recovery..   i have two custom board. in one of my board during boot up itself

    initalizing i2c recovery is running

     when i run i2c application its keep on running

  • Hi Meena,

    Some times, I2C bus get hang when I2C SDL line grounded/low state (master lock up issue) . So, I2C master needs to send 9 clock pules on I2C SCL line to recover from I2C bus hang that is called I2C bus recovery process.

    Please refer to the page no 2.

    http://www.analog.com/static/imported-files/application_notes/54305147357414AN686_0.pdf

    https://lkml.org/lkml/2010/4/6/262

    http://e2e.ti.com/support/microcontrollers/stellaris_arm/f/471/t/71089.aspx

    Check your I2C data line.

  • Never used this OLED. Some comments on the code. Your code fragment use malloc() but never calls free(). I assume that your code lets the OS clean after it exits.

    From what I can tell from the OLED doc, the commands are 1+n bytes. Your code uses a 2+n bytes where the first byte is OLED_Command_Mode. Is OLED_Command_Mode the device I2C address? Do you set the I2C address?

  • hi stalin

    i checked my data line its in high only both d1 and d2 .

  • hi norman,

    no my oled command mode is not device address.

     i set oled addr as 3C OR 3D INITIALLY..

  • i want to know whether my i2c is working or not because its keep on getting  write failed

    so i used the command i2cdetect -y 1

    then  i got 

    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- 08 -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --

    then i got the address as 0x08 so 

    i gave  i2cget -y 1 0x08 

    i got 

    i2c_davinci i2c_davinci.1: RDR IRQ while no data requested
    0x00

    again i gave same command but now 

    i2c_davinci i2c_davinci.1: controller timed out
    i2c_davinci i2c_davinci.1: initiating i2c bus recovery
    Error: Read failed

    i gave   i2cset -y 1 0x08 255  

    i2c_davinci i2c_davinci.1: controller timed out
    i2c_davinci i2c_davinci.1: initiating i2c bus recovery
    Error: Write failed

    i don know what is happenning ,,

    please  kindly help me out i still having this issue for a long time

     

  • Hi Meena,

    Try to reduce the I2C operating frequency to 20KHz , just for testing.

    static struct davinci_i2c_platform_data omapl138_hawk_i2c_0_pdata = {

    .bus_freq = 20, /* kHz */
    .bus_delay = 0, /* usec */
    };

  • hi stalin,

     i reduced i2c operating frequency.

    but no change same error

    i2cset -y 1 0x08 255
    SUCCESS: open passed
    i2c_davinci i2c_davinci.1: controller timed out
    i2c_davinci i2c_davinci.1: initiating i2c bus recovery
    Error: Write failed

  • Hi Meena,

    What is your kernel version and SDK details please ?

    Do you have pull up resistors on I2C bus ?

    What are all the i2c slave devices are connected  to the bus ?

  •  stalin.

     i am using linux-3.1.10

    ya i have pull up resistors 

    right now i connected my oled alone. 

  •  iam using ti -sdk .

    in my oled the controller is ssd1309 for this is programed as like this

    buff[0] = 0x3c; // slave address

    if (write(fd,buff,1) != 1)
    printf("Failed to write to the i2c bus.data\n");
    buff[0] = 0x40; // oled data mode    buff[0] = 0x00; // command mode

    if (write(fd,buff,1) != 1) 
    printf("Failed to write to the i2c bus.data\n");
    buff[0] = c0; // data to display

    if (write(fd,buff,1) != 1)
    printf("Failed to write to the i2c bus.data\n");

     but  no changes..  result is failed to write  to the i2c bus

  • before that  i am using the same i2c0 pin for my speaker..

     i got audio.in my speaker

    now for display y its not working.. my i2c0 data0 data1 and data2 all are in high.

     

  • Hi Meena,

    Are you getting this "i2c controller time out error" only when you use OLED ?

    And not getting the same error when you use speaker on I2C bus ?

    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- 08 -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --

    Could you please tell us, what are all the i2c slave devices has been connected to the I2C bus 0 other than OLED ?

    What is the slave device which has 0x19 as a slave address ?

    I have seen TI E2E post similar to yours.

    http://e2e.ti.com/support/embedded/linux/f/354/t/191705.aspx?pi196120=1

    Try it out the mentioned suggestions.

  • sorry for late reply, i connected my audia wm8974 in i2c0 and my oled 128x64  

    DD-12864WE-6B in i2c0 .. 

    my oled adress is 3c or 3d

    my audio address is 1A.. i don know about 0x19.. from where u get this.

  • The Densitron DD-12864WE-6B uses Solomon SSD1305. The SSD1305 does not respond to serial reads. I believe i2cdetect uses read transactions. It will not see a response if the SSD1305 does not respond.

    The linux i2c driver requires you to set the slave address via ioctl, eg.

    ioctl(fd, I2C_SLAVE, 0x3C); /* Do this once */

    The mainline kernel has a driver for a similar controller. See "drivers/video/ssd1307fb.c" at http://www.kernel.org.

  • hi norman,

    ya i done ret= ioctl(fd, I2C_SLAVE, 0x3C); /* Do this once */

    it returned a value 0  so i concluded Connected with the I2C slave address.. 

    then my next command is write

    if i give write command it keeps on telling write failed..

  • Here's my pseudo code of i2cset functionality that sends a command to the OLED controller. I have not compiled this code.

    #include <stdio.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <sys/ioctl.h>
    #include <errno.h>
    #include <linux/i2c.h>
    #include <linux/i2c-dev.h>
    
    /* progname DATA1 ... DATA6 */
    /* Example to send "Display OFF" */
    /* progname 0xAE */
    int main(int argc, char *argv[])
    {
      int           fd;
      unsigned char buf[7]; /* 1 control byte + 6 data bytes */
      int           i;
      unsigned long x;
    
      if (argc<2)
      {
        printf("Not enough arguments.\n");
        return(-1);
      }
    
      if (argc>7)
      {
        printf(Too enough arguments.\n");
        return(-1);
      }
    
      buf[0] = 0x80; /* control byte */
      for(i=1; i<argc; i++)
      {
        x = strtoul(argv[i], NULL, 0);
        if(x>255)
        {
          printf("arg %d too big\n", i);
          return(-1);
        }
        buf[i] = (unsigned char)x;
      }
    
      fd = open("/dev/i2c-1",O_RDWR);
      if(fd==NULL)
      {
        printf("Unable to open file\n");
        return(-1);
      }
    
      if (ioctl(fd, I2C_SLAVE, 0x3C) < 0)
      {
        printf("Unable to set address, err=%d\n", errno);
        close(fd);
        return(-1);
      }
    
      if(write(fd,buf,argc)!=argc)
      {
        printf("write failed,err=%d\n", errno);
      }
    
      close(fd);
      return(0);
    }
    

  •  hi norman.. i compiled ur code and run using arguments

    ./example  0xAF 0x00   /* 0xAF.. to display on*/

    for even this to i got the same output.. 

     write failed,err=121 ..

    i am sure its not writing or reading.. if i use i2c detect -y 1 /* device connected in i2c0 */

    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: i2c_davinci i2c_davinci.1: RDR IRQ while no data requested
    -- -- -- -- -- 08 -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- 1a -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --

    1a is address of my audio .. wm8974..\

    0x3c is not found here.. 

    i done below configuration in my board file. so i got 0x1A

    static struct i2c_board_info __initdata omapl138_hawk_i2c_devices[] = {
    {

    I2C_BOARD_INFO("wm8974", 0x1a),

    },
    };

    i don know how to configure for my oled.. because i don have driver file to add driver name but i have address 

    just a try i configured 

    I2C_BOARD_INFO("i2c-gpio", 0x3C),

    but i didnt get my oled addres in i2cdetect.

    can u help me .. waiting for the reply..

    thanks in advance

  • Error 121 is EREMOTEIO. Without digging into the i2c core driver, I am guessing the device did not ACK the write request.

    I doubt i2cdetect will find the OLED. I believe i2cdetect uses dummy read transactions to see if a device responds. The OLED controller responds only to write transactions.

    Adding "I2C_BOARD_INFO("wm8974", 0x1a)," should result in "UU" in i2cdetect. The "UU: means that a kernel driver has reserved that address. Do not add I2C_BOARD_INFO for 0x3C or 03D. That might interfere with userspace access to those addresses.

    At this point, you need to connect up an oscilloscope to the OLED SCL and SDA lines. Write a command out and check the signals.

  • It seems t2cset uses the SMBus version of I2C. It should not matter though. What is the result of:

    i2cset -y 1 0x3C 0x80 0xAE
    i2cset -y 1 0x3D 0x80 0xAE

  • hi norman,

     i am totally confused.. whats is happenning now..\

    i2cset -y 1 0x3C 0x80 0xAE
    i2cset -y 1 0x3D 0x80 0xAE  if i gave these command

    Error: Write failed  

    .. 

    in my oled i am not using any driver file using only application file.. configured i2c_chardev.. 

    they using ssd1309 driver ic..

    shall i add ssd1307fb.c driver file??

    it will work?

     

  • hi,

    i have pullup resistors in my sda and scl line.. all are in high

    but if i gave  i2c write  and i checked whether my sda pin going low then come back to high..

    but  sda pin is in high state only... 

    totally fed up with this.

    i don know why .. didnt toggle.

  • We have been operating under the assumption that the I2C signal path is good.

    With just pullups connected and no I2C devices, If you do a i2cdetect, do you see SCL an SDA activity?

    Do you have a working scenario with the audio chip? If you do a i2cget from the audio chip, do you see SCL an SDA activity?

    Not much more to suggest. Perhaps the pullup resistors are too small. Try larger pullup resistors.

  • thankyou .. thankyou to every one who support me in this oled..

    i got my oled working finallyyyyy

  • That is good news. What was the problem? What did you do to solve it?

  • Hi Meena,

    The sound is pretty good really.

    Could you please update us what have you changed to make it OLED working, so other community members also get benefited.

    Thank you.

    Dear Norman,

    Again, thank you very much for your help on this.

  • hi hi,

    i enabled reset pin using gpio

    and then i make  reset to of and then on with delay 3ms

    then my ic2 wrote successfully.. 

    finally i got rolling my name..

  • and  now in my i2c detect i can find my address 0x3d

    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- 08 -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- 1a -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- 3d -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --