ADC + DMA + TIMER
PHP:
//misurare ogni secondo la temperatura tramite sensore interno dello schedino
//spostare dall'adc->dr in un vettore di 10 elementi, calcolare incertezza di tipo a
#include "stm32f4xx.h"
#define N 10
short buffer[N]={0};
int main(){
//abilitiamo le periferiche tim2 dma2 adc1
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
//configuro il timer tim2
TIM2->ARR = 36000000;
TIM2->CR2 |= TIM_CR2_MMS_1;
//configuro adc1
ADC1->CR2 |= ADC_CR2_EXTEN_0 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_2 | ADC_CR2_DDS | ADC_CR2_DMA | ADC_CR2_EOCS;
ADC1->SMPR1 |= ADC_SMPR1_SMP16_0 | ADC_SMPR1_SMP16_1 | ADC_SMPR1_SMP16_2;
ADC1->SQR3 |= 16;
ADC->CCR |= ADC_CCR_TSVREFE;
//configuro il dma2
DMA2_Stream0->CR |= DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC | DMA_SxCR_CIRC;
DMA2_Stream0->NDTR = N;
DMA2_Stream0->PAR = (uint32_t) (&(ADC1->DR));
DMA2_Stream0->M0AR = (uint32_t) (buffer);
ADC1->CR2 |= ADC_CR2_ADON;
TIM2->CR1 |= TIM_CR1_CEN;
ADC1->CR2 |= ADC_CR2_SWSTART;
DMA2_Stream0->CR |= DMA_SxCR_EN;
while(1);
}