SLUSCZ1 May 2017 TPS92518-Q1
PRODUCTION DATA.
The Command Frame can be constructed using the following code:
//assemble the 16-bit command
uint_t AssembleSPICmd(bool write, Registers518 regAddr, uint16_t data)
{
uint16_t assembledCmd = 0; // Build this to shift through parity calc
uint16_t parity = 0; // Parity bit calculated here
uint16_t packet = 0; // This will be what we send
// Set the CMD bit high if this is a write
if(write)
{
assembledCmd |= 0x8000; // Set CMD = 1
}
// Move the register address into the correct position
assembledCmd |= (( regAddr << 10) & 0x7C00);
// Append the data for a write
if(write)
{
assembledCmd |= (data & 0x01FF);
}
// Save this off into the returned variable
packet = assembledCmd;
// Calculate the parity bit
while(assembledCmd > 0)
{
// Count the number of 1s in the LSb
if(assembledCmd & 0x0001)
{
parity++;
}
// Shift right
assembledCmd >>= 1;
}
// If the LSb is a 0 (even # of 1s), we need to add the odd parity bit
if(!(parity & 0x0001))
{
packet |= (1 << 9);
}
return(packet);
}