SLAA476B February 2011 – July 2019 BQ2040 , BQ2040 , BQ2060A , BQ2060A , BQ2063 , BQ2063 , BQ2083-V1P3 , BQ2083-V1P3 , BQ2084-V143 , BQ2084-V143 , BQ2084-V150 , BQ2084-V150 , BQ2085-V1P3 , BQ2085-V1P3 , BQ20Z40-R1 , BQ20Z40-R1 , BQ20Z70-V160 , BQ20Z70-V160 , BQ20Z80A-V110 , BQ20Z80A-V110 , BQ28400 , BQ28400 , BQ78PL114 , BQ78PL114 , BQ78PL116 , BQ78PL116 , LM5145 , LM5145 , MSP430F5500 , MSP430F5500 , MSP430F5501 , MSP430F5501 , MSP430F5502 , MSP430F5502 , MSP430F5503 , MSP430F5503 , MSP430F5504 , MSP430F5504 , MSP430F5505 , MSP430F5505 , MSP430F5506 , MSP430F5506 , MSP430F5507 , MSP430F5507 , MSP430F5508 , MSP430F5508 , MSP430F5509 , MSP430F5509 , MSP430F5510 , MSP430F5510 , TPS40057 , TPS40057 , TPS40170 , TPS40170
This function is implemented as a generic SMBus access function with packet error checking (PEC) implementation on the MSP430F5510 initialized to master mode. While similar to the SMBus_Access function, this function can either generate the PEC byte (if the master is transmitter) or can compare the PEC byte received against the internally computed one (if the master is receiver).
This function calls another function crc8MakeBitwise(), which computes the PEC byte within the MSP430F5510. In the master transmitter case, the PEC byte is appended last to the transmit buffer. If the slave fuel gauge returns an ACK immediately following the PEC byte, then data integrity was preserved during the transaction. On the other hand, if the return is a NACK, then some bits are being altered unintentionally during the transaction. In the case of the master receiver, the last byte in the receive buffer is the PEC byte. The PEC byte is internally generated, compared with the received one and if the bytes are equal, then a valid transaction occurred.
Function Definition
unsigned char Smbus_Access_PEC (unsigned char smbus_command, unsigned char read_write, unsigned char size_in_bytes {...}
Inputs
Name | Type | Description | Example Value |
---|---|---|---|
smbus_command | unsigned char | One byte of SMBus command (0x00 to 0x7F). See Section 4 for a list of supported SMBus commands. | SBS_CMD_VOLTAGE, SBS_CMD_CHARGING_CURRENT |
read_write | unsigned char | Set the mode to either read data from or write data to the slave device. | SMBUS_MASTER_MODE_READ, SMBUS_MASTER_MODE_WRITE |
size_in_bytes | unsigned char | Based on the command syntax, size of the data set to be sent or received. | 0x01 to 0x20 |
SMBus_Data_To_Slave | unsigned char[] | Array of data to be sent to the slave. The calling function should parse the data into byte-size elements and stuff them into this array. |
Return
Name | Type | Description | Example Value |
---|---|---|---|
smbus_access_status | unsigned char | Returns the status flag if the PEC byte sent by the slave fuel gauge matches the ones computed in the MSP430F5510 or if the PEC byte written by the MSP430F5510 is acknowledged by the slave device. | FLAG_SUCCESS=0, FLAG_FAIL=1, FLAG_NACK=2 |
SMBus_Data_From_Slave | unsigned char[] | Array of data to be received from the slave. The calling function should concatenate the byte-size elements to construct the data received. |
Example Function Call
To access the battery voltage through SMBus with PEC:
smbus_access_status = SMBus_Access_PEC(SBS_CMD_VOLTAGE, SMBUS_MASTER_MODE_READ, 2);
// Tables for data to/from Slave Device declared with size of 32 bytes
#define SMBUS_DATA_TO_SLAVE 32 //Table length
unsigned char SMBus_Data_To_Slave[SMBUS_DATA_TO_SLAVE];
#define SMBUS_DATA_FROM_SLAVE 32 //Table length
unsigned char SMBus_Data_From_Slave[SMBUS_DATA_FROM_SLAVE];