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: SMBus

Part Number: TM4C123GH6PM

I am trying to use SMBus over I2C in tm4c123gh6pm. I use the example code as they given in utils user guide. But every time I call any function to read or write from slave i2c bus hang. Does anyone have any example code to read or write form SMBus slave. Please help me.

Thanks & Regards,

Aman. 

  • Can you be more specific as to where in the code the software hangs? It would also be very helpful if you can trace the I2C SCL and SDA lines with an oscilloscope or logic analyzer.
  • Dear Mr. Crosby,

    Thanks for the reply. This is my code to for initialize and read.

    void SMBusInitonI2C(void) {


    //
    // Enable the peripherals for the SMBus master.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    //
    // Configure the required pins for I2C0.
    //
    while(!SysCtlPeripheralReady(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);
    //
    // Configure the IO mux so that the I2C pins for I2C0 are on PB2/3.
    //

    //
    // Initialize the master SMBus port.
    //
    SMBusMasterInit(&g_sMaster, I2C0_BASE, SysCtlClockGet());

    I2CIntRegister(GPIO_PORTB_BASE,&SMBusMasterIntHandler);
    // Enable master interrupts.
    //
    SMBusMasterIntEnable(&g_sMaster);
    I2CMasterEnable(I2C0_BASE);
    IntMasterEnable();

    }

    U8_t readFromSlave(U8_t device_address, U8_t device_register) {

    int i;

    SMBusPECEnable(&g_sMaster);

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

    for(i=0; i<2; i++) {

    UARTprintf("%d \r\n",g_pucSlaveRxBuffer[i]);

    }

    return 0;

    }

    When i call readFromSlave(slave_addr,RegVal) it prints 0 and uC stops all operation.

    Regards,

    Aman.

  • The 0 returned from SMBusMasterByteWordRead is the status that the command has been started. A status of 0 is "SMBUS_OK". You need to poll to wait for the read to complete by calling SMBusStatusGet() until it returns "SMBUS_TRANSFER_COMPLETE", then read the data from your buffer.
  • Dear Bob,

    I tried this too. I think their is few problem in initialization. After calling SMBusMasterByteWordRead() uC stops all other functions. like got stuck some where and Wachdog reset it.

    Regards,
    Aman.
  • In the first post you said it "prints 0". In the next post you tell me it hangs. I am confused. Where does the code hang? Please step through the code and tell me specifically where it hangs.

    Please describe your hardware. What SMBus slave device is connected? Does it use ARP or a fixed slave address? Have you put a scope or logic analyzer on the I2C bus lines as I requested in my first post?
  • Perhaps this example will be helpful.

    /cfs-file/__key/communityserver-discussions-components-files/908/SMBus.zip

    // Simple SMBus example. This example uses two EK-TM4C123GXL launchpads. I2C0
    // and pins PB2 and PB3 are used on both launchpads. These pins must be tied
    // connected between the two launchpads and they must have a common ground.
    // Both pins (SDA and SCL) must have external pullup resistors.
    //
    // The master sends out a ByteWord read command requesting a single byte. The
    // slave responds with a single byte that increments with each request.
    

    Here is a logic analyzer shot of the first 3 I2C bus transactions.

  • Thank you So much Bob. You just made my day....

    Regards,
    Aman..