Part Number: MSP432P401R
Tool/software: Code Composer Studio
I`m trying to communicate a MSP432 luanchpad (red edition) with a temperature & humidity sensor, SI7005 (Sensirion), over I2C protocol. I think I´m messing with the code. I´ve various problems now. This is the code I´m using:
void SI7021_readHumidity(void) { int i; uint8_t raw_data[3]; MAP_I2C_initMaster(EUSCI_B3_BASE, (const eUSCI_I2C_MasterConfig *)&SI7021_i2cConfig ); MAP_I2C_setSlaveAddress(EUSCI_B3_BASE, SI7021_ADDR); MAP_I2C_enableModule(EUSCI_B3_BASE); while (MAP_I2C_masterIsStopSent(EUSCI_B3_BASE)); //MAP_I2C_masterSendSingleByte(EUSCI_B3_BASE, SI7021_MEAS_RH_HOLD); // Start + 1Byte MAP_I2C_masterSendMultiByteStart(EUSCI_B3_BASE, SI7021_MEAS_RH_HOLD); //MAP_I2C_masterSendMultiByteNext(EUSCI_B3_BASE, 0x00); MAP_I2C_masterSendMultiByteFinish(EUSCI_B3_BASE, 0x00); while(!(EUSCI_B3->IFG & EUSCI_B_IFG_TXIFG0)); EUSCI_B3->CTLW0 &= ~(EUSCI_B_CTLW0_TR); EUSCI_B3->CTLW0 |= EUSCI_B_CTLW0_TXSTT; while(MAP_I2C_masterIsStartSent(EUSCI_B3_BASE)); for (i = 0; i<3; i++) { while(!(EUSCI_B3->IFG & EUSCI_B_IFG_RXIFG0)); raw_data[i] = EUSCI_B3->RXBUF; } MAP_I2C_disableModule(EUSCI_B3_BASE); SI7021_raw_RH = (raw_data[0] << 8) | raw_data[1]; }
And this is the frame according to the SI7021 datasheet:
As you can see in the image, between the 'slave address' you only need to send the 'measurement command' (1 byte). When I tried to use MAP_I2C_masterSendSingleByte(EUSCI_B3_BASE, SI7021_MEAS_RH_HOLD) the program got toasted at the line while(!(EUSCI_B3->IFG & EUSCI_B_IFG_TXIFG0)). Searching in the forum I found someone had a similar issue and managed to skip the problem by sending a blank byte (0x00) afterwords. That`s why in the above code you can see MAP_I2C_masterSendMultiByteStart(EUSCI_B3_BASE, SI7021_MEAS_RH_HOLD) and MAP_I2C_masterSendMultiByteFinish(EUSCI_B3_BASE, 0x00). After this change I was able to obtain a first measure.
But now I´m facing a new problem. When I try to take a second measurement the program gets stuck at while (MAP_I2C_masterIsStopSent(EUSCI_B3_BASE)). I imagine I´m not sending a stop signal to free both SDA and SCL lines. I´ve used a multi-meter and realized both lines stay low.
Could someone give a hand with this? Thanks in advance.