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.

SMBus on TM4C1294NCPDT Tiva Evaluation board

Other Parts Discussed in Thread: TM4C1294NCPDT, BQ78350-R1, EK-TM4C123GXL

Hi,

I am trying to get SM Bus protocol up and running on the Tiva TM4C1294NCPDT evaluation board that is connected to bunch of I2C devices. Is there some sample code on how to go about doing it? Please share.

Thanks

--Rajeev

  • Hello Rajeev,

    The SMBus drivers are available in TivaWare utils folder. Did you try a search of the forum data base? I would be surprised if there is not an example code snippet.

    Regards

    Amit

  • Amit,

         Yes, I did find the drivers but have difficulty getting to use it. I did search the database to find a code snippet but did not find any. Please point me to one to a location where I can find it.

    Thanks

    --Rajeev

  • Hello Rajeev,

    OK. I may have to take back my words. The search is rather difficult if not "tegged". Do you have a starting code and also do have a look at the SW-TM4C-UTILS-UG-2.1.0.12573.pdf in the TivaWare Installation as it does attempt to describe what it needs to build a SMBus application.

    I can only help you if you have a base code to start with.

    Regards

    Amit

  • Amit,

          No I do not have the base code, please point me to it so that I can download. I took a look at the SM Bus stack in the UTILs user guide. The example code just show how to initialize but not the actual operation. It will be of immense help, if you can walk me through the sample code for basic read and write operations.

    Regards

    --Rajeev

  • Hello Rajeev,

    Unfortunately, you would need to make a start at the the code (forum members most welcome to provide your code), before we can help you debug and get it to 100% working condition. Also please note that SMBus is built on I2C Physical Protocol, so you can develop the code using I2C drivers for which there are plenty of examples.

    Regards

    Amit

  • I'll post my code here -- it is not reading from the SMBus slave device - a BQ78350-R1:

    //*****************************************************************************
    //
    // hello.c - Simple hello world example.
    //
    // Copyright (c) 2012-2014 Texas Instruments Incorporated. All rights reserved.
    // Software License Agreement
    //
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    //
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    //
    // This is part of revision 2.1.0.12573 of the EK-TM4C123GXL Firmware Package.
    //
    //*****************************************************************************

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/i2c.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    #include "smbus.h"

    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>Hello World (hello)</h1>
    //!
    //! A very simple ``hello world'' example. It simply displays ``Hello World!''
    //! on the UART and is a starting point for more complicated applications.
    //!
    //! UART0, connected to the Virtual Serial Port and running at
    //! 115,200, 8-N-1, is used to display messages from this application.
    //
    //*****************************************************************************

    // Slave address of SMBus device BQ78350R1 -verify!
    #define BQ78350R1_ADDR 0x17

    tSMBus g_sMaster;
    //tSMBus g_sSlave;

    #define MAX_SMB_BLOCK_SIZE 2 //32
    //unsigned char g_pucSlaveTxBuffer[MAX_SMB_BLOCK_SIZE] = {0};
    uint8_t g_pucSlaveRxBuffer[MAX_SMB_BLOCK_SIZE] = {0};


    // All the SMBus commands needed
    #define TEMPERATURE 0x08
    #define VOLTAGE 0x09
    #define CURRENT 0x0A
    // ...more

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

    //*****************************************************************************
    //
    // Configure the UART and its pins. This must be called before UARTprintf().
    //
    //*****************************************************************************
    void
    ConfigureUART(void)
    {
    //removed to save space in post
    }

    void SMBusInit(void)
    {
    //
    // Enable the peripherals for the SMBus master.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    //
    // Configure the required pins for I2C0.
    //
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
    //
    // Configure the IO mux so that the I2C pins for I2C0 are on PB2/3.
    //
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    //
    // Initialize the master SMBus port.
    //
    SMBusMasterInit(&g_sMaster, I2C0_BASE, SysCtlClockGet());

    //
    // Enable master interrupts.
    //
    SMBusMasterIntEnable(&g_sMaster);

    //
    // Enable interrupts to the processor.
    //
    IntMasterEnable();

    }

    void SMBusMasterIntHandler(void)
    {
    tSMBusStatus eStatus;
    //
    // Process the interrupt.
    //
    eStatus = SMBusMasterIntProcess(&g_sMaster);
    //
    // Check for errors.
    //
    switch(eStatus)
    {
    case SMBUS_PEC_ERROR:
    {
    //
    // Handle error.
    //
    break;
    }
    case SMBUS_TIMEOUT:
    {
    //
    // Handle error.
    //
    break;
    }
    case SMBUS_ADDR_ACK_ERROR:
    case SMBUS_DATA_ACK_ERROR:
    {
    //
    // Handle error.
    //
    break;
    }
    }
    }
    //*****************************************************************************
    //
    // Print "Hello World!" to the UART on the evaluation board.
    //
    //*****************************************************************************
    int
    main(void)
    {
    //volatile uint32_t ui32Loop;

    //
    // Enable lazy stacking for interrupt handlers. This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
    SYSCTL_OSC_MAIN);

    //
    // Initialize SMBus
    //
    SMBusInit();

    //
    // Initialize the UART.
    //
    ConfigureUART();

    //
    // Hello!
    //
    UARTprintf("SMBus Test \n");

    // Command byte
    uint8_t COMMAND = TEMPERATURE;
    //
    // We are finished. Hang around doing nothing.
    //
    while(1)
    {
    uint8_t returnStatus;

    switch(COMMAND)
    {
    case TEMPERATURE:
    COMMAND = VOLTAGE;
    break;
    case VOLTAGE:
    COMMAND = CURRENT;
    break;
    case CURRENT:
    COMMAND = TEMPERATURE;
    break;
    default:
    break;
    }

    SMBusPECEnable(&g_sMaster);
    //SMBusMasterBlockRead(&g_sMaster, BQ78350R1_ADDR, COMMAND, g_pucSlaveRxBuffer);

    returnStatus = SMBusMasterByteWordRead(&g_sMaster, BQ78350R1_ADDR, COMMAND, g_pucSlaveRxBuffer, 2);
    UARTprintf("Status: %d \r\n",returnStatus);

    while(SMBusStatusGet(&g_sMaster)== SMBUS_TRANSFER_IN_PROGRESS)
    {/*WAIT*/};

    int i;
    for(i=0; i<2; i++){
    UARTprintf("%d \r\n",g_pucSlaveRxBuffer[i]);
    }

    SysCtlDelay(8000000); //half second
    }
    }
    //EOF
  • While "nice" that you've posted "non-reading" code - had you noted that requesting poster was last seen/heard 2 years, 3 months past?
  • Yes I had noted it like you have. It's not for poster but anyone (like me) visiting this post in the future. And hopefully someone can suggest a fix for my code, or find it useful in any way.

    Any other problems for you cb1?

  • Perhaps your (bit) more direct request for assistance proves better?  You've hitched your wagon to a (very) old/tired horse (post) - my response was aimed at your "comfort/awareness" - and instead of "thanks" - receives attack.

    I do hope that you succeed & resolve your problem - and I'd bet that my suggestion (fresh, new post - clearly & directly voicing your request) will trump the (reanimated) "resurrection special" - pulled from the forum graveyard...