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.

CCS/TMS320F280041: 280041 I2C Configuration

Part Number: TMS320F280041
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

Hello,

If i want to use 280041 controller as slave receiver mode continuously then,

how to trigger i2c interrupt and how initialize I2c for this configuration.

Please suggest any example because in library it has only EPROM example.

Regards,

Bharat

   

  • Bharat,

    As of now the only example we have are I2C EEPROM and I2C boot code available in C2000Ware. Both of them are configured as I2C master mode. We unfortunately don't have an example for I2C slave receive mode. If I were you, I would start with I2C boot.c available in C2000Ware in below path.

    C2000Ware path: <C2000Ware>\libraries\boot_rom\f28004x\revB\rom_sources\F28004x_ROM\bootROM\source\

    File path: I2C_Boot.c

    In order for you configure I2C slave receiver, you need to clear I2CMDR.MST = 0 (configured as slave) and I2CMDR.TRX = 0 (configured as receiver)

    If you aren't using I2C FIFO, you need to enable I2C interrupt (RRDYINT) when I2C receive ready condition. Enable by setting the I2CIER.RRDY = 1

    If you are using I2C FIFO, you need to enable I2C FIFO interrupt (Receive FIFO interrupt). Enable by setting I2CFFRX.RXFFIENA = 1 and appropriately setting I2CFFRX.RXFFIL

    Regards,

    Manoj

  • Hello,

    I am using I2C receive FIFO ISR for receiving data.

    Master (MSP430) Transmitting 8 byte data on every 4ms time. Now the problem is some time randomly  the data of buffer inter changed with each other. Means first buffer data comes in 4 th buffer then continuous. 

    My Code is as per below.

    interrupt void I2CA_FIFO_ISR(void)
    {
    // Insert ISR Code here
    uint16_t i;
    if((I2C_getInterruptStatus(I2CA_BASE) & I2C_INT_RXFF) != 0)
    {
    for(i = 0; i < 8; i++)
    {
    buf[i] = I2C_getData(I2CA_BASE);
    }

    I2C_clearInterruptStatus(I2CA_BASE, I2C_INT_RXFF);
    I2caRegs.I2CSTR.all=0;
    }

    //
    // To receive more interrupts from this PIE group,
    // acknowledge this interrupt.
    //
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;

    }

    Intit code

    //////////////////////////////////////////////////////////////////////////////////////////////
    I2C_disableModule(I2CA_BASE);
    I2caRegs.I2CMDR.bit.NACKMOD = 1;
    // I2C configuration. Use a 400kHz I2CCLK with a 50% duty cycle.

    I2C_initMaster(I2CA_BASE, DEVICE_SYSCLK_FREQ, 400000, I2C_DUTYCYCLE_50);
    I2C_setOwnSlaveAddress(I2CA_BASE, MY_ADDRESS);
    I2C_setConfig(I2CA_BASE, I2C_SLAVE_RECEIVE_MODE);
    I2C_setDataCount(I2CA_BASE, 8);
    I2C_setBitCount(I2CA_BASE, I2C_BITCOUNT_8);
    // I2C_setEmulationMode(I2CA_BASE, I2C_EMULATION_FREE_RUN);

    I2C_enableFIFO(I2CA_BASE);
    I2C_clearInterruptStatus(I2CA_BASE, I2C_INT_RXFF);
    I2C_setFIFOInterruptLevel(I2CA_BASE, I2C_FIFO_TX8, I2C_FIFO_RX8);
    I2C_enableInterrupt(I2CA_BASE, I2C_INT_RXFF);

    I2C_enableModule(I2CA_BASE);

    Please give any suggestion for that.

    Regards,

    Bharat

  • Bharat,

    I didn't see any glaring mistake from your code expect I don't understand why are clearing I2CSTR register and I would urge you to avoid using both driverlib and bitfield approach.

    Did you use I2C protocol analyzer to snoop the I2C bus and see MSP430 is transmitting the correct bytes? Also, make sure TXFFINT is not getting triggered and messing up I2C timing.

    Regards,

    Manoj

  • Hello,

    The problem is that  only some time receive buffer data interchange??

    Any other condition is required other then Receive buffer levels  interrupt trigger?????

    /*

    * Initialization.h

    *

    *  Created on: Apr 8, 2020

    *      Author: BHARAT_CHAUHAN

    */

    #ifndef INITIALIZATION_H_

    #define INITIALIZATION_H_

    //**************************Variable Initialization

    //**************************Constant Initialization***************************************************//

    #define TIMER_PERIOD                           16000  //for 1ms Timer = 16MHz/1kHz =16000

    #define SLAVE_ADDRESS                          0x48

    #define CS_XT1_CRYSTAL_FREQUENCY               32768

    #define CS_MCLK_DESIRED_FREQUENCY_IN_KHZ       16000

    #define CS_MCLK_FLLREF_RATIO                   487

    void Initialization();

    void Initialization()

    //***********************************I2C Initialization Code start*****************************************//

           //I2C Pin Configuration

           GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,GPIO_PIN2 + GPIO_PIN3,GPIO_PRIMARY_MODULE_FUNCTION);

           PMM_unlockLPM5();

           EUSCI_B_I2C_initMasterParam param1 = {0};

           param1.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;

           param1.i2cClk = CS_getSMCLK();

           param1.dataRate = EUSCI_B_I2C_SET_DATA_RATE_400KBPS;

           param1.byteCounterThreshold = 0;

           param1.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;

           EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param1);

           //Specify slave address

           EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE,SLAVE_ADDRESS);

           //Set Master in receive mode

           EUSCI_B_I2C_setMode(EUSCI_B0_BASE,EUSCI_B_I2C_TRANSMIT_MODE);

           //Enable I2C Module to start operations

           EUSCI_B_I2C_enable(EUSCI_B0_BASE);

           EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0 +EUSCI_B_I2C_NAK_INTERRUPT);

           //Enable master Receive interrupt

           EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT)

        //For

    #endif /* INITIALIZATION

  • Bharat,

    I2C FIFO interrupt can be triggered only by two events:

    TX FIFO ready event: When TXFFST <= TXFFIL

    RX FIFO data ready event: When RXFFST >=RXFFIL

    In your case, you need only RXFIFO data ready event to trigger I2C FIFO interrupt. So, make sure to disable TXFFIENA (I2CFFTX.TXFFIENA = 0). This will ensure TX FIFO ready event doesn't trigger any interrpt.

    I'm not familiar with MSP430 I2C. So, I can't help you much in that regard. But, the easiest way to debug this issue is to check the I2C bus using I2C protocol analyzer. This will tell whether MSP430 I2C is incorrectly swapping those bytes.

    Regards,

    Manoj

  • Hello Manoj

    For diagnose the problem i am defining the F280041 controller as Master but The Clock signal is not coming on SCL Pin.

    Code is as per below.

    void i2c_init(void)
    {
    //////////////////////////////////////////////////////////////////////////////////////////////
    I2C_disableModule(I2CA_BASE);

    // I2C configuration. Use a 400kHz I2CCLK with a 50% duty cycle.

    I2C_initMaster(I2CA_BASE, DEVICE_SYSCLK_FREQ, 400000, I2C_DUTYCYCLE_50);
    I2C_setSlaveAddress(I2CA_BASE, MY_ADDRESS);
    I2C_setConfig(I2CA_BASE, I2C_SLAVE_RECEIVE_MODE);
    I2C_setDataCount(I2CA_BASE, 8);
    I2C_setBitCount(I2CA_BASE, I2C_BITCOUNT_8);

    I2C_enableFIFO(I2CA_BASE);
    I2C_clearInterruptStatus(I2CA_BASE, I2C_INT_RXFF);
    I2C_setFIFOInterruptLevel(I2CA_BASE, I2C_FIFO_TX8, I2C_FIFO_RX8);
    I2C_enableInterrupt(I2CA_BASE, I2C_INT_RXFF);
    I2C_disableInterrupt(I2CA_BASE, I2C_INT_TXFF);

    I2C_enableModule(I2CA_BASE);

    }

    Please help for this

    Regards,

    Bharat

  • Bharat,

    You have configured your I2C in I2C_SLAVE_RECEIVE_MODE. When you configure I2C in slave mode, it doesn't generate clock.

    To generate clock you need to use either I2C_MASTER_SEND_MODE (or) I2C_MASTER_RECEIVE_MODE.

    Regards,

    Manoj

  • Hello Manoj

    Sorry i have attached wrong code 

    if i was configure I2C module as   I2C_MASTER_SEND_MODE (or) I2C_MASTER_RECEIVE_MODE. then after also clock is not generating.

    regards,

    Bharat

  • Bharat,

    I would recommend you to checkout I2C_Boot.c found in below C2000Ware path which provides an example for I2C configuration for master receiver mode.

    Path         : <C2000Ware>\libraries\boot_rom\f28004x\revB\rom_sources\F28004x_ROM\bootROM\source\

    Filename  : I2C_Boot.c

    Regards,

    Manoj

  • Hello Manoj,

    As per your suggestion i have tried that initialization but it is not working.

    i have initialize as master transmitter and master receiver both but clock is not generating. 

    I do not understand where i made a mistake.

    Regards,

    Bharat 

  • Bharat,

    Once I2C is configured (in master transmitter mode), you need to write to I2C data register (I2CDXR) to generate I2CCLK on SCL pin.

    Check whether your I2C pins is pulled high through pull-up resistor? Check whether you have configured I2C pins correctly in your software?

    Regards,

    Manoj

  • Is this issue resolved?

  • Hello manoj

    Thank you for your reply.

    But still i am facing problem i am try to figure out problem.

    Regards,

    Bharat

  • Hello Manoj,

    Finally Communication is success full between MSP430 as Master and F280041 as slave on I2C bus.

    Problem is resolved i have changed the code of I2C Interrupt as per below. 

    interrupt void I2CA_FIFO_ISR(void)
    {
    // Insert ISR Code here
    uint16_t i;
    if(((I2C_getInterruptStatus(I2CA_BASE) & I2C_INT_RXFF) != 0)/*&&(!I2caRegs.I2CSTR.bit.AAS)*/)
    {
    for(i = 0; i < 8; i++)
    {
    buf[i] = I2C_getData(I2CA_BASE);
    }
    flag.Data_Ok = 1;
    I2C_clearStatus(I2CA_BASE,I2C_STR_RSFULL);
    I2C_clearInterruptStatus(I2CA_BASE, I2C_INT_RXFF);
    I2C_disableModule(I2CA_BASE);
    I2C_setFIFOInterruptLevel(I2CA_BASE, I2C_FIFO_TX8, I2C_FIFO_RX8);
    I2C_enableModule(I2CA_BASE);
    }


    PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;

    }

    Regards,

    Bharat