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.

tiva used as i2c in slave mode

Hello,

i want to used i2c in slave mode and raspberry pi as master. I write a code for this but it is not working. any one knows whats the mistake in this.

#include "inc/hw_memmap.h"

/* Defines the common types and macros */
#include "inc/hw_types.h"

/* Defines and Macros for GPIO API */
#include "driverlib/gpio.h"

/* Prototypes for the system control driver */
#include "driverlib/sysctl.h"

#include "driverlib/adc.h"

#include "driverlib/uart.h"

#include "driverlib/interrupt.h"

#include "utils/uartstdio.h"

#include "inc/hw_i2c.h"
#include "driverlib/i2c.h"
#define SLAVE_ADDRESS 0x04
void
InitConsole(void)
{

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);

/* Make the UART pins be peripheral controlled. */
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART for console I/O.
//
UARTStdioInit(0);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

}

int main(void)
{
//unsigned long temp[8];
/*Set the clocking to run at 80Mhz from the crystal of 16MHz using PLL*/
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);


I2CSlaveEnable(I2C0_SLAVE_BASE);

I2CSlaveInit(I2C0_SLAVE_BASE, SLAVE_ADDRESS);
while(1){
I2CSlaveDataPut(I2C0_SLAVE_BASE,'q');
}
}

  • My initial comment is that I don't see where the InitConsole() function is called to setup the UART and I2C interface signals.

    --Bobby

  • Hello,

    i reconfigure my code but still not working.

    tell me the reason 

    #include "inc/hw_memmap.h"

    /* Defines the common types and macros */
    #include "inc/hw_types.h"

    /* Defines and Macros for GPIO API */
    #include "driverlib/gpio.h"

    /* Prototypes for the system control driver */
    #include "driverlib/sysctl.h"

    #include "driverlib/adc.h"

    #include "driverlib/uart.h"

    #include "driverlib/interrupt.h"

    #include "utils/uartstdio.h"

    #include "inc/hw_i2c.h"
    #include "driverlib/i2c.h"
    #define SLAVE_ADDRESS 0x3B
    void
    InitConsole(void)
    {

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

    /* Make the UART pins be peripheral controlled. */
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    //
    // Initialize the UART for console I/O.
    //
    UARTStdioInit(0);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    }

    int main(void)
    {

    /*Set the clocking to run at 80Mhz from the crystal of 16MHz using PLL*/
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    I2CSlaveIntEnable(I2C0_SLAVE_BASE);
    InitConsole();
    I2CSlaveEnable(I2C0_SLAVE_BASE);
    I2CSlaveInit(I2C0_SLAVE_BASE, 0x3B);


    I2CSlaveDataPut(I2C0_SLAVE_BASE,'q');

    }

    reply

  • Hello Payal,

    Which TIVAWare version are you using since in 2.0.1.11577 release I2C0_SLAVE_BASE is not defined.

    Secondly, can you read the I2C0 register through the debugger and cross check it against the Register Specification in the data sheet to check if the Slave Module is enabled correctly.

    Regards

    Amit

  • i dont know tivaware version.

    how can read i2c0 regster ?

    when i used "I2CSlaveDataPut(I2C0_SLAVE_BASE,'q');" instruction it write q in i2c register. it is put q in data bus or reg?

    and i interface tiva with raspberry pi using i2c.

  • Hello Payal,

    You can open the inc/hw_i2c.h file (as an example) and within the first 40 lines there should be a comment like

    // This is part of revision 2.0.1.11577 of the Tiva Firmware Development Package.
    This can be used to inform the version of TivaWare

    Do you have a debugger connected to the TIVA device? When you call the I2CSlaveDataPut it would write to the Register. However my contention is on the I2C0_SLAVE_BASE define. Can you check what the define value is and when you use the I2CSlaveDataPut what address does it correspond to.

    Regards

    Amit

  • This is part of revision 8555 of the Stellaris Firmware Development Package.

    in hw_i2c i found this.

    would u tell me what i do now?

    no i have only tiva launchpad .

  • Hello Payal,

    Can you please remove the following line from your code

    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    Also, can you put a scope probe or a LA probe and see if the Master is sending a I2C Transaction. if yes, then please do attach the waveform.

    Regards

    Amit