2021-08-11 01:27 AM
My ADC1_Data Register is null. I can't understand why it is. Can u help me?
#include "main.h"
#include "SysClockConf.h"
uint16_t values[256];
// MY CLOCK IS 170 MHz."
// STM32G431
// READ_BIT() Fonksiyonu
void GPIO_Config(){
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // Initialize the clock for GPIOA. -->
RCC->AHB2ENR |= RCC_AHB2ENR_ADC12EN; // ADC12 clock is enabled.
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN; // FOR LED
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; // TIM8 clock is enabled.
GPIOA->MODER |= (0b11<<GPIO_MODER_MODE0_Pos); // GPIOA0 is adjusted as analog, default state
GPIOB->MODER &= ~(0b1<<(GPIO_MODER_MODE8_Pos+1)); // LED as output.
}
void delay(){
static uint16_t t=10000;
while(t--);
}
void ADC_Config(){
ADC1->CR &= ~(ADC_CR_ADSTART) ; // ADSTART is set to 0, to configure, default.
ADC1->CR &= ~(1<<ADC_CR_DEEPPWD_Pos); // not in deep power down.
ADC1->CR |= ADC_CR_ADVREGEN; //
delay();
//ADC1->CFGR &= ~(ADC_CFGR_CONT);// Single conversion mode
ADC1->CFGR |= ADC_CFGR_DISCEN; // Discontinous mode is enabled.
ADC1->SQR1 &= ~(1<<ADC_SQR1_L_Pos); // one channel
ADC1->SQR1 |= (1<<ADC_SQR1_SQ1_Pos); // 1st conversion in regular sequence (DATASHEETDAN BAK) !!! IN1 olarak geçiyor PA0 olmasına rağmen.
ADC1->DIFSEL &= ~(ADC_DIFSEL_DIFSEL_0); //
//ADC1->CFGR &= ~(0b11<<ADC_CFGR_RES_Pos); // 12 bit resolution, default
ADC1->CFGR |= (0b01<<ADC_CFGR_EXTEN_Pos); // Rising Edge Triggered.
//ADC1->CFGR |= ADC_CFGR_EXTSEL_2 | ADC_CFGR_EXTSEL_1 | ADC_CFGR_EXTSEL_0; // External event TIM8 TRGO [00111]
ADC1->CFGR |= ADC_CFGR_EXTSEL_3; // TIM8 TRGO2 [010000];
ADC1->CR |= ADC_CR_ADEN; // ADC ON
ADC1->SMPR1 |= (0b111<<ADC_SMPR1_SMP1_Pos); // Default 2.5 ADC_CLK
while(!(ADC1->ISR & ADC_ISR_ADRDY)); // Till ADC ready
ADC1->CR &= ~(1<<ADC_CR_ADCALDIF_Pos); // Calibration single ended
ADC1->CR |= ADC_CR_ADCAL; // Calibration starts - single channel
while(!(ADC1->CR & ADC_CR_ADCAL)); // Till the calibration is done
ADC1->ISR |= (ADC_ISR_ADRDY); // Clear ready flag
}
void TIM8_Config(){ // Up counter and edge aligned mode
TIM8->PSC = 1000-1;
TIM8->ARR = 17000-1;
TIM8->DIER |= TIM_DIER_UIE; // UPDATE INTERRUPT ENABLED
TIM8->CR2 = (0010<<TIM_CR2_MMS_Pos); // Update event mode
}
void TIM8_UP_IRQHandler(void){
TIM8->SR &= ~(TIM_SR_UIF);
static uint8_t m = 0;
values[m++] = ADC1->DR;
ADC1->ISR &= ~(ADC_ISR_EOC);
while(!(ADC1->ISR & ADC_ISR_EOC)); // END OF CONVERSION FLAGI KALKMIYOR.
GPIOB->ODR ^= (1<<GPIO_ODR_OD8_Pos);
}
int main(void)
{
HAL_Init();
SystemClock_Config();
GPIO_Config();
TIM8_Config();
ADC_Config();
ADC1->CR |= ADC_CR_ADSTART;
NVIC_EnableIRQ(TIM8_UP_IRQn);
NVIC_SetPriority(TIM8_UP_IRQn,1);
TIM8->CR1 |= (1<<TIM_CR1_CEN_Pos);
while (1){
GPIOB->ODR |= 0;
}
}
// PSC--> 5000 ARR 17000 for her saniyede TIM8_UP_URQHandler fonksiyonuna giriyor.
2021-08-12 07:03 AM
Hi YKahr.1 ,
It is hard to say where is problem from the code - probably the timer trigger not works. Please try to design given application in STM32CubeMX and check the functionality then. And then compare the generated code and your original code (check the ADC and TIM8 registers content).
Regards
Igor
2021-08-12 09:43 AM
JW