cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ADC from STM32F207

sven
Associate II
Posted on May 25, 2015 at 20:51

Hallo,

I try to read the ADC but get allways 0 als result :-( Does anybody have an Idea whats wrong?

GPIO_Clk_Enable(@GPIOA_BASE);
GPIO_Config(@GPIOA_BASE,_GPIO_PINMASK_All,_GPIO_CFG_MODE_ANALOG or _GPIO_CFG_PULL_NO);
ADON_bit :=1; // ADC on/off
CONT_bit :=1; // use continius measurement
ADC1_CR1 := %00000010000000000000000000000000;
ADC1_CR2 := %01000000000000000000000000000011;
ADC1_SQR1 := %00000000000000000000000000000000;
ADC1_SQR3 := %00000000000000000000000000000000;
//ADC1_SMPR1 := %0000000000000000000000000000000;
//ADC1_SMPR2 := %0000000000000000000000000000000;
SWSTART_bit := 1; //start conversion
while EOC1_bit = 1 DO nop;value := ADC1_DR;

9 REPLIES 9
raptorhal2
Lead
Posted on May 25, 2015 at 21:52

Did you turn on the ADC peripheral clock ?

Cheers, Hal

sven
Associate II
Posted on May 26, 2015 at 07:40

I found this

// RCC_APB2ENR:= //ADC CLK activate ADC1EN_bit :=1;

// RCC_APB2LPENR := //

it is allowed to write only the ADC_CKL bit= or have I write all bits(16?)

And I found this, do I really need all?!? of this with DMA clk and so on!?!

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/ADC%20channel%20reading&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=3404

sven
Associate II
Posted on May 26, 2015 at 12:09

is there any Diagram where I can see, what and when I have to set for using Perepheri?!?

Thinks like 

For using ADC you have set

1.DMA ON

2. ADC ON

3.configureiece register X

4.Write reggister y

5. wait ms

6. read something 

something like this??!

AvaTar
Lead
Posted on May 26, 2015 at 12:14

is there any Diagram where I can see, what and when I have to set for using Perepheri?!?

 

Perhaps in the

http://r.duckduckgo.com/l/?kh=-1&uddg=http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/CD00225773.pdf

?

sven
Associate II
Posted on May 26, 2015 at 12:49

no, there I can't see something like this

AvaTar
Lead
Posted on May 26, 2015 at 13:32

no, there I can't see something like this

 

Of course it's there.

Nobody said it will leap to your eye immediately. You will have to read the document.

And if you plan to spend some more time on this MCU, you will need it anyway.

sven
Associate II
Posted on May 26, 2015 at 14:36

yes, I think with Xmega its much easier, because more hrlp from the community :(

Now I have this, but it run about 1 to 5 seconds then the ADC freeze... And I can't see anything like I asked into the Reference!!!

Startet once
ADC1EN_bit :=1;
ADON_bit :=1; // ADC on/off
delay_ms(100);
this is into the loop
CONT_bit :=1; // use continius measurement
ADC1_CR2 := %00000000000000000000000100000011;
ADC_CCR := %00000000000000110000111100000000;
ADC1_SQR3 := %00000000000000000000000000000001;
ADC1_CR2 := %01000000000000000000000000000011;
delay_ms(1);
while EOC1_bit = 0 DO nop;
value := ADC1_DR;

sven
Associate II
Posted on May 26, 2015 at 15:30 now it works 🙂 there was something, that should only use once..but I put it into the loop.. Only one is this

Procedure ADC_Init;
Begin
ADON_bit :=1; // ADC on/off
CONT_bit :=1; // use continius measurement
ADC1EN_bit :=1;
//ADC1_CR2 := %00000000000000000000000100000011;
ADC1_CR1 := %00000000000000000000000000000000;
ADC_CCR := %00000000110000010000000000000000;
ADC1_SQR3 := %00000000000000000000000000000001;
ADC1_CR2 := %01000000000000000000000000000011;
SWSTART_bit:=1;
delay_ms(1);
end;

and then the loop

while EOC1_bit = 0 DO nop;
// delay_ms(5);
value := ADC1_DR;

I think it's not really correct..but with this it works..the rest will be much easier 🙂
raptorhal2
Lead
Posted on May 26, 2015 at 15:31

Use the examples in the Standard Peripheral Library as a guide to the steps required.

Not many Forum responders will take the time to check register level code.

Cheers, Hal