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.

[Request][TIVA][I2C] Please help in Initialising the I2C Master

Other Parts Discussed in Thread: LM3S2965, TM4C123GH6PZ, TM4C123GH6PGE

Hi 

I have a working Project using Stellaris, we have written the code the previous Year. But now we are porting to TIVA controller and I am not able to make I2C work

Previous Controller : LM3S2965

Present Controller : TM4C123GH6PZ

 

This is the code i am trying :

SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C5);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
I2CMasterIntEnable(I2C5_BASE);
GPIOPinTypeI2CSCL(I2C5_BASE, GPIO_PIN_6);
GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_7);
GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
I2CMasterInitExpClk(I2C5_BASE, SysCtlClockGet(), false);
IntEnable(INT_I2C5);

 I noticed many codes using these lines:

 ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
 ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);

But i get error that the GPIO_PB2_I2C0SCL (GPIO_PG6_I2C5SCL in my case) does not exist.

Also I there is no 'GPIO_PIN_TYPE_OD_WPU' available, instead there is 'GPIO_PIN_TYPE_OD' or  'GPIO_PIN_TYPE_STD_WPU'

i have been trying from 2 days but i couldnt make it to work. 

Please help me.

  • Can I use this ?

    GPIOPinConfigure(GPIO_PCTL_PG6_I2C5SCL);
    GPIOPinConfigure(GPIO_PCTL_PG7_I2C5SDA);

    Even with this the I2C doesnt work :( 

    I have no issues with the Stellaris, Here is the Stellaris code:

            // MASTER INIT
            SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enables a peripheral.
            SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); //Enables a peripheral .
            GPIOPinTypeI2C(GPIO_PORTB_BASE, I2C0_SCL | I2C0_SDA); //Configures pin(s) for use by the I2C peripheral
            I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false); //Initializes the I2C Master block
            I2CMasterIntEnable(I2C0_MASTER_BASE); //Enables the I2C Master interrupt.
            IntEnable(INT_I2C0);

    I basically am not seeing any signal on the SCL and SDA lines on the SCOPE. Also i noticed that I2C Interrupt is not getting triggered. So i am wondering its something to do with the init.

  • Hello Feroze,

    The correct sequence for GPIO Configuration would be

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

    and that for I2C-0 would be

    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
    I2CMasterIntEnable(I2C0_MASTER_BASE);

    IntEnable(INT_I2C0);

    The Pull Up has to be on the board as the device pull up is weak pull of ~30K. Just by enabling I2C the data transmission will not happen. there are examples in the TIVAWare for I2C that you can refer to for sending and recieving I2C frames along with posts on E2E forum.

    Also it is not clear which TIVA device you are using, so really can't tell why I2C5 is not working.

    Regards

    Amit

  • GPIO_PB2_I2C0SCL is not defined in the Header file.

    I2C0_MASTER_BASE is not defined, there is a definition for I2C0_BASE 

    My cntroller is : tm4c123gh6pz

    Errors :

    #20 identifier "GPIO_PB2_I2C0SCL" is undefined
    #20 identifier "GPIO_PB3_I2C0SDA" is undefined
    #20 identifier "I2C0_MASTER_BASE" is undefined 

     

  • Hello Feroze,

    Have you included the file driverlib/pin_map.h and also added the define for PART_TM4C123GH6PZ during compilation?

    I have checked the TM4C123GH6PZ and the define exists in the file and is required in the compilation flow.

    Regards

    Amit

  • Hi Amit,

    THank you for quick response,

    Yes i have both headers included.

    I have included the following :

    #include <assert.h>
    #include "inc/tm4c123gh6pge.h"
    #include "stdbool.h"
    #include "stdint.h"
    //#include "inc/lm4f232h5qd.h"
    //#include "inc/hw_timer.h"
    #include "inc/hw_types.h"
    //#include "inc/hw_ints.h"
    #include "driverlib/timer.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    #include "string.h"

    I am having Development Board with "tm4c123gh6pge" controller, while my Proto Type is having "TM4C123GH6PZ ", and i didnt find the definitions in the Headers.

    I am using Tivaware 2.xxx

  • Hello Feroze,

    The define is there in the file driverlib/pin_map.h

    What I meant about the define PART_TM4C123GH6PZ is to be added in the compilation flow. You will have to use Configuration manager of the project in CCS to add the define for compiling.

    Regards

    Amit

  • Can you please guide me where to define the part  ?

  • Hello Feroze

    If you are using CCS then

    Right Click your project, Select "Show Build Settings".

    In the pop-up

    Build->ARM Compiler->Advanced Options->Predefined Symbols

    In the section for Pre-define, press the add button and Type in the define I have already mentioned.

    Save it and compile your project.

    Regards

    Amit

  • WOW :)

    Thank you very much.

    And 'I2C0_MASTER_BASE' is not identified so i replaced with 'I2C0_BASE'

  • Hello Feroze,

    You can always load one of the example project in TIVAWare and check the settings against any custom project.

    Regards

    Amit

  • Finally i can see the Clock Signals.

    Thank you Amit.

  • Dear Amit,

    i have one more doubt, i can see Clock and Data on the scope but they dont look proper.

    They are not perfect Square, Clock looks like RAMP signal. I thought its some hardware issue, but i checked by writing a GPIO BLINK code on the same pins and they worked fine for the same frequency.

    Is there any configuration problem ?

    Here is my working Init Code :

        	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
        	GPIOPinConfigure(GPIO_PG2_I2C4SCL);
        	GPIOPinConfigure(GPIO_PG3_I2C4SDA);
        	GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_2); // SCL
        	GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_3);
    
        	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C4);
        	I2CMasterInitExpClk(I2C4_BASE, SysCtlClockGet(), false);
        	GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);//GPIO_PIN_TYPE_STD_WPU
    
        	I2CMasterIntEnable(I2C4_BASE);
        	IntEnable(INT_I2C4);
        	//---------------------------------

  • Hello Feroze,

    Please refer to I2C Protocol Specification. This kind of eave is very typical of Open Drain Protocol.

    Regards

    Amit