cancel
Showing results for 
Search instead for 
Did you mean: 

ADC init.

pvi
Associate
Posted on September 22, 2008 at 08:35

ADC init.

2 REPLIES 2
pvi
Associate
Posted on May 17, 2011 at 12:45

Hi,

I'm in the process of making a data logger to store converted ADC-values on the SD card.

The board I'm using is the STM3210B-EVAL/A.

I have managed to get the STR7 fat demo indicated by STOne-32 (thanks btw.) working and I've managed to get ADC values read from the potmeter and printed through the UART in two separate projects, but when I combine both nothing works.

I believe the ADC example does way more than I want it to do.

All I want to do is sample the ADC every so often using for example ADC_GetConversionValue(ADC1) That would mean it wouldn't be in continuous mode.

What do I need to inialize it properly?

On previous µcs I've used(AVR, AVR32), all you needed was to set the mode,rate and port, and it would be ready to go. On this µc it seems that I have to set-up all kinds of clocks I don't fully understand yet, as it is not very well documented(they're assuming we know ARM well enough, I guess).

What is the bare minimum I would need to set the ADC to one port, start a conversion and read it? Please don't say ''Google it'', I've tried :p

Thanks in advance,

Pascal Viala

[ This message was edited by: pvi on 19-09-2008 09:33 ]

stevemelnikoff9
Associate II
Posted on May 17, 2011 at 12:45

Use a state machine with 4 states. Here's some psuedo-code. Note that you have to use the right DMA channel for whichever ADC you're using.

Code:

First state:

Turn on ADC (CR2: ADON)

Second state:

Start calibration (CR2: CAL | ADON)

Third state:

Wait until calibration has completed (CR2: CAL)

Set number of channels (SQR1)

Select conversion order (SQR3:SQx)

Set channel sample times (SMPRx)

Enable continuous conversion and DMA (CR2: ADC_CR2_TSVREFE | ADC_CR2_CONT | ADC_CR2_DMA | ADC_CR2_ADON)

Enable scan mode (CR1: ADC_CR1_SCAN)

DMA setup:

Set peripheral address (DMA_Channel1->CPAR = &ADC1->DR)

Set memory address (DMA_Channel1->CMAR = where you want to store the result);

Set number of data (DMA_Channel1->CNDTR = number of channels)

Configure: periph-to-mem; very high priority; memory size 16 bits;

peripheral size 16 bits; memory incremented;

peripheral not incremented; circular mode; read from memory;

enable

DMA_Channel1->CCR = 0

| DMA_CCRx_PL_VeryHigh

| DMA_CCRx_MSIZE_16bits

| DMA_CCRx_PSIZE_16bits

| DMA_CCRx_MINC

| DMA_CCRx_CIRC

| DMA_CCRx_EN;

/* Go (write 1 to ADON when it's already 1, with no other changes) */

ADC1:CR2 = ADC1:CR2;

Fourth state:

Do nothing! It all happens in the background

Steve.