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.

MCF8316AEVM: I2C Register MAP

Part Number: MCF8316AEVM
Other Parts Discussed in Thread: MCF8316A, MSP-EXP430FR2355

Hi,

I am MCF8316AEVM development board for motor driver control. I have question regarding the i2c register and reading and writing method of the i2c. As I know If EVM Support standard protocol of I2C, So don't have much Question regarding this but still i am looking for the register map document which will help me to understand, how motor driver operate through the I2C.

Well I am planning to use external MCU in my final layer of PCB, So it will talk with MCF8316AEVM through the I2C, So that means MCF8316AEVM will be preloaded once and later i am controlling through the external Host MCU using i2c.

Question. 

How can we read and write MCF8316AEVM through the I2C.

Could please provide some information related to I2C Register Map or datasheet something.

  • Hi Ketan,

    Thanks for your question on the Motor Drives E2E Forum. 

    I will aim to provide an answer on this by the end of the week!

    Best,

    Robert

  • Hi,

    Thank you for your reply.

    Sure No Problem .

  • Hi Ketan,

    For general information about getting started with our EVM, I suggest you read into and look over the MCF8316AEVM (Evaluation Module) User's Guide to get started spinning your motor. (https://www.ti.com/lit/ug/sllu338/sllu338.pdf)

    Our EVM lets you control the various inputs of the featured microcontroller using our EVM GUI (https://dev.ti.com/gallery/view/BLDC/MCF8316A_GUI/ver/1.1.8/). Using this GUI will allow you to read and write to the MCF8316AEVM and configure all of your desired settings.

    To find more information about the Register Map and various configurations available for this device, please look at the MCF8316A datasheet found of this product page: https://www.ti.com/product/MCF8316A

    I hope this answers your question. If it does, please help by marking this thread as resolved!

    Best,

    Robert

  • Hi, 

    Noted. I'll go through the document for I2C register map.

    Regarding the I2C. I am trying some i2c example to read the device information from i2c base sensor but looks like i am not able to read the i2c data.

    I am using MSP430RF2355 development board and I have a connected external I2C Sensor with P1.3 and P1.2 pin for SCLK and SDA line. I have a set the slave address in I2C register for the master communication. See Initialization part.

    Question: 

    Polling transmit flag is required after the start the condition ? still slave address not loaded into the tx buffer ?

     //Poll for transmit interrupt flag.
        while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG) && --timeout) {
            ;
        }
    

    void msd_i2c_initialization(void) {
    
        //SDA line
        GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION);
        //clock line
        GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1, GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    
        EUSCI_B_I2C_initMasterParam i2c_master_init_param = { 0 };
        i2c_master_init_param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;      //use SMCLK clock signal
        i2c_master_init_param.i2cClk = CS_getSMCLK();                         //Give SMCLK freq in Hz
        i2c_master_init_param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_400KBPS;   //400KBps datarate
        i2c_master_init_param.byteCounterThreshold = 0;                       //Don't care because 'no auto stop'
        i2c_master_init_param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;            //We will handle the stop bit manually
        EUSCI_B_I2C_initMaster( EUSCI_B0_BASE, &i2c_master_init_param);
        EUSCI_B_I2C_enable(EUSCI_B0_BASE);  //Enable the I2C bus (i.e. pull it out of reset state)
        EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, I2C_SLAVE_ADDRESS);
    }
    
    static bool start_transfer(uint16_t baseAddress) {
    
        bool success = false;
        uint8_t timeout = 40;
    
        //Send start condition.
        HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTR + UCTXSTT;
    
        //wait for master send the slave address
        //Poll for transmit interrupt flag.
        while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG) && --timeout) {
            ;
        }
    
        //Check if transfer timed out
        if (timeout == 0) {
            MSP_LOG("start_transfer() TIMEOUT");
            return success;
        }
        success = true;
        return success;
    }
    
    static bool restart_transfer(uint16_t baseAddress) {
    
        bool success = false;
        uint8_t timeout = 40;
    
        //wait here
        delay_ms(40);
    
        //Set USCI in Receive mode
        HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~UCTR;
    
        //Send start
        HWREG16(baseAddress + OFS_UCBxCTLW0) |= (UCTXSTT + UCTXSTP);
    
        //Poll for receive interrupt flag.
        while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCRXIFG) && --timeout) {
            ;
        }
    
        if (timeout == 0) {
            MSP_LOG("restart_transfer() TIMEOUT");
            return success;
        }
        success = true;
        return success;
    }
    static void stop_transfer() {
        EUSCI_B_I2C_masterReceiveMultiByteStop(EUSCI_B0_BASE);
    }
    static bool write_reg(uint16_t baseAddress, uint8_t *data, uint8_t len) {
        //start the transmission now
        //MSP430 send slave address once start bit occur
        bool success = start_transfer(baseAddress);
        if (!success) {
            return 0;
        }
    
        //send the data to be sent
        uint8_t i = 0;
        for (i = 0; i < len; i++) {
            EUSCI_B_I2C_slavePutData(baseAddress, data[i]);
        }
    
        //stop the transmission
        stop_transfer();
    
        return success;
    }
    static bool read_reg(uint16_t baseAddress, uint8_t *data, uint8_t len) {
    
        //start the communication
        //restart with received mode
        bool success = restart_transfer(baseAddress);
        if (!success) {
            return 0;
        }
        //start reading now.
        uint8_t i = 0;
        for (i = 0; i < len; i++) {
            *data++ = EUSCI_B_I2C_slaveGetData(baseAddress);
        }
    
        //stop the transmission
        stop_transfer();
        return success;
    }

  • Hi Ketan,

    Are you trying to bypass the MSP430RF2355 that is already on the MCF8316AEVM by depopulating the SCL and SDA jumpers and hooking up the MSP-EXP430FR2355 LaunchPad directly to the MCF8316A?

    If so, you can use the CCS project here as a starting point:

    8867.HardwareI2C_MSP430FR2355_MCF8316AEVM.zip

    If you have more questions specifically about I2C communication, you may want to direct those questions to our MSP team to help with debug.

    Best,

    Robert

  • Hi,

    Thank you for you reply.

    Yes i am bypassing the existing MSP430RF2355. 

    I think I got the answer here. MCF8316AEVM  device slave will be 0x01 always by default ?

  • Hi,

    After drill down you example code.I have question regarding the I2C Read method. 

    As per data sheet of MCF8316AEVM, It's accepting 4 byte of control word for reading and writing.

    As per the example code, It sending 4 byte of control word and reading data from the register. Firstly configuring into the transmission mode for the write control word with automatic stop condition through the @byteCounterThreshold but what about the reading case, at end of the reading not using stop condition for end transmission, So that mean @byteCounterThreshold count will generate the stop condition again at end ot reading ?

    As per my understanding, @byteCounterThreshold will generate stop condition once writing count reach to the @byteCounterThreshold count which is already reached while sending the control word so it's not necessary now to generate the stop condition once it's received. ?

    bool I2C_read32(unsigned long addr, unsigned long *result, uint32_t timeout) {
        // Temp variables
        uint8_t val;
        unsigned long r = 0;
    
        EUSCI_B_I2C_initMasterParam param = {0};
        param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
        param.i2cClk = CS_getSMCLK();
        param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_400KBPS;
        param.byteCounterThreshold = 4;
        param.autoSTOPGeneration = EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD;
        EUSCI_B_I2C_initMaster(EUSCI_I2C_BASE, &param);
    
        //Enable I2C Module to start operations
        EUSCI_B_I2C_enable(EUSCI_I2C_BASE);
    
        // Construct the 24 bit control word (refer to datasheet section 7.6.2.1)
        char control_word[3] = {0x90, 0x00, addr&0xFF};
    
        /* Set slave Address */
        EUSCI_B_I2C_setSlaveAddress(EUSCI_I2C_BASE,
                    SLAVE_ADDR
                );
    
        /* Set master to transmit mode */
        EUSCI_B_I2C_setMode(EUSCI_I2C_BASE,
            EUSCI_B_I2C_TRANSMIT_MODE);
    
        EUSCI_B_I2C_masterSendStart(EUSCI_I2C_BASE);
    
        __delay_cycles(INTER_BYTE_DELAY);
    
        /* Send bits CW23-CW16 of the control word */
        if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_I2C_BASE, control_word[0], timeout))
            return 0;
    
        __delay_cycles(INTER_BYTE_DELAY);
    
        /* Send bits CW15-CW8 of the control word */
        if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_I2C_BASE, control_word[1], timeout))
            return 0;
    
        __delay_cycles(INTER_BYTE_DELAY);
    
        /* Send bits CW7-CW0 of the control word */
        if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_I2C_BASE, control_word[2], timeout))
            return 0;
    
        __delay_cycles(INTER_BYTE_DELAY);
    
        /*
         * Set master to receive mode and generate Start condition
         * This sends out the slave address and continues to read
         * until you issue a STOP
         */
        EUSCI_B_I2C_masterReceiveStart(EUSCI_I2C_BASE);
    
        __delay_cycles(INTER_BYTE_DELAY);
    
        val = EUSCI_B_I2C_masterReceiveSingle(EUSCI_I2C_BASE);
        r |= val;
        __delay_cycles(INTER_BYTE_DELAY);
    
        val = EUSCI_B_I2C_masterReceiveSingle(EUSCI_I2C_BASE);
        r |= ((unsigned long)val)<<8;
        __delay_cycles(INTER_BYTE_DELAY);
    
        val = EUSCI_B_I2C_masterReceiveSingle(EUSCI_I2C_BASE);
        r |= ((unsigned long)val)<<16;
        __delay_cycles(INTER_BYTE_DELAY);
    
        val = EUSCI_B_I2C_masterReceiveSingle(EUSCI_I2C_BASE);
        r |= ((unsigned long)val)<<24;
        *result = r;
        __delay_cycles(INTER_BYTE_DELAY);
    
        return 1;
    }

  • Hi Ketan,

    You are correct, the autostopgeneration is enabled in the code snippet you sent and the stop condition is generated automatically once the byte counter threshold is reached.

    Best,

    Robert

  • Hi,

    That means the threshold count can be use for the both the operation like reading and writing. 

    So first operation when writing is done, threshold count generates the stop condition and when reading start using restart the i2c operation using i2c start the flag, again once number bytes reader as per the threshold count, device generates the stop condition for end of the operation. Right?

  • Hi Ketan,

    As per the MSP340FR2355 user's guide in Section 24.3.8, "Address bytes do not increment the counter". So the stop condition is not generated when reading the function I2C_read32 that you snipped from the code. There are only 3 Control Word bytes as seen in the MCF8316A datasheet:

    This means that in the I2C Read Operation, the byte counter threshold of 4 is not reached during the start sequence when the 24-bit Control Word is sent. The next step in the Read Operation is to follow the control word with a repeated start which resets the counter. This is then additionally followed by data bytes to be read until byte counter threshold is reached. 

    You may also notice in the code that I sent, the I2C_write32 function has the autoSTOPGeneration function disabled. To implement this function into this Write Operation, you would need to set the byte counter threshold to 7: 3 for the Control Word and then 4 for the write byte because there is no repeated start. 

    Best,

    Robert

  • Hi,

    Noted. that means i should not issue extra stop condition for reading the shadow register because which will handle by the @byteCounterThreshold.

    Is shadow register is always be available for reading and writing through I2C Communication or any restriction is there for reading and writing?

     what about the slave address ?

  • that means i should not issue extra stop condition for reading the shadow register

    Correct.

    The shadow registers are always available for reading and writing through I2C unless a read or write operation is already occurring. For best practices, please review our datasheet that covers EEPROM access and the I2C interface.

    Best,

    Robert

  • Hi,

    Thank you for your update. 

    I'm able to read the shadow register through I2C without writing anything. 

    Preloaded GUI code for MSP340FR2355 is available on TI?

  • Hi Ketan,

    I am unsure of this, please direct this question to the MSP E2E forum.

    If I have answered all of your questions regarding our motor driver, please help by marking this thread as resolved.

    Best,

    Robert 

  • Hi

    Thank you for reply.

    I'm marking as resolved.