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.

CCS: TM4C1294NCPDTI3 I2C does not work

Other Parts Discussed in Thread: EK-TM4C1294XL

Tool/software: Code Composer Studio

ody

Hello.

I am trying to run i2c on TM4C1294 Connected LaunchPad Evaluation Board (EK-TM4C1294XL), but I2C0SCL clock does not occur.

I am measuring the waveforms of PB2 and PB3 with an oscilloscope, but no clock is generated.

Do you know why it doesn't work.

Board : TM4C1294 Connected LaunchPad Evaluation Board (EK-TM4C1294XL) (TM4C1294NCPDTI3)
Development environment : Code Composer Studio v6.1.0
Connection : Texas Instruments XDS2xx USB Debug Probe

The program is as follows


  • Hi,

      Glancing your code looks fine to me. I think you probably miss the pullup resistors on the SCL and SDA buses. Can you please check?

  • hello ,

             U can debug for the issue using uart  terminal and print those values and take a look at those pull up resistor cheers mate.

  • Thank you for your answer.

    It supplies 5V to SCL and SDA and has pull-up resistors.

    However, SCL and SDA output near 0V.
    Is the program wrong?
  • I'm running pretty much the same code as you and I can see the SCL and the slave address put on the bus. Although not related to your problem, I think you SLAVE_ADDRESS is probably wrong. Please note that the SLAVE_ADDRESS is a '7-bit' address, not including the R/W bit. You put 0x90 as your SLAVE_ADDRESS. After left shift by 1 the MSB is chopped off. You need to verify your slave address. Other than that, I can see the SCL and SCA. I have them pulled up to 3.3V via a pullup resistors. The MCU is 3.3V device, not 5V. So you want to check your hardware too. Run my below code again. If you still don't see anything on the scope you need to check your hardware.

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_i2c.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "driverlib/i2c.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    //*****************************************************************************
    //
    //! \addtogroup i2c_examples_list
    //! <h1>I2C Master Loopback (i2c_master_slave_loopback)</h1>
    //!
    //! This example shows how to configure the I2C0 module for loopback mode.
    //! This includes setting up the master and slave module.  Loopback mode
    //! internally connects the master and slave data and clock lines together.
    //! The address of the slave module is set in order to read data from the
    //! master.  Then the data is checked to make sure the received data matches
    //! the data that was transmitted.  This example uses a polling method for
    //! sending and receiving data.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - I2C0 peripheral
    //! - GPIO Port B peripheral (for I2C0 pins)
    //! - I2C0SCL - PB2
    //! - I2C0SDA - PB3
    //!
    //! The following UART signals are configured only for displaying console
    //! messages for this example.  These are not required for operation of I2C.
    //! - UART0 peripheral
    //! - GPIO Port A peripheral (for UART0 pins)
    //! - UART0RX - PA0
    //! - UART0TX - PA1
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - None.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // Number of I2C data packets to send.
    //
    //*****************************************************************************
    #define NUM_I2C_DATA 10
    
    //*****************************************************************************
    //
    // Set the address for slave module. This is a 7-bit address sent in the
    // following format:
    //                      [A6:A5:A4:A3:A2:A1:A0:RS]
    //
    // A zero in the "RS" position of the first byte means that the master
    // transmits (sends) data to the selected slave, and a one in this position
    // means that the master receives data from the slave.
    //
    //*****************************************************************************
    #define SLAVE_ADDRESS 0x90
    
    
    
    //*****************************************************************************
    //
    // Configure the I2C0 master and slave and connect them using loopback mode.
    //
    //*****************************************************************************
    int
    main(void)
    {
    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
        defined(TARGET_IS_TM4C129_RA2)
        uint32_t ui32SysClock;
    #endif
        uint32_t pui32DataTx[NUM_I2C_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.
        //
    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
        defined(TARGET_IS_TM4C129_RA2)
        ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN |
                                           SYSCTL_USE_OSC), 25000000);
    #else
        SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    #endif
    
        //
        // The I2C0 peripheral must be enabled before use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    
        //
        // 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_GPIOB);
    
        //
        // 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);
    
        //
        // 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.
        //
        GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
        GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
    
    //    HWREG(I2C0_BASE + I2C_O_MCR) = |= 0x10;
        I2CMasterEnable(I2C0_BASE);
    
        //
        // 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.
        //
    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
        defined(TARGET_IS_TM4C129_RA2)
        I2CMasterInitExpClk(I2C0_BASE, ui32SysClock, false);
    #else
        I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
    #endif
    
    
        //
        // 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.
        //
        I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);
    
        //
        // Initalize the data to send.
        //
        pui32DataTx[0] = 0xFF;
    
       //
    	// Place the data to be sent in the data register
    	//
    	I2CMasterDataPut(I2C0_BASE, pui32DataTx[0]);
    
    
    	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
    
        //
        // Return no errors
        //
        while(1);