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.

MSP430F5501: I2C Communication Using DriverLib

Part Number: MSP430F5501
Other Parts Discussed in Thread: MSP430F5510, MSP430WARE

Hello,

I am relatively new to working with the MSP430 and am also just starting out as a C programmer.

I designed a custom board based around the MSP430F5510 microcontroller. I have managed to bring up the prototype and have been able to initialize two external crystal based clocks (32,768 KHz for XT1 and 24.0000 MHz for XT2. When I start these oscillators, the code returns "Success" in each case. I am able to manipulate I/O pins without any trouble.

Here is the code that initializes the clocks:

void initclks(void) {
// Initialize clocks.
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, (GPIO_PIN4 + GPIO_PIN5));
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, (GPIO_PIN3 + GPIO_PIN2));
UCS_setExternalClockSource(32768, 24000000);
blnStatus = UCS_turnOnLFXT1WithTimeout(UCS_XT1_DRIVE_0, UCS_XCAP_3, 10);
blnStatus = UCS_turnOnXT2WithTimeout(UCS_XT1_DRIVE_3, 10);
UCS_initClockSignal(UCS_MCLK, UCS_XT2CLK_SELECT, UCS_CLOCK_DIVIDER_1);
UCS_initClockSignal(UCS_SMCLK, UCS_XT2CLK_SELECT, UCS_CLOCK_DIVIDER_8);
UCS_initClockSignal(UCS_ACLK, UCS_XT1CLK_SELECT, UCS_CLOCK_DIVIDER_1);
}

However, I am now trying to establish I2C communication with an onboard peripheral chip with a slave address of 0x45. I read a document called "Examples of Using I2C Master Usage". This is a very useful document that shows how to send and receive data via I2C both with DMA and without. I tried to implement this code in my project. However, it appears that this code does not work with the MSP430F5x family.

I then tried to follow the sample code in the DriverLib documentation.

I have a subroutine that attempts to initialize the I2C module:

void initi2c(void) {
// Initialize I2C Peripheral.
USCI_B_I2C_initMasterParam param = {0};
param.selectClockSource = USCI_B_I2C_CLOCKSOURCE_SMCLK;
param.i2cClk = UCS_getSMCLK();
param.dataRate = USCI_B_I2C_SET_DATA_RATE_400KBPS;
USCI_B_I2C_initMaster(USCI_B0_BASE, &param);
}

I then try to send a single byte to the I2C peripheral by calling the following subroutine:

 

void set_tw8833_data(uint16_t i2c_add, uint8_t i2c_data) {
// Set up the base address for TW8833.
USCI_B_I2C_setSlaveAddress(USCI_B0_BASE, 0x45);
USCI_B_I2C_setMode(USCI_B0_BASE, USCI_B_I2C_TRANSMIT_MODE);
USCI_B_I2C_enable(USCI_B0_BASE);
USCI_B_I2C_clearInterrupt(USCI_B0_BASE, USCI_B_I2C_STOP_INTERRUPT + USCI_B_I2C_TRANSMIT_INTERRUPT);

while (1)
{
USCI_B_I2C_masterSendSingleByte(i2c_add, i2c_data);
while(USCI_B_I2C_BUS_BUSY);
}
}

When I monitor the I2C data and clock lines . . . nothing happens.

Can anyone recommend a document that shows how to establish communication with an I2C peripheral using the MSP430F5510?

Thank you for your help,

Max

  • Max,

    Thank you for posting this question.

    You can also find some good examples of USCI_BI2C on TI’s Resource Explorer. (http://dev.ti.com/tirex/#/)
    Pertaining to your question you can find the examples by opening the following
    Software-> MSP430Ware -> Libraries -> Driver Library -> MSP430F5xx_6xx -> Example Projects->EUSCI_B_I2C

    Let me know if this helped you.

    - Travis Black
  • Max,

    Along with Travis's recommendation, please refer to SLAA734 for suggestions regarding typical MSP430 I2C communication issues. Logic analyzer or oscilloscope screenshots would be particularly helpful, the issue could range from the wrong slave address to improper pull-up resistor values.

    Regards,
    Ryan
  • You have configured P5.2/P5.3/P5.4/P5.5 for the XT1/XT2 functions, but you do not have configured the I²C pins.
  • Thank you very much for recommending the code examples. I have managed to use a modified version of the usci_b_i2c_ex2_masterTxMultiple code to transfer multiple bytes to my slave device. I have verified proper operation by checking the I2C Data and I2C Clock lines using a logic analyzer.  So, I am now confident that my I2C peripheral is initialized properly. I am now trying to read data from the I2C peripheral. I have read through the usci_b_i2c_masterRxSingle code. However, this code only seems to read a byte of information that has already been written to the internal receive register on the MSP430F5510. I don't see where I can set the address of the register in my peripheral where I want to read from.  For example, the slave address of my device is 0x45. I know how to set the slave address using the USCI_B_I2C_setSlaveAddress method. I now want to receive the data stored in a register with an address of 0x37. Where in the code do I set the 0x37 address?
    Thank you,

    Max

  • Thank you very much. The document you suggested was very helpful.
  • Thank you. Have done so now and I can transmit data to my I2C peripheral. However, I have not yet figured out how to read data from the peripheral.
  • Please see the "Reading from the Slave" section of this I2C protocol tutorial: www.robot-electronics.co.uk/i2c-tutorial

    Typically you will send a start sequence, send the slave address + R/W bit low (write), write the address you want to read from (0x37 in your case), send a repeated start, send the slave address + R/W bit high (read), read from the desired register (one or multiple consecutively), and then send the stop sequence. I'm glad to hear that you have a logic analyzer as creating this sequence will take some practice. There are several examples to model from on separate E2E threads.

    Regards,
    Ryan

**Attention** This is a public forum