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.

Again problem interfacing I2C device with TM4C123 launchpad

Other Parts Discussed in Thread: TM4C123GH6PM

Dear all,

 I have been facing serious issues with the I2C peripheral (I2C1 in specific with pins PA6 = SCL and PA7 = SDA). I got replies from helpful members, but the problems seems to have remained.

I have configured the peripheral exactly as per the tivaware as well as register setup descriptions in the datasheet, but somehow, whenever I try to read data back from the EEPROM AT24C02 specific area (say 0x00), it simply returns a 0xFF . Sometimes it returns even a garbage value.

Also I have been using an I2C device that works at 5V. So I have used a 10K pullup with the VCC, is there a problem in the voltage level? Is it a problem if the I2C device runs at 5V, whereas the Tiva runs at 3v3?

Please help me with some sample code either in tivaware lookup or direct register configuration that has worked with systems like 24cxx eeprom where we have to write one internal address pointer byte (for eeprom) and then the data.

Regards

  • Hello Turjasu,

    TM4C123 devices are 5V tolerant so there is no problem connecting the pads to 5V pull up. Since you have connected the Pull to VCC=3.3V, that may not match the Vih(min) as expected by the device causing issues.

    Regards

    Amit

  • He's vague on just what those pull-ups drive to!  By my read - could be 3V3 or 5V.

    Are not 3V3 eeproms easily/quickly available?  (instant resolution - that issue)

    We just answered his past (tres similar) post - as famed baseball player (Yogi Berra) stated, "Deja Vu - all over again!"

    Attention to detail - and/or connection to a proper/tested/new external device beats (endless) repeat efforts here... (If I scream - alone - in a forest - would anyone hear it?)  We note that famed, "Does not work" (nearly) rides again...

  • Thanks amit.. I meant i pulled up to 5V.. Its ok now... after serching through some same topics in the forum i figured out the code. I will share it here...if someone needs it

    To cb1_mobile :  I would like to say  that I may be people like me are vague in their expression, silly in my questions because I have never done work more than a 89s52 system, that too in assembly system and I guess TI has done efforts in their MCU deepdive to initiate such "make the switch" cases. So i gues i would expect some more patient replies from you. I understnad that my questions repeats the same word " does not work" but as an expert you should respect silly questions in the forum.. thanks for your help

  • @Turjasu,

    No one characterized your questions (ever) as silly. 

    As for patience - you'll note that I suggested a likely "superior mating" of a 3V3 eeprom to your 3V3 MCU.  Most always I'm patient enough to provide "real" workable suggestions.  (my firm does this for a living...)

    Inexactness of issue description has long been a serious issue here/other forums.  And - I've gone far "above/beyond" the normal outsider in attempting to provide a, "standardized"  forum-post protocol - intended to insure posts' "completeness."  Vendor here rejected my guidelines (not Amit - he was/remains supportive) clearly I do my small part...

    I doubt a fair read will reveal any, "disrespect" - my hoped for - clear identification of post "weaknesses" is a proper means to raise awareness - is it not?  (and raise it - both @ the original poster and follow-on reader level)  When nothing is said - how are you/multiple follow-on readers - ever supposed to improve?  Some may (more properly) characterize that "care/effort" as "real, pin-pointed, & more importantly, USEFUL respect!"  Vendor's rep is bound by, "political correctness" hesitates to risk offense.  (although after some prodding - that's improved)  We outsiders - so long as we tread w/some care - are free to speak, "bit more directly."  (or we can remain silent - let the forum, "run amuck!")

    Over long years here (& elsewhere) have amassed >300 "forum friends."  Doubtful that disrespect is much in evidence and "silly" did not flow - my pen...  Precision, care in post's creation (detail, detail) & clear report of, "all you've tried" are my (pen's) ink-trail...

  • This is the code that has worked for me:

    MY SLAVE ADDR = 0x50

    THE CODE WAS ORIGINALLY GIVEN IN SEPARATE FORUMS HERE... I HAVE JUST MODIFIED A BIT ACCORDING TO MY USE

    I2C MODULE USED = I2C1

    HAVE SAVED SOME DATA AND RECALLED IT BACK USING REPEATED START TECHNIQUE.

    THIS CODE I HAVE TESTED WITH PA6 = SCL & PA7 = SDA AND WORKD FINE WITH 24C02

    #include <stdint.h> // ift
    #include <stdbool.h>
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/i2c.h"
    #include "driverlib/rom.h"
    #include "driverlib/pin_map.h"
    #include "inc/tm4c123gh6pm.h"
    #include "inc/hw_i2c.h"

    int i = 0;
    uint8_t lcd[5]={0x99,0x88,0x77,0x66,0x54};


    int main(void)
    {
    unsigned long data;
    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);

    //
    // The I2C1 peripheral must be enabled before use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);

    //
    // For this example I2C0 is used with PortB[3:2]. The actual port and
    // pins used may be different on your part, consult the data sheet for
    // more information. GPIO port B needs to be enabled so these pins can
    // be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Select the I2C function for these pins. This function will also
    // configure the GPIO pins pins for I2C operation, setting them to
    // open-drain operation with weak pull-ups. Consult the data sheet
    // to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    //GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6); // I2CSCL
    GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);

    //
    // Configure the pin muxing for I2C0 functions on port B2 and B3.
    // This step is not necessary if your part does not support pin muxing.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinConfigure(GPIO_PA6_I2C1SCL);
    GPIOPinConfigure(GPIO_PA7_I2C1SDA);

    //
    // Enable and initialize the I2C0 master module. Use the system clock for
    // the I2C0 module. The last parameter sets the I2C data transfer rate.
    // If false the data rate is set to 100kbps and if true the data rate will
    // be set to 400kbps. For this example we will use a data rate of 100kbps.
    //
    I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false);

    //
    // Tell the master module what address it will place on the bus when
    // communicating with the slave. Set the address to SLAVE_ADDRESS
    // (as set in the slave module). The receive parameter is set to false
    // which indicates the I2C Master is initiating a writes to the slave. If
    // true, that would indicate that the I2C Master is initiating reads from
    // the slave.
    //

    while(1)
    {
    I2CMasterSlaveAddrSet(I2C1_BASE, 0x50, false); // The address of the Slave is 0x50

    I2CMasterDataPut(I2C1_BASE, 0x10); // Addr 0x10

    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    while(I2CMasterBusy(I2C1_BASE));

    for (i=0;i<5;i++)
    {
    I2CMasterDataPut(I2C1_BASE, lcd[i]); // data to be saved at Addr 0x11 under autoincrement mode

    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);

    while(I2CMasterBusy(I2C1_BASE));

    }

    //I2CMasterDataPut(I2C1_BASE, 0xee); // data to be saved at Addr 0x12 under autoincrement mode

    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

    while(I2CMasterBusy(I2C1_BASE));
    //////// write complete/////////////////////////////////////////////////////////////////////////////////
    SysCtlDelay(5500000); // writing time

    ///////////////////////////////////////////////////////////////
    // Read at address 0x11
    I2CMasterSlaveAddrSet(I2C1_BASE, 0x50, false);

    I2CMasterDataPut(I2C1_BASE, 0x10); // Addr 0x11

    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_SINGLE_SEND);

    while(I2CMasterBusy(I2C1_BASE));


    I2CMasterSlaveAddrSet(I2C1_BASE, 0x50, true);

    data = I2CMasterDataGet(I2C1_BASE); //Receive

    //I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
    //
    while(I2CMasterBusy(I2C1_BASE));

    data = I2CMasterDataGet(I2C1_BASE); //test

    for (i=0;i<4;i++)
    {
    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    //
    while(I2CMasterBusy(I2C1_BASE));

    data = I2CMasterDataGet(I2C1_BASE); //Receive
    }

    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
    //
    while(I2CMasterBusy(I2C1_BASE));

    }
    //return(0);
    }

    Thanks to all for help