Other Parts Discussed in Thread: BQ27510, HALCOGEN
I'm trying to use the I2C module on a LAUNCHXL2 RM46 LaunchPad to talk to the Texas Instruments bq27510 fuel gauge IC.
I should send commands in this order:
Start
Send Write Address (0xAA)
- ACK
Send 1 byte: 0x2e
- ACK
Re-Start
Send Read Address (0xAB)
- ACK
Read byte
- ACK
Read byte
- NACK
Stop
I have issues working with the restart mode.
I've checked TRM, section 30.2.5.3 Using the Repeated START Condition
In HALCoGen, I set
- enable Master
- 7BIT_AMODE
- enable repeat mode
- TRANSMITTER
- 8_BIT
- Data Count 8 (modified in code to be 1 at send, 2 at receive)
#define bq27510_address 0x55
#define Slave_Address bq27510_address
uint8_t TX_Data_Master[1] = { 0x2E};
uint8_t RX_Data_Master[2] = { 0 };
// ...
i2cInit();
i2cSetSlaveAdd(i2cREG1, Slave_Address);
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
i2cSetCount(i2cREG1, 1);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStart(i2cREG1);
i2cSend(i2cREG1, 1, TX_Data_Master);
while(i2cIsBusBusy(i2cREG1) == true);
/* Simple delay before starting Next Block */
/* Depends on how quick the Slave gets ready */
for(delay=0;delay<1000000;delay++);
i2cSetSlaveAdd(i2cREG1, Slave_Address);
i2cSetDirection(i2cREG1, I2C_RECEIVER);
i2cSetCount(i2cREG1, 2);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cReceive(i2cREG1, 2, RX_Data_Master);
/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true);
/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);
/* Clear the Stop condition */
i2cClearSCD(i2cREG1);
The program doesn't generate the repeated start after sending the 0x2e, and I'm uncertain on how to proceed.
Edit and clarification:
The STOP line on position 5 in this image is what I should get rid off (repeated start scenario):
The image below is the communication scenario that I should achief:









