2020-07-27 01:51 PM
int main(void){
double digital;
char Stringa[20];
int x=1,k,j,i=0;
RCC_CFGR=RCC_CFGR|0xE000; //clock divided by 16---->APB2 pheripherals CLK = 1MHz
RCC_APB1ENR=RCC_APB1ENR|0x20001; //abilitazione clock per TIMER2 e USART2
RCC_CR=RCC_CR|0x1;
RCC_APB2ENR=0x101; //abilitazione clock per TIMER1 e ADC1
RCC_AHB1ENR=0x40000F; //abilitazione clock GPIOA, GPIOB,GPIOC e GPIOD e DMA2
GPIOB_MODER=0x10004001;
GPIOA_MODER=GPIOA_MODER|0x2BC00; //pin A7,A8 in alternate function mode e pin A6 e A5 in analog mode
GPIOD_MODER=0x2800; //pin D5/D6 in alternate function mode
GPIOD_AFRL=GPIOD_AFRL|0x7700000; //mappo PD5/PD6 per USART2
//NVIC_ADC=0x40000;
DMA2_S0PAR=0x4001204C; //base address della periferica dalla quale lo stream prende il dato
DMA2_S0M0AR=0x40020814; //indirizzo di memoria dove scrivere il dato
DMA2_S0NDTR=DMA2_S0NDTR|0xFFFF; //numero di elementi da trasferire
//DMA2_S0CR=DMA2_S0CR|0x400;
DMA2_S0CR=DMA2_S0CR|0x75111; //stream enabled, DIR, circular mode e interrupt enabled
ADC1_CR1=ADC1_CR1|0x100; //Scan mode enabled
ADC1_SQR1=0x100000; //regular sequence lenght
ADC1_SQR3=0xC5; //canale 5(PA5) come primo nella sequenza e PA6 come secondo nella sequenza
ADC1_SMPR2=0x1D8000; //56 cycles per entrambi i canali
ADC1_CR2=ADC1_CR2|0x503; //ADC ON, continuos conversion mode DMA mode enabled
TIM2_CNT=0x0;
TIM2_ARR=0x1E8; //intervallo di conteggio pari a 10ms
USART2_BRR=0x8B; //fisso un baud rate pari a 115200 simb/s
USART2_CR1=USART2_CR1|0x200C; //transmit e receiver enable e usart enable
ADC1_CR2=ADC1_CR2|0x40000000; //avvio della conversione
digital=GPIOC_ODR;
}
For example, playing the program, it converts ch5 for a certain time(casual) then convert ch6 but it doesn't convert the channel alternately.