SLUSCZ1 May 2017 TPS92518-Q1
PRODUCTION DATA.
Perform a SPI read/write; with assumption that the buffer holding write data has been filled using the AssembleSPICmd function, Then send the 16-bit characters. Lower numbered array elements are nearer the MCU in the daisy-chain.
/* Perform the SPI read/write; assumed that the buffer holding write data has been filled
* using the AssembleSPICmd function. */
void SendSPIPacket(uint16_t chainID, uint16_t *writeBuf_ptr, uint16_t *readBuf_ptr)
{
uint16_t i;
// Which SSN to take low; SSx_LOW is a macro for GPO manipulation switch(chainID)
{
case 0:
SS0_LOW();
break;
case 1:
SS1_LOW();
break;
case 2:
SS2_LOW();
break;
default:
break;
}
// Send the 16-bit characters; lower numbered array elements are nearer the MCU in the daisy-chain
for(i = NUM_DEVICES_PER_CHAIN; i >= 1; i--)
{
SpibRegs.SPITXBUF = *(writeBuf_ptr + (i-1)); // Send each 16-bit piece of the packet
while(SpibRegs.SPISTS.bit.INT_FLAG == 0); // Wait for buffer to empty
*(readBuf_ptr + (i-1)) = SpibRegs.SPIRXBUF; // Grab the TPS92518 response
}
// Small delay to ensure all data is shifted out
DELAY_US(5);
// Make sure all SSN#s are high (SSx_HIGH is a macro)
SS0_HIGH();
SS1_HIGH();
SS2_HIGH();
}