Stm32 ADC rule multi-channel Conversion

Source: Internet
Author: User

After reading this code, I finally understood what the rule multi-channel conversion is, and how it is implemented as a whole. Code:

/*************************************** ****************************************

* Function name: Main

* Description: Main Program

* Input: None

* Output: None

* Return: None

**************************************** ***************************************/

Int main (void)

{

# Ifdef debug

Debug ();

# Endif


/* System clocks configuration ---------------------------------------------*/

Rcc_configuration ();


/* Configure C ------------------------------------------------------*/

Nvic_configuration ();


/* Gpio configuration ------------------------------------------------------*/

Gpio_configuration ();


Lcdshow_init ();


/* Dma1 channel1 configuration ----------------------------------------------*/

Dma_deinit (dma1_channel1 );

Dma_initstructure.dma_peripheralbaseaddr = adc1_dr_address; // peripheral address

Dma_initstructure.dma_memorybaseaddr = (u32) adc_rcvtab; // memory address

Dma_initstructure.dma_dir = dma_dir_peripheralsrc; // One-way DMA Transmission Direction

Dma_initstructure.dma_buffersize = 160; // set the DMA buffer length during transmission. Word

Dma_initstructure.dma_peripheralinc = dma_peripheralinc_disable; // sets the auto-increment mode of the DMA peripherals.

Dma_initstructure.dma_memoryinc = dma_memoryinc_enable; // set the memory increment mode of DMA,

Dma_initstructure.dma_peripheraldatasize = dma_peripheraldatasize_halfword; // The length of the peripheral data.

Dma_initstructure.dma_memorydatasize = dma_memorydatasize_halfword; // Memory Data Length

Dma_initstructure.dma_mode = dma_mode_circular; // set the DMA transmission mode: continuous loop mode

Dma_initstructure.dma_priority = dma_priority_high; // sets the priority of DMA.

Dma_initstructure.dma_m2m = dma_m2m_disable; // set the variables in the two memory databases of DMA to access each other.

Dma_init (dma1_channel1, & dma_initstructure );



/* Enable dma1 channel1 */

Dma_cmd (dma1_channel1, enable );


/* Adc1 configuration ------------------------------------------------------*/

Adc_initstructure.adc_mode = adc_mode_independent; // standalone Mode

Adc_initstructure.adc_scanconvmode = Enable; // scan mode

Adc_initstructure.adc_continuousconvmode = Enable; // Continuous Conversion

Adc_initstructure.adc_externaltrigconv = adc_externaltrigconv_none; // disable External triggering

Adc_initstructure.adc_dataalign = adc_dataalign_right; // right-aligned data

Adc_initstructure.adc_nbrofchannel = 8; // number of channels used for conversion

Adc_init (adc1, & adc_initstructure );


/* Adc1 regular channels configuration [Rule mode channel configuration] */

Adc_regularchannelconfig (adc1, adc_channel_8, 1, adc_sampletime_239cycles5 );

Adc_regularchannelconfig (adc1, adc_channel_9, 2, adc_sampletime_239cycles5 );

Adc_regularchannelconfig (adc1, adc_channel_10, 3, adc_sampletime_239cycles5 );

Adc_regularchannelconfig (adc1, adc_channel_11, 4, adc_sampletime_239cycles5 );

Adc_regularchannelconfig (adc1, adc_channel_12, 5, adc_sampletime_239cycles5 );

Adc_regularchannelconfig (adc1, adc_channel_13, 6, adc_sampletime_239cycles5 );

Adc_regularchannelconfig (adc1, adc_channel_14, 7, adc_sampletime_239cycles5 );

Adc_regularchannelconfig (adc1, adc_channel_15, 8, adc_sampletime_239cycles5 );


/* Enable adc1 DMA [enable adc1 DMA] */

Adc_dmacmd (adc1, enable );



/* Enable adc1 [enable adc1] */

Adc_cmd (adc1, enable );


/* Enable adc1 reset calibaration register */

Adc_resetcalibration (adc1 );

/* Check the end of adc1 reset calibration register */

While (adc_getresetcalibrationstatus (adc1 ));


/* Start adc1 calibaration */

Adc_startcalibration (adc1 );

/* Check the end of adc1 calibration */

While (adc_getcalibrationstatus (adc1 ));



/* Start adc1 software conversion */

Adc_softwarestartconvcmd (adc1, enable );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.