Other Parts Discussed in Thread: HDC2080
I'm trying to connect a board that uses the MSP430FR5969 (the WISP 5.1) with a HDC2080 temperature/humidity sensor through I2C, using the driverlib HAL, based on this example. I'm using a 2k ohm pull-up, if that plays a part. The sensor was confirmed working fine with an Arduino, but now I wanted to replicate the functionality in the MSP.
Here's a code snippet I'm currently using (other unrelated parts omitted for brevity. If it helps, this is built on top of the WISP firmware in CCS 11):
#define SENSOR_ADDRESS 0x40 // HDC2080 address
#define SENSOR_CONFIG_REGISTER 0x0F // HDC2080 configuration register
void initI2C(){
WDT_A_hold(WDT_A_BASE);
//Set DCO frequency to 1MHz
CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0);
//Set ACLK = VLO with frequency divider of 1
CS_initClockSignal(CS_ACLK,CS_VLOCLK_SELECT,CS_CLOCK_DIVIDER_1);
//Set SMCLK = DCO with frequency divider of 1
CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
//Set MCLK = DCO with frequency divider of 1
CS_initClockSignal(CS_MCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
// Configure Pins for I2C
//Set P1.6 and P1.7 as Secondary Module Function Input.
/*
* Select Port 1
* Set Pin 6, 7 to input Secondary Module Function, (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
*/
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P1,
GPIO_PIN6 + GPIO_PIN7,
GPIO_SECONDARY_MODULE_FUNCTION
);
/*
* Disable the GPIO power-on default high-impedance mode to activate
* previously configured port settings
*/
PMM_unlockLPM5();
//Initialize Master
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 = 1;
param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, ¶m);
//Specify slave address
EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, SENSOR_ADDRESS);
//Set in transmit mode
EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
// Set timeout to prevent infinite loops
EUSCI_B_I2C_setTimeout(EUSCI_B0_BASE, 1000);
//Enable I2C Module to start operations
EUSCI_B_I2C_enable(EUSCI_B0_BASE);
}
uint8_t readI2CRegister(uint8_t registerAddress){
// Send single byte as address
EUSCI_B_I2C_masterSendSingleByte(EUSCI_B0_BASE, registerAddress);
// Delay until transmission completes
while (EUSCI_B_I2C_isBusBusy(EUSCI_B0_BASE));
// Switch to read mode
EUSCI_B_I2C_setMode(SENSOR_ADDRESS, EUSCI_B_I2C_RECEIVE_MODE);
// Receive start
EUSCI_B_I2C_masterReceiveStart(SENSOR_ADDRESS);
// Read data from register (and then send STOP)
uint8_t data = EUSCI_B_I2C_masterReceiveSingle(SENSOR_ADDRESS);
// Return data
return data;
}
void writeI2CRegister(uint8_t registerAddress, uint8_t data){
// Go to transmit mode
EUSCI_B_I2C_setMode(SENSOR_ADDRESS, EUSCI_B_I2C_TRANSMIT_MODE);
// Send single byte as address
EUSCI_B_I2C_masterSendSingleByte(EUSCI_B0_BASE, registerAddress);
// Delay until transmission completes
while (EUSCI_B_I2C_isBusBusy(EUSCI_B0_BASE));
// Send data
EUSCI_B_I2C_masterSendSingleByte(EUSCI_B0_BASE, data);
// Delay until transmission completes
while (EUSCI_B_I2C_isBusBusy(EUSCI_B0_BASE));
}
void main(void) {
...
// Init I2C
initI2C();
// Enable measurements on the HDC2080 with mostly default settings
writeI2CRegister(SENSOR_CONFIG_REGISTER, 0x01);
uint8_t temp1;
while(true){
...
temp1 = readI2CRegister(0x00);
...
}
}
When this is run, it looks like the code is getting stuck in "EUSCI_B_I2C_masterSendSingleByte" (in driverlib's eusci_b_i2c.c). More specifically, it's looping in here:
//Poll for transmit interrupt flag. while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
How can I further debug this problem?



