2022-11-28 05:37 AM
Hello,
I am having difficulties trying to sample both channels of the LTC1865 ADC and was hoping someone could point out my mistakes. This is my function to sample the channels. I am using the STM32WB55 micro.
unsigned int READ_External_ADC(int channel)
{
if (channel != previousADCchannel)
{
// The LTC1865 conversion cycle begins with the rising edge of Conv (pin..)
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
// Wait for the conversion to complete
HAL_Delay(ADC_CONVERSION_TIME);
// Enable the Serial Data out to allow the data to be shifted out by taking CONV low
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, (uint16_t *)(0x8000 | ((unsigned int) channel << 14)), 2, HAL_MAX_DELAY);
// save the new ADC channel
previousADCchannel = channel;
}
// The LTC1865 conversion cycle begins with the rising edge of Conv (pin..)
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
// Wait for the conversion to complete
HAL_Delay(ADC_CONVERSION_TIME);
// Enable the Serial Data out to allow the data to be shifted out by taking CONV low
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, (uint16_t *)(0x8000 | ((unsigned int) channel << 14)), 2, HAL_MAX_DELAY);
HAL_SPI_TransmitReceive(hspi, pTxData, pRxData, Size, Timeout)
return(adcVal); // Return the 16-bit value
}
Any help would be very much appreciated
Thanks.
2022-11-29 07:36 PM
Get CubeMX installed, there are examples how to use SPI.
I see in code two attempts calling HAL_SPI_Transmit and one HAL_SPI_TransmitReceive, but all you need is HAL_SPI_TransmitReceive properly configured. CubeMX has an answer