Other Parts Discussed in Thread: MSP430F5529
Tool/software: Code Composer Studio
Hello TI team,
I'm working on MSP430F5529LP with the Fuel Tank MKII Battery BoosterPack to read from the BQ27441 fuel gauge the value of SOC.
I started my work based an old project developed by TI on MSP_EXP432P401R.
The UART section work fine and I can see the character on my terminal. But as it expected I can't read from BQ27441.
This is my I2C function to read :
bool I2C_read16(unsigned char pointer, short * result, unsigned int timeout) { uint8_t val = 0; uint8_t valScratch = 0; short r = 0; /* Set master to transmit mode PL */ USCI_B_I2C_setMode(I2C_BASE, USCI_B_I2C_TRANSMIT_MODE); /* Clear any existing interrupt flag PL */ USCI_B_I2C_clearInterrupt(I2C_BASE, USCI_B_I2C_TRANSMIT_INTERRUPT); /* Initiate start and send first character */ if (!USCI_B_I2C_masterSendSingleByteWithTimeout(USCI_B0_BASE, pointer, timeout)) return 0; /* * Generate Start condition and set it to receive mode. * This sends out the slave address and continues to read * until you issue a STOP */ USCI_B_I2C_masterReceiveSingleStart(I2C_BASE); /* Wait for RX buffer to fill */ while(!(USCI_B_I2C_getInterruptStatus(I2C_BASE, USCI_B_I2C_RECEIVE_INTERRUPT))); /* Read from I2C RX register */ valScratch = USCI_B_I2C_masterReceiveMultiByteNext(I2C_BASE); /* Receive second byte then send STOP condition */ if (!USCI_B_I2C_masterReceiveMultiByteFinishWithTimeout(I2C_BASE, &val, timeout)) return 0; /* Shift val to top MSB */ r = (val << 8); /* Read from I2C RX Register and write to LSB of r */ r |= valScratch; /* Return temperature value */ *result = r; return 1; }
any condition in this code always back return 0 . for exemple this "if (!USCI_B_I2C_masterSendSingleByteWithTimeout(USCI_B0_BASE, pointer, timeout))"
bool USCI_B_I2C_masterSendMultiByteStartWithTimeout(uint16_t baseAddress, uint8_t txData, uint32_t timeout) { //Store current transmit interrupt enable uint8_t txieStatus = HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE; //Disable transmit interrupt enable HWREG8(baseAddress + OFS_UCBxIE) &= ~(UCTXIE); //Send start condition. HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTR + UCTXSTT; //Poll for transmit interrupt flag. while((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout) { ; } //Check if transfer timed out if(timeout == 0) { return (STATUS_FAIL); } //Send single byte data. HWREG8(baseAddress + OFS_UCBxTXBUF) = txData; //Reinstate transmit interrupt enable HWREG8(baseAddress + OFS_UCBxIE) |= txieStatus; return(STATUS_SUCCESS); }
Please can Anyone show me the error ?