主题中讨论的其他器件: HDC2080
我正在尝试使用 基于 此 示例的 driverlib HAL、通过 I2C 连接使用 MSP430FR5969 (WISP 5.1)和 HDC2080温度/湿度传感器的电路板。 我将使用2k Ω 上拉电阻器、如果这起作用的话。 传感器经确认可与 Arduino 配合使用、但现在我想在 MSP 中复制该功能。
这是我当前使用的代码片段(为简洁起见、省略了其他不相关的器件。 如果有用、这是 在 CCS 11中的 WISP 固件的基础上构建的):
#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); ... } }
运行该函数时、代码看起来像卡在"eUSCI_B_I2C_masterSendSingleByte"中(在 driverlib 的 eusci_b_i2c.c 中)。 更具体地说、它在这里循环:
//Poll for transmit interrupt flag. while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
如何进一步调试此问题?