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.

TM4C123GH6PM: Interface Tiva C to BQ78350R1 using SMbus over I2C

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: EV2400, BQSTUDIO, EK-TM4C123GXL, BQ78350

Hello, 

I want to create an application to read the battery measurements from BQ78350R1 using a Tiva tm4c123 Launchpad board (before porting to my custom board). 

I do see that there is an smbus.c/.h files in TivaWare, but that's doesn't give any clues to how to interface with the BQ chip. 

There seems to be no resource on how to setup the SMBus interface to this BQ78350R1 chip, only references are to using BQStudio and the EV2400 device from TI. 

Anyone knows where/how to find a solution to this?

Thanks in advance. 

  • Hello Nabeel,

    Did you check the document SW-TM4C-UTILS-UG-2.1.3.156.pdf for the example code for SMBus module files?
  • Hello Amit,

    Yes I did see that -- it just shows all the function API available, and how to setup the Master or Slave interrupt for SMBus. No other details - especially I need some direction on how to interface with BQ78350R1

    Nabeel
  • It would be more clear if you'd indicate if its the (hardware) interface you seek...

    It is hard to imagine that you're challenged by connecting to SMBus (version) of: SDA & SCL - that's what (I believe) requires your explanation...

  • Hello Nabeel

    I would need to clarify one item: Considering the number of devices present on buses like I2C, SPI and UART, it is not seen so far to have an exhaustive and complete library for a MCU or class of MCU.
    The documentation provides for guidance, in terms of API and that the user along with the device data sheet should implement the application. Now if the TM4C micro does not work at all for SMBus (and it works well) then that is where we can help (provided we have equivalent setup).
  • Hello Amit,

    Yes I recognize that - the utils library, and documentation of it is complete and provides great direction.

    My question is more on the BQ78350R1 chip side - but I do have a bit of code I put together after reading through SMBus documentation of both TI and of NXP - and technical reference of the BQ chip. It seems rather simple using slave address, command byte, and read block to read back battery info.

    I will test that and see if i works -- if not then I'll return for help. Regardless I'll post the code here after testing.
  • Hi Amit,

    Firm/I continue to believe that poster's use of "interface" proves vague/imprecise.

    If it's detailed code functionality - as you (now) seem to suggest - such can be (far) better described via, "Software functional detail" as opposed to poster's "interface."
  • the "inteface" is SMBus -- but how exactly to set it up specifically for BQ78350R1 is the question - the "software functional detail"
  • Hello Nabeel,

    It is a question for the BQ78350R1 forum and not for TM4C.
  • That's the LEAST Satisfying "Verified Answer" since (another Self-Verified) by one void obsessed...
    What has been answered? How can one learn/benefit?
  • take a chill pill brother...

    Here's the code I have --- it still reads back 0s from the BQ - I also asked the question in Battery Gauge forums ... can you or Amir (or anyone) see anything I'm missing?

    //*****************************************************************************
    //
    // 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().
    //
    //*****************************************************************************
    // not shown to save space.

    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;
    }
    }
    }
    //*****************************************************************************
    //
    // MAIN
    //
    //*****************************************************************************
    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);

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

    SysCtlDelay(8000000); //half second
    }
    }
    //EOF
  • Hello Nabeel,

    Can you check if the BQ78350 device has a RO register like device ID and check what transaction is being seen on the bus?
  • Hello Amit,

    I have posted my SMBus code below in forum based on the only example provided in the utils document.

    The code still does nothing, reads all 0s. in fact, checking the clock signal on the SCL pin shows nothing on oscilloscope or protocol analyzer.

    I have sucessfully used I2C before with sensors and etc. but SMBus is not working at all.

    Please help as this is for product development.

    Thanks,
    Nabeel
  • Hello Nabeel

    It would seem to be something basic being missed out here. Can you check the SCL and SDA before any transaction is performed; i.e. are the SCL and SDA high? When the first transaction is performed, make sure that the scope trigger is kept on the correct signal and at half voltage (1.65V) and is kept in Normal mode (instead of auto-run)! Do paste what you see and capture in both cases.