2021-06-28 01:32 PM
Hello,
I'm working on hobby project using STM32F746IGT. I wrote ADC init sequence but cannot get it working properly. Timer 4 reloads at given period and It's interrupt is called properly. ADC starts conversion after setting SWSTART bit manually but I cannot make Timer4 to trigger ADC1.
Please help :)
void adc_init( void )
{
RCC -> APB2ENR |= RCC_APB2ENR_ADC1EN;
RCC -> APB1ENR |= RCC_APB1ENR_TIM4EN;
RCC -> AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOHEN;
gpio_pin_cfg(GPIOA, 7, GPIO_ANALOG);
// Timer 4 TRGO
// Max 36 MHz @ 3.3V
ADC->CCR = ADC_CCR_ADCPRE_0 | ADC_CCR_ADCPRE_1;
ADC1->CR2 = ADC_CR2_EXTEN_0 | ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_ADON;
ADC1->CR1 = ADC_CR1_SCAN | ADC_CR1_DISCEN | ADC_CR1_EOCIE;
ADC1->SQR1 = 0; // 1 regular conversion
ADC1->SQR3 = (7 << 0); // 1st conv IN7
ADC1->SMPR2 = (0b001 << (7*3)); // IN7 112 cycles
NVIC_EnableIRQ( ADC_IRQn );
NVIC_EnableIRQ( TIM4_IRQn );
ADC1->CR2 |= ADC_CR2_SWSTART;
// Sampling 16000 Hz
//
TIM4 -> ARR = 125 - 1;
// 500ns tick
//
TIM4 -> PSC = 216/2/2 - 1;
TIM4 -> CNT = 0;
TIM4 -> EGR = TIM_EGR_UG;
TIM4 -> CR2 = TIM_CR2_MMS_1;
TIM4 -> DIER = TIM_DIER_UIE;
TIM4 -> CR1 |= TIM_CR1_CEN;
}
void ADC_IRQHandler(void)
{
ADC1->SR = 0;
ADC->CSR = 0;
//static uint8_t val = 0;
double in = (double)(ADC1->DR-2048.0)/4096.0;
in++;
}
void TIM4_IRQHandler(void)
{
TIM4->SR = 0;
}
Solved! Go to Solution.
2023-02-22 08:21 AM
Thanks @Community member for coming back to this discussion. As confirmed here, issue is tracked internally.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-02-22 08:31 AM
Thanks, Amel.
Jan