Last active
January 15, 2024 16:20
-
-
Save csrohit/2fa28dbf3f04d3f993512f94ca511007 to your computer and use it in GitHub Desktop.
scan-adc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Set peripheral address as ADC data register */ | |
DMA1_Channel1->CPAR = (uint32_t)&ADC1->DR; | |
/* Set memory address as adc_value buffer */ | |
DMA1_Channel1->CMAR = (uint32_t)adc_value; | |
/* Set number of transfers */ | |
DMA1_Channel1->CNDTR = 2U; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Set transfer direction : Peripheral -> Memory */ | |
DMA1_Channel1->CCR &= ~DMA_CCR_DIR; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Enable memory increment */ | |
DMA1_Channel1->CCR |= DMA_CCR_MINC; | |
/* Disable perpheral increment */ | |
DMA1_Channel1->CCR &= ~DMA_CCR_PINC; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Set total conversions = 2 */ | |
ADC1->SQR1 &= ~ADC_SQR1_L; | |
ADC1->SQR1 |= 1 << ADC_SQR1_L_Pos; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Configure PA1 & PA2 in analog input mode */ | |
GPIOA->CRL &= ~(GPIO_CRL_CNF1 | GPIO_CRL_MODE1); | |
GPIOA->CRL &= ~(GPIO_CRL_CNF2 | GPIO_CRL_MODE2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ADC1->SMPR2 |= (ADC_SMPR2_SMP1_1 | ADC_SMPR2_SMP1_0); | |
ADC1->SMPR2 |= (ADC_SMPR2_SMP2_1 | ADC_SMPR2_SMP2_0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Enable SCAN mode */ | |
ADC1->CR1 |= ADC_CR1_SCAN; | |
/* Enable DMA request generation */ | |
ADC1->CR2 |= ADC_CR2_DMA; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ADC1->SQR3 &= ~(ADC_SQR3_SQ1 | ADC_SQR3_SQ2); | |
ADC1->SQR3 |= 1 << ADC_SQR3_SQ1_Pos; | |
ADC1->SQR3 |= 2 << ADC_SQR3_SQ2_Po |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Set memory size = 16 bits */ | |
DMA1_Channel1->CCR &= ~DMA_CCR_MSIZE; | |
DMA1_Channel1->CCR |= DMA_CCR_MSIZE_0; | |
/* Set peripheral size=16bits */ | |
DMA1_Channel1->CCR &= ~DMA_CCR_PSIZE; | |
DMA1_Channel1->CCR |= DMA_CCR_PSIZE_0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment