STM32 SPI Master Receiving
- September 30, 2019
- 5 replies
- 3895 views
Hello,
On my custom design board, I use external 12 bit ADC (ADS7886) and STM32F767VI. I try to get digitized ADC values with SPI interface. I set the SPI as Receive only master than prescaler as 8; baudrate as 13.5 Mbits/s; polarity as 1; phase as 1; data size as 16 bits; MSB.
My C code in Keil is
uint16_t ADC_Buf;
if(Rx_flag)
{
HAL_GPIO_WritePin(ADC_CS_GPIO_Port, ADC_CS_Pin, GPIO_PIN_RESET);
HAL_SPI_Receive(&hspi4, (uint8_t*)&ADC_Buf,2,100);
volt = (float)(ADC_Buf * 5 / pow(2,12)); //
HAL_GPIO_WritePin(ADC_CS_GPIO_Port, ADC_CS_Pin, GPIO_PIN_SET);
Rx_flag = 0;
}
I enabled SPI global interrupt. Then I set a timer. Timer frequency is at least 10 times bigger frequency than the input signal frequency. Every each interrupt of the timer, a flag is active then transmission happen. But I didn't plot in STM Studio and observe in debugger mode successfully yet. For example, now my input signal frequency is 1.96kHZ and I set the timer as 20kHz.
Do you have any idea to solve this problem?
Thank you,
