2020-09-01 10:10 PM
2020-09-01 11:47 PM
Data shifted by one but for some reason? Observe SPI bus using logic analyzer and compare to waveform given in the ADC datasheet.
If SCK pin's GPIO OSPEEDR setting is low, try increasing it to medium.
JW
2020-09-04 04:11 AM
Thank you reply.. I checked SCK pin, it is high only. I will add here that I am using SPI with DMA here.
2020-09-04 04:25 AM
This is my SCK GPIO configuration.
/*##-2- Configure peripheral GPIO ##########################################*/
/* SPI SCK GPIO pin configuration */
GPIO_InitStruct.Pin = SPI4_SCK_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = SPI4_SCK_AF;
HAL_GPIO_Init(SPI4_SCK_GPIO_PORT, &GPIO_InitStruct);
2020-09-04 04:30 AM
1.Register_write finction.
2.ADC_Read finction.
uint8_t ADC_ADS8688_2_Register_Write(uint8_t RegAddrVal, uint8_t Data)
{
uint8_t TempTx[3] = {0,0,0}, TempRx[3] = {0,0,0};
HAL_GPIO_WritePin(SPI4_ADC_ADS8688_2_CS_GPIO_PORT, SPI4_ADC_ADS8688_2_CS_PIN, GPIO_PIN_RESET);
TempTx[0] = (RegAddrVal << 1) | 0x01;
TempTx[1] = Data;
TempTx[2] = 0x00;
if(HAL_SPI_TransmitReceive_DMA(&Spi4Handle, TempTx, TempRx, sizeof(TempTx)) != HAL_OK)
{
/* Transfer error in transmission process */
Error_Handler();
}
while(Spi4Handle.State != HAL_SPI_STATE_READY);
HAL_GPIO_WritePin(SPI4_ADC_ADS8688_2_CS_GPIO_PORT, SPI4_ADC_ADS8688_2_CS_PIN, GPIO_PIN_SET);
if(TempTx[1] == TempRx[2])
{
return 1;
}
else
{
return 0;
}
}
void ADC_ADS8688_2_Read_Channel(uint8_t *data)
{
uint8_t TempTx[4] = {0,0,0,0}, TempRx[4] = {0,0,0,0};
memset(TempTx, 0x00, sizeof(TempTx));
memset(TempRx, 0x00, sizeof(TempRx));
HAL_GPIO_WritePin(SPI4_ADC_ADS8688_2_CS_GPIO_PORT, SPI4_ADC_ADS8688_2_CS_PIN, GPIO_PIN_RESET);
if(HAL_SPI_TransmitReceive_DMA(&Spi4Handle, TempTx, TempRx, sizeof(TempTx)) != HAL_OK)
{
/* Transfer error in transmission process */
Error_Handler();
}
while(Spi4Handle.State != HAL_SPI_STATE_READY);
HAL_GPIO_WritePin(SPI4_ADC_ADS8688_2_CS_GPIO_PORT, SPI4_ADC_ADS8688_2_CS_PIN, GPIO_PIN_SET);
memcpy(data, &TempRx[2], 2);
}