cancel
Showing results for 
Search instead for 
Did you mean: 

Using SPI to sample both channels of LTC1865 ADC. Need help

kcire L.
Associate III

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.

1 REPLY 1
MasterT
Lead

Get CubeMX installed, there are examples how to use SPI.

https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html

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