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, ¶m);
}
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