This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

I2C protocal (BQ27510)

Other Parts Discussed in Thread: BQ27510

Hello I'm completely new to I2C protocol. but first is there any sample code for a Atmel microprocessor using I2C (or HDQ) talking to the BQ27510 fuel gauge,

Secondly would this quick mock code I made be able to access both the control register and the SOC register.

Thank you

	//////////read command register/////////////
	
	i2cSendStart();
	i2cWaitForComplete();
	i2cSendByte(0xaa);    //writes to BQ
	i2cWaitForComplete();
	i2cSendByte(0x00);    //control register
	i2cWaitForComplete();
	i2cSendStop();
	
	i2cSendStart();
	i2cWaitForComplete();
	i2cSendByte(0xab);    //reads from BQ 
	i2cWaitForComplete();
	i2cReceiveByte(TRUE);
	i2cWaitForComplete();
	xm = i2cGetReceivedByte();	//high byte
	i2cWaitForComplete();
	i2cReceiveByte(TRUE);
	i2cWaitForComplete();
	xl = i2cGetReceivedByte();	//high byte
	i2cWaitForComplete();
	i2cReceiveByte(TRUE);	
	i2cSendStop();
	i2cSendStart();	
	
	xo = xl|(xm << 8);
	
	return xo;
}

void read_percent(void)
{		
	//0xaa write, 0xab read
	
	uint8_t xm, xl;
	//uint8_t xmh, xml, xlh, xll;
	//long xo;
	
	i2cSendStart();
	i2cWaitForComplete();
	i2cSendByte(0xaa);    //writes to BQ
	i2cWaitForComplete();
	i2cSendByte(0x2c);    //SOC register 0.2c for bq27510
	i2cWaitForComplete();
	i2cSendStop();
	
	i2cSendStart();
	i2cWaitForComplete();
	i2cSendByte(0xab);    //read from BQ
	i2cWaitForComplete();
	i2cReceiveByte(TRUE);
	i2cWaitForComplete();
	xm = i2cGetReceivedByte();	//high byte
	i2cWaitForComplete();
	i2cReceiveByte(TRUE);
	i2cWaitForComplete();
	xl = i2cGetReceivedByte();	//high byte
	i2cWaitForComplete();
	i2cReceiveByte(TRUE);	
	i2cSendStop();
	i2cSendStart();