5 Software example source code
The following source code shows a 4-wire SPI application case.
/*!
*****************************************************************************
* \brief Reads out chip data via SPI interface
*
* This function is used to read out cordic value from chips supporting SPI
* interface.
* After calling this function the data can be displayed using #displayData.
*
* \param[in] die : index of the die to read out.
* \param[out] dd : Buffer of type #t_displayData where the read out data
* will be written to.
*
*****************************************************************************
*/
static void spiReadData(u8 die, t_displayData * dd)
{
umword i;
u16 dat;
u16 agcreg;
#ifdef AS5048_CHIPDESCRIPTION
u16 magreg;
#endif
PARAMETER_UNUSED(die);
dd->angleprec = 0;
/* read agc value */
for (i = 0; i < 2; i++)
{
/* the result is available only just in the second transfer.
transfers must be separated by chip selects */
dat = SPI_CMD_READ | SPI_REG_AGC;
dat |= spiCalcEvenParity(dat);
spiTransfer((u8*)&dat, sizeof(u16));
}
agcreg = dat;
#ifdef AS5048_CHIPDESCRIPTION
for (i = 0; i < 2; i++)
{
/* the result is available only just in the second transfer.
transfers must be separated by chip selects */
dat = SPI_CMD_READ | SPI_REG_MAG;