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 on dk-tm4c129x is not working

Other Parts Discussed in Thread: TMP100

Hello,

I'm using TI's EVM for TIVA: TM4C129X

The  board contains TI's TMP 100 which is an I2C Temp. sensor.

Based on the master_slave_loopback.c code example I coded the attached file.

But it seems the TMP100 is not sending a reply.

Also. upon init compltion, the clock of the SCL should be set to '0'  but it remains '1'

Can you help ?

int main(void)
{
    //
    // 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 I2C6 peripheral must be enabled before use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);

    //
    // For this example I2C6 is used with PortB[7:6].  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 I2C6 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_PB6_I2C6SCL);
    GPIOPinConfigure(GPIO_PB7_I2C6SDA);

    //
    // 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_6 | GPIO_PIN_7);

    //
    // Enable and initialize the I2C6 master module.  Use the system clock for
    // the I2C6 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(I2C6_BASE, SysCtlClockGet(), false);

    //
    // Place the data to be sent in the data register
    //
    I2CMasterDataPut(I2C6_BASE, 0x00);

        
    I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_SINGLE_SEND);
    
    while (1);
}

Thanks,

Zvika

  • Hi,

    Did you mounted the jumpers J18 and J20? see page 15 of spmu360.pdf (user manual of the board, schematics. Take care to avoid any possible hardware conflict.

    Petrei

  • Zvi Vered said:
    Also. upon init compltion, the clock of the SCL should be set to '0'  but it remains '1'

     Hi try look at this code generated from Tiva Pin mux, seems SCL need special configuration clause.

    //*****************************************************************************
    // Copyright (c) 2013 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    //
    //   Redistribution and use in source and binary forms, with or without
    //   modification, are permitted provided that the following conditions
    //   are met:
    //
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    //
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the  
    //   distribution.
    //
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    //
    // This file was automatically generated by the Tiva C Series PinMux Utility
    // Version: 1.0.3
    //
    //*****************************************************************************

    #include <stdint.h>
    #include <stdbool.h>
    #include "i2c6.h"
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/gpio.h"

    //*****************************************************************************
    void
    PortFunctionInit(void)
    {
        //
        // Enable Peripheral Clocks
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

        //
        // Enable pin PB7 for I2C6 I2C6SDA
        //
        GPIOPinConfigure(GPIO_PB7_I2C6SDA);
        GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_7);

        //
        // Enable pin PB6 for I2C6 I2C6SCL
        //
        GPIOPinConfigure(GPIO_PB6_I2C6SCL);
        GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_6);
    }

  • Hi Zvi,

    Looked at the code and I see the following things missing

    1. The Master Function is not enabled. This has to be done after the I2CMasterInitExpClk

    I2CMasterEnable(I2C6_BASE);

    2. The Slave Address is not set int for the Address Phase of the I2C frame. This has to be done after step-1

    //

    // true in the 3 parameter if the R/W of the address Phase is recieve

    // false in the 3 parameter if the R/W of the address Phase is transmit

    //

    I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true);

    Amit

  • Dear Members,

    Your help is highly appreciated !

    The first line in the loopback code is:

    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    Should I change it to:

    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_25MHZ)   ?

    In  other samples the first line is:

    g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                             SYSCTL_OSC_MAIN |
                                             SYSCTL_USE_PLL |
                                             SYSCTL_CFG_VCO_480), 120000000);

    What is the difference between SysCtlClockFreqSet and  SysCtlClockSet ?

    Thanks,

    Zvika

  • Hi Zvika

    SysCtlClockFreqSet is the new TIVA function to set the system clock frequency while SysCtlClockSet is the older form. The first one is more flexible.

    Secondly the SYSCTL_XTAL_16MHZ or SYSCTL_XTAL_25MHZ depends on whether you have a 16MHz or a 25MHz External Crystal on the board. You have to select the correct parameter based what the External Crystal Frequency is.

    Amit