Chủ Nhật, 31 tháng 3, 2019

[ Học ARM-Bài3 ] ADC STM32 với Standard Peripheral Library

Author: Cong Neb
Alias: Dark Neb
Studied at: SET BKHN K57
Nếu copy tài liệu: Nhớ ghi nguồn tác giả..Tk


Registers:

__IO uint32_t SR
__IO uint32_t CR1
__IO uint32_t CR2
__IO uint32_t SMPR1
__IO uint32_t SMPR2
__IO uint32_t JOFR1
__IO uint32_t JOFR2
__IO uint32_t JOFR3
__IO uint32_t JOFR4
__IO uint32_t HTR
__IO uint32_t LTR
__IO uint32_t SQR1
__IO uint32_t SQR2
__IO uint32_t SQR3
__IO uint32_t JSQR
__IO uint32_t JDR1
__IO uint32_t JDR2
__IO uint32_t JDR3
__IO uint32_t JDR4

__IO uint32_t DR


Các bước khởi tạo ADC

1.  Enable the ADC interface clock using

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADCx, ENABLE);
2.  ADC pins configuration
3.  Configure the ADC Prescaler, conversion resolution and data alignment using  the ADC_Init() function.

4.  Activate the ADC peripheral using ADC_Cmd() function.

Các function chính

1.ADC_DeInit
void ADC_DeInit ( void )



2.ADC_Init
void ADC_Init ( ADC_TypeDef *  ADCx, ADC_InitTypeDef * ADC_InitStruct)

3.ADC_CommonInit
void ADC_CommonInit ( ADC_CommonInitTypeDef *  ADC_CommonInitStruct)

4. ADC_Cmd
void ADC_Cmd ( ADC_TypeDef *  ADCx, FunctionalState  NewState)

5.ADC_TempSensorVrefintCmd
void ADC_TempSensorVrefintCmd ( FunctionalState  NewState)

Mục đích:  Enables or disables cảm biến nhiệt độ nội và Vref channels.

NewState:ENABLE or DISABLE

6. ADC_RegularChannelConfig
void ADC_RegularChannelConfig ( ADC_TypeDef *  ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)

ADC_Channel:
ADC_Channel_0 :  ADC Channel0 selected
ADC_Channel_1 :  ADC Channel1 selected
ADC_Channel_2 :  ADC Channel2 selected
ADC_Channel_3 :  ADC Channel3 selected
ADC_Channel_4 :  ADC Channel4 selected
ADC_Channel_5 :  ADC Channel5 selected
ADC_Channel_6 :  ADC Channel6 selected
ADC_Channel_7 :  ADC Channel7 selected
ADC_Channel_8 :  ADC Channel8 selected
ADC_Channel_9 :  ADC Channel9 selected




Ví dụ

RCC_APB2PeriphClockCmd ( RCC_APB2Periph_ADC1, ENABLE);

ADC_InitTypeDef  ADC_InitDef;
ADC_CommonInitTypeDef   ADC_CommonInitDef;

// Config ADC single mode
ADC_CommonInitDef.ADC_Mode = ADC_Mode_Independent;

/* ADCCLK = PCLK2/2 */
ADC_CommonInitDef.ADC_Prescaler = ADC_Prescaler_Div2;

ADC_CommonInitDef.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

/* Delay between 2 sampling phases */
ADC_CommonInitDef.ADC_TwoSamplingDelay = ADC.TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStruct);


/* Configure ADC1 to convert continously channel14 *

ADC_InitDef.ADC_Resolution = ADC_Resolution_12b;
ADC_InitDef.ADC_ScanConvMode = DISABLE;
ADC_InitDef.ADC_ContinuousConvMode = ENABLE;
ADC_InitDef.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitDef.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitDef.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStruct);

/* ADC1 regular channel 14 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1,
ADC_SampleTime_3Cycles);
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);

/* Enable ADC1's DMA interface */
ADC_DMACmd(ADC1, ENABLE);

/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);

/* Start ADC1 Software Conversion */
ADC_SoftwareStartConv(ADC1);

//done

Contact me 

Facebook :https://www.facebook.com/congneb94

Không có nhận xét nào:

Đăng nhận xét