Struggle with the ADC configuration of an stm32L476RG












0















I work on a project and I wanted to use ADC conversion (I work on an stm32L476), but I'm struggling with my code. My goal was to put a potentiometer between the ground and my 3.3 pin and see the result on PA1 with Putty. Here is the code of my ADC initialisation :



void BSP_Threshold_Init(){
//Enable GPIOA clock
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;

//Configure PA1 as input
GPIOA->MODER &= ~GPIO_MODER_MODE1_Msk;
GPIOA->MODER |= (0x00 <<GPIO_MODER_MODE1_Pos);

// Enable ADC clock
RCC->APB2ENR |= RCC_AHB2ENR_ADCEN;

// Reset ADC configuration
ADC1->CR = 0x00000000;
ADC1->CFGR = 0x00000000;
ADC1->CFGR2 = 0x00000000;
ADC1->SQR1 = 0x00000000;
ADC123_COMMON->CCR = 0x00000000;

// Enable continuous conversion mode
ADC1->CFGR |= ADC_CFGR_CONT;

// 12-bit resolution
ADC1->CFGR |= (0x00 <<ADC_CFGR_RES_Pos);

// Set sampling time to 24.5 ADC clock cycles
ADC1->SMPR1 |= (0x03 << 0U);

// Choose the number of conversion (here 1)
ADC1->SQR1 |= (0x00 << 0U);

//Choose the channel of the first conversion
ADC1->SQR1 |= (0x01 << 6U);

//// Select HCLK/1 as ADC clock
ADC123_COMMON->CCR |= (0x01 <<ADC_CCR_CKMODE_Pos);

// Enable ADC
ADC1->CR |= ADC_CR_ADEN;

// Start conversion
ADC1->CR |= ADC_CR_ADSTART;

}


Then in my main, I want to print the value of my ADC on Putty (I worked with Putty several times, so I don't think there is a problem here).



Here is the portion of code in my main :



while(1)
{

// Wait here until ADC EOC
while ((ADC1->ISR & ADC_ISR_EOC) != ADC_ISR_EOC);

// Report result to console
my_printf("ADC value = %xrn", ADC1->DR);

// Wait about 200ms
for (i=0; i<500000; i++);

}


I printed other things in the init phase with my_printf, but when comes the time to do the loop, nothing appears. Do you have any clues of what I could do wrong ? I don't know if my problem comes from my ADC configuration, or if it comes from my clock configuration or the way I wait for the ADC conversion in my main.



Thanks in advance.










share|improve this question


















  • 1





    Hi, please debug your program first so you will see if the ADC is producing any useful output. Then you will have much more informations about where your problem might be.

    – A.R.C.
    Nov 22 '18 at 14:20
















0















I work on a project and I wanted to use ADC conversion (I work on an stm32L476), but I'm struggling with my code. My goal was to put a potentiometer between the ground and my 3.3 pin and see the result on PA1 with Putty. Here is the code of my ADC initialisation :



void BSP_Threshold_Init(){
//Enable GPIOA clock
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;

//Configure PA1 as input
GPIOA->MODER &= ~GPIO_MODER_MODE1_Msk;
GPIOA->MODER |= (0x00 <<GPIO_MODER_MODE1_Pos);

// Enable ADC clock
RCC->APB2ENR |= RCC_AHB2ENR_ADCEN;

// Reset ADC configuration
ADC1->CR = 0x00000000;
ADC1->CFGR = 0x00000000;
ADC1->CFGR2 = 0x00000000;
ADC1->SQR1 = 0x00000000;
ADC123_COMMON->CCR = 0x00000000;

// Enable continuous conversion mode
ADC1->CFGR |= ADC_CFGR_CONT;

// 12-bit resolution
ADC1->CFGR |= (0x00 <<ADC_CFGR_RES_Pos);

// Set sampling time to 24.5 ADC clock cycles
ADC1->SMPR1 |= (0x03 << 0U);

// Choose the number of conversion (here 1)
ADC1->SQR1 |= (0x00 << 0U);

//Choose the channel of the first conversion
ADC1->SQR1 |= (0x01 << 6U);

//// Select HCLK/1 as ADC clock
ADC123_COMMON->CCR |= (0x01 <<ADC_CCR_CKMODE_Pos);

// Enable ADC
ADC1->CR |= ADC_CR_ADEN;

// Start conversion
ADC1->CR |= ADC_CR_ADSTART;

}


Then in my main, I want to print the value of my ADC on Putty (I worked with Putty several times, so I don't think there is a problem here).



Here is the portion of code in my main :



while(1)
{

// Wait here until ADC EOC
while ((ADC1->ISR & ADC_ISR_EOC) != ADC_ISR_EOC);

// Report result to console
my_printf("ADC value = %xrn", ADC1->DR);

// Wait about 200ms
for (i=0; i<500000; i++);

}


I printed other things in the init phase with my_printf, but when comes the time to do the loop, nothing appears. Do you have any clues of what I could do wrong ? I don't know if my problem comes from my ADC configuration, or if it comes from my clock configuration or the way I wait for the ADC conversion in my main.



Thanks in advance.










share|improve this question


















  • 1





    Hi, please debug your program first so you will see if the ADC is producing any useful output. Then you will have much more informations about where your problem might be.

    – A.R.C.
    Nov 22 '18 at 14:20














0












0








0








I work on a project and I wanted to use ADC conversion (I work on an stm32L476), but I'm struggling with my code. My goal was to put a potentiometer between the ground and my 3.3 pin and see the result on PA1 with Putty. Here is the code of my ADC initialisation :



void BSP_Threshold_Init(){
//Enable GPIOA clock
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;

//Configure PA1 as input
GPIOA->MODER &= ~GPIO_MODER_MODE1_Msk;
GPIOA->MODER |= (0x00 <<GPIO_MODER_MODE1_Pos);

// Enable ADC clock
RCC->APB2ENR |= RCC_AHB2ENR_ADCEN;

// Reset ADC configuration
ADC1->CR = 0x00000000;
ADC1->CFGR = 0x00000000;
ADC1->CFGR2 = 0x00000000;
ADC1->SQR1 = 0x00000000;
ADC123_COMMON->CCR = 0x00000000;

// Enable continuous conversion mode
ADC1->CFGR |= ADC_CFGR_CONT;

// 12-bit resolution
ADC1->CFGR |= (0x00 <<ADC_CFGR_RES_Pos);

// Set sampling time to 24.5 ADC clock cycles
ADC1->SMPR1 |= (0x03 << 0U);

// Choose the number of conversion (here 1)
ADC1->SQR1 |= (0x00 << 0U);

//Choose the channel of the first conversion
ADC1->SQR1 |= (0x01 << 6U);

//// Select HCLK/1 as ADC clock
ADC123_COMMON->CCR |= (0x01 <<ADC_CCR_CKMODE_Pos);

// Enable ADC
ADC1->CR |= ADC_CR_ADEN;

// Start conversion
ADC1->CR |= ADC_CR_ADSTART;

}


Then in my main, I want to print the value of my ADC on Putty (I worked with Putty several times, so I don't think there is a problem here).



Here is the portion of code in my main :



while(1)
{

// Wait here until ADC EOC
while ((ADC1->ISR & ADC_ISR_EOC) != ADC_ISR_EOC);

// Report result to console
my_printf("ADC value = %xrn", ADC1->DR);

// Wait about 200ms
for (i=0; i<500000; i++);

}


I printed other things in the init phase with my_printf, but when comes the time to do the loop, nothing appears. Do you have any clues of what I could do wrong ? I don't know if my problem comes from my ADC configuration, or if it comes from my clock configuration or the way I wait for the ADC conversion in my main.



Thanks in advance.










share|improve this question














I work on a project and I wanted to use ADC conversion (I work on an stm32L476), but I'm struggling with my code. My goal was to put a potentiometer between the ground and my 3.3 pin and see the result on PA1 with Putty. Here is the code of my ADC initialisation :



void BSP_Threshold_Init(){
//Enable GPIOA clock
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;

//Configure PA1 as input
GPIOA->MODER &= ~GPIO_MODER_MODE1_Msk;
GPIOA->MODER |= (0x00 <<GPIO_MODER_MODE1_Pos);

// Enable ADC clock
RCC->APB2ENR |= RCC_AHB2ENR_ADCEN;

// Reset ADC configuration
ADC1->CR = 0x00000000;
ADC1->CFGR = 0x00000000;
ADC1->CFGR2 = 0x00000000;
ADC1->SQR1 = 0x00000000;
ADC123_COMMON->CCR = 0x00000000;

// Enable continuous conversion mode
ADC1->CFGR |= ADC_CFGR_CONT;

// 12-bit resolution
ADC1->CFGR |= (0x00 <<ADC_CFGR_RES_Pos);

// Set sampling time to 24.5 ADC clock cycles
ADC1->SMPR1 |= (0x03 << 0U);

// Choose the number of conversion (here 1)
ADC1->SQR1 |= (0x00 << 0U);

//Choose the channel of the first conversion
ADC1->SQR1 |= (0x01 << 6U);

//// Select HCLK/1 as ADC clock
ADC123_COMMON->CCR |= (0x01 <<ADC_CCR_CKMODE_Pos);

// Enable ADC
ADC1->CR |= ADC_CR_ADEN;

// Start conversion
ADC1->CR |= ADC_CR_ADSTART;

}


Then in my main, I want to print the value of my ADC on Putty (I worked with Putty several times, so I don't think there is a problem here).



Here is the portion of code in my main :



while(1)
{

// Wait here until ADC EOC
while ((ADC1->ISR & ADC_ISR_EOC) != ADC_ISR_EOC);

// Report result to console
my_printf("ADC value = %xrn", ADC1->DR);

// Wait about 200ms
for (i=0; i<500000; i++);

}


I printed other things in the init phase with my_printf, but when comes the time to do the loop, nothing appears. Do you have any clues of what I could do wrong ? I don't know if my problem comes from my ADC configuration, or if it comes from my clock configuration or the way I wait for the ADC conversion in my main.



Thanks in advance.







stm32






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 7:54









HixHix

134




134








  • 1





    Hi, please debug your program first so you will see if the ADC is producing any useful output. Then you will have much more informations about where your problem might be.

    – A.R.C.
    Nov 22 '18 at 14:20














  • 1





    Hi, please debug your program first so you will see if the ADC is producing any useful output. Then you will have much more informations about where your problem might be.

    – A.R.C.
    Nov 22 '18 at 14:20








1




1





Hi, please debug your program first so you will see if the ADC is producing any useful output. Then you will have much more informations about where your problem might be.

– A.R.C.
Nov 22 '18 at 14:20





Hi, please debug your program first so you will see if the ADC is producing any useful output. Then you will have much more informations about where your problem might be.

– A.R.C.
Nov 22 '18 at 14:20












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426193%2fstruggle-with-the-adc-configuration-of-an-stm32l476rg%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426193%2fstruggle-with-the-adc-configuration-of-an-stm32l476rg%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$