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 Setup problem

Hello!

I have a problem with the I2C setup of a LM4F120H5QR. I'm trying to configurate the SDA line with this instruction:

"GPIOPinConfigure(GPIO_PB3_I2C0SDA);"

The problem is that I get this error: "#20 identifier "GPIO_PB3_I2C0SDA" is undefined"

The include path is correct, and this is the files I'm using:

#include "inc/lm4f120h5qr.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/i2c.h"

Thank you!

  • Hi Francisco,

    here's is my initialization code for I2C0. I also configure UART0 for StdIO. Pls notice the instruction marked in yellow! 

    Rgds
    aBUGSworstnightmare 

    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/adc.h"
    #include "driverlib/rom.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "utils/uartstdio.h"
    #include "driverlib/i2c.h"

    ...

    //
    // Set the system clock to run at 40Mhz off PLL with external crystal as
    // reference.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

    //
    // Initialize the UART interface
    //
    // Configure the appropriate pins as UART pins; in this case, PA0/PA1 are
    // used for UART0.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Initialize the UART standard IO module (prints to Launchpad virtual COM port)
    //
    UARTStdioInit(0);
    //
    // Print a string.
    //
    UARTprintf("UARTStdioInit ...\n");
    ROM_SysCtlDelay(2000000);

    //
    // 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.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Select the I2C function for these pins. This function will also
    // configure the GPIO 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.
    //
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); // special I2CSCL treatment for M4F devices
    ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

    //
    // 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_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    //
    // Initialize the I2C interface to talk to the TCAxxx/TLCxxx . The true
    // parameter specifies a I2C speed of 400kbps.
    //
    //
    // The I2C0 peripheral must be enabled before use.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    //
    // Enable and initialize the I2C0 master module.
    //
    ROM_I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), true);

    //
    // Print a string.
    //
    UARTprintf("I2C running ...\n");
    ROM_SysCtlDelay(2000000);

    ...

  • Thank you for your help!

    I get the same error (#20 identifier "GPIO_PA1_U0TX" is undefined, etc...) if I use GPIOPinConfigure. 

  • What are you're include-path settings and file search paths? Also check the Predefined symbols!

  • Everything is like in your images. There is only one difference in the include path:

    And now, I get another error...

    I tried to add uartstdio.c to the project, but It didn't work. This is what i get when I add this file to the project:

    Here is the project with your code if you want to see it

    0216.Prueba.rar

  • For CCS V5.x

    From the main menu -- Your current project has a highlight (Bold)

    File --> New --> Folder

    Link to Alternate Location (Bottom Radio Button)

    Browse  --> To folder Containing the UARTSTDIO files etc.

    Click OK.

    Now a folder with a arrow pointing to the upper left will appear in your project pane.

    You need to add a folder as above, as well as the correct path.

    When you look at your project pane -- the left one. The "Includes" folder should clearly have a path from which the path to the utils directory makes sense.

    In my projects I move the specialized drivers to my project group folder and then add a path and a folder to there...

    The my include is something like this...

    #include "LocalDrivers/uartstdio.h"

    ...and, I have my folder link to that folder

  • I did everything but i still get this error

    Maybe I did something wrong but I don't know what...

    6253.Prueba2.rar

  • First: I can duplicate your error. Don't refernece back to "utils" -- it will try to build everything -- plus you may not have a proper reference set up in your Compiler includes.

    To fix this once and for all:

    Create yourself a directory at the same level as your project directory -- or just above it.

    I have a directory Called:

    C:\Stellarisware\boards\MyLaunchpadBoard\... project dirs ...

    Then I have:

    C:\Stellarisware\boards\MyLaunchpadBoard\MyLocalDrivers

    Into that directory I place the UART files and Display drivers and any other part of the Utils directory that I will be using...

    Then I create the Folder Reference to it...

    Then I make sure that I have something like...

    "${PROJECT_ROOT}/.."

    (Which is just one level up in this case...)

    in the Compiler include Options -- so that the compiler can "see" the MyLocalDrivers directory.

    Depending on where your"ccs" directory is you may have to do this...

    "${PROJECT_ROOT}/../.."

    You can tell when it is right by opening the "includes" folder in the left hand pane and seeing which directories the compiler can "see".

    Then you create the "Folder" to the MyLocalDrivers directory.

    Then you can delete the other folder back to "utils" -- when you right click on it in the left hand pane and choose "Delete" -- it just deletes the link.

    Hope that is clear.

    I find that I need the "Folder" reference -- and the "Compiler Includes" plus the include statement to have the proper reference in the main.c(pp).

    #include "LocalDrivers/ustdlib.h"
    #include "LocalDrivers/uartstdio.h"

    like above.

    So -- three things need to be correct... the compiler includes, the folder and the include statement.

    The folders will help you organize your work better as well. I put things like the utilities ioutside my project -- cause I did not write them....

    Note that you will get one last set of errors...

    In uartstdio -- you now have to change the include line for its own header.

    #include "uartstdio.h"

    The as you go forward doing other projects -- just refer to the "LocalDrivers" directory and all your stuff is packed in there. I put the LCD display drivers there and any other "third-party" source.

    It takes a few minutes -- you will "get it" :-)

  • Fixed some typos in the above -- sorry.

  • Thank you so much for your help ;-)

    I finnally fix it with your help and adding this code I found in a StellarisWare example

    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, unsigned long ulLine)
    {
    }
    #endif

    Thank you again!

  • De nada mi amigo. No hay problema.

    You're welcome! No problem -- just remember to help others when you can.

    De donde eres?

    The routine to help find the error does help from time to time. ;-)

  • I'm from Spain!

    I'll try to help the community :-D

  • I have tentative plans to visit Barcelona in early spring. I will wave hello as I pass over your hometown -- assuming it happens.