Function AFERead16BitBuffer() function in afe_config.c does not return a status
I am running the Analog Devices EVAL-ADE9430 board and noticed if I enable CRC checking reading 32 bit registers fail while 16-bit registers always pass.
I trace it down to the AFERead16BitBuffer() function not returning a status after reading the register over the SPI bus. This allows 16 bit register reads to work all the time while 32 Bit registers fail all the time (that's another story).
See line 12 below: HAL_SPI_Receive(&hSPI, (uint8_t *)&pData[0], 2 * numSamples, SPI_TIMEOUT);
uint32_t AFERead16BitBuffer(uint16_t addr, uint16_t numSamples, uint16_t *pData)
{
int32_t status = SYS_STATUS_SUCCESS;
cmdBuffer[0] = (addr >> 4);
cmdBuffer[1] = ((addr & 0x0F) << 4) + 8;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
status = HAL_SPI_Transmit(&hSPI, (uint8_t *)&cmdBuffer, 2, SPI_TIMEOUT);
if (status == 0)
{
HAL_SPI_Receive(&hSPI, (uint8_t *)&pData[0], 2 * numSamples,
SPI_TIMEOUT);
}
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
SwapEndian16Bit(&pData[0], numSamples);
DEBUG_MSG("REG16RD,0x%x,0x%x", addr, pData[0]);
return status;
}
Compare this to the uint32_t AFERead32BitBuffer(), line 17 below which returns a status.
uint32_t AFERead32BitBuffer(uint16_t addr, uint16_t numSamples, uint32_t *pData)
{
int32_t status = SYS_STATUS_SUCCESS;
cmdBuffer[0] = (addr >> 4);
cmdBuffer[1] = ((addr & 0x0F) << 4) + 8;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
status = HAL_SPI_Transmit(&hSPI, (uint8_t *)&cmdBuffer, 2, SPI_TIMEOUT);
/* FIXME : Handling SPI_Transmit error*/
if (status != 0)
{
status = HAL_SPI_Transmit(&hSPI, (uint8_t *)&cmdBuffer, 2, SPI_TIMEOUT);
}
if (status == 0)
{
status = HAL_SPI_Receive(&hSPI, (uint8_t *)&pData[0], 4 * numSamples,
SPI_TIMEOUT);
}
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
SwapEndian32Bit(&pData[0], numSamples);
DEBUG_MSG("REG32RD,0x%x,0x%x", addr, pData[0]);
return status;
}
Thanks - mike