Home > other >  ADC + UART serial port output: no, don't read, ADC conversion: no, nothing
ADC + UART serial port output: no, don't read, ADC conversion: no, nothing

Time:03-19

 
ADC. C file

# include "Adc. H"
__IO uint16_t ADC_ConvertedValue;

Void ADC_GPIO_Config (void)
{
GPIO_InitTypeDef GPIO_InitStructre;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA, ENABLE);

GPIO_InitStructre. GPIO_Pin=GPIO_Pin_1;
GPIO_InitStructre. GPIO_Mode=GPIO_Mode_AIN;

GPIO_Init (GPIOA, & amp; GPIO_InitStructre);
}

Void ADC_MODE_Config (void)
{
ADC_InitTypeDef ADC_InitStructre;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_ADC1, ENABLE);

ADC_InitStructre. ADC_Mode=ADC_Mode_Independent;
ADC_InitStructre. ADC_ScanConvMode=DISABLE;
ADC_InitStructre. ADC_ContinuousConvMode=ENABLE;
ADC_InitStructre. ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;
ADC_InitStructre. ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStructre. ADC_NbrOfChannel=1;

ADC_Init (ADC1, & amp; ADC_InitStructre);

//the Main: 96 MHZ=12 MHZ (ADC - TIME)//the Main: 72 MHZ=9 MHZ (ADC - TIME)
RCC_ADCCLKConfig (RCC_PCLK2_Div8);
ADC_RegularChannelConfig (ADC1, ADC_Channel_1, 1, ADC_SampleTime_55Cycles5);

ADC_ITConfig (ADC1, ADC_IT_EOC, ENABLE);
ADC_Cmd (ADC1, ENABLE);

ADC_StartCalibration (ADC1);
While (ADC_GetCalibrationStatus (ADC1));

ADC_SoftwareStartConvCmd (ADC1, ENABLE);
}

Void ADC_NVIC_Config (void)
{
NVIC_InitTypeDef NVIC_InitStructre;

NVIC_PriorityGroupConfig (NVIC_PriorityGroup_1);

NVIC_InitStructre. NVIC_IRQChannel=ADC1_2_IRQn;
NVIC_InitStructre. NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructre. NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructre. NVIC_IRQChannelSubPriority=1;
NVIC_Init (& amp; NVIC_InitStructre);
}

Void ADC_IRQHandler (void)
{
If (ADC_GetITStatus (ADC1, ADC_IT_EOC)==SET)
{
ADC_ConvertedValue=https://bbs.csdn.net/topics/ADC_GetConversionValue (ADC1);
}
ADC_ClearITPendingBit (ADC1, ADC_IT_EOC);
}

 
ADC. H file

# # ifndef ADC_H
# define ADC_H

# include "stm32f10x. H"
Void ADC_GPIO_Config (void);
Void ADC_MODE_Config (void);
Void ADC_NVIC_Config (void);
Void ADC_IRQHandler (void);

# endif


 
USART. C file

# include "Usart. H"
# include "stdio.h"

Void Usart_Config ()
{
GPIO_InitTypeDef GPIO_InitStructre;
USART_InitTypeDef USART_InitStructre;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);

GPIO_InitStructre. GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructre. GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructre. GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init (GPIOA, & amp; GPIO_InitStructre);

GPIO_InitStructre. GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructre. GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, & amp; GPIO_InitStructre);

USART_InitStructre. USART_BaudRate=9600;
USART_InitStructre. USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructre. USART_Mode=USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructre. USART_Parity=USART_Parity_No;
USART_InitStructre. USART_StopBits=USART_StopBits_1;
USART_InitStructre. USART_WordLength=USART_WordLength_8b;
USART_Init (USART1, & amp; USART_InitStructre);

USART_ITConfig (USART1, USART_IT_RXNE, ENABLE);
USART_Cmd (USART1, ENABLE);
}

Void USART_NVIC_Config ()
{
NVIC_InitTypeDef NVIC_InitStructre;

NVIC_PriorityGroupConfig (NVIC_PriorityGroup_2);
NVIC_InitStructre. NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructre. NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructre. NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructre. NVIC_IRQChannelSubPriority=2;
NVIC_Init (& amp; NVIC_InitStructre);
}

Void USART_SendBye (under-16 BYE)
{
USART_SendData (USART1, BYE);
While (USART_GetFlagStatus (USART1, USART_FLAG_TXE)==RESET);
}

Word void USART_SendString (char *)
{
U8 I=0;
While (1)
{
If (word [I]!=0)
{
USART_SendData (USART1, word [I]);
While (USART_GetFlagStatus (USART1, USART_FLAG_TXE)==RESET);
i++;
}
The else return;
}
}

Void USART_IRQHandler ()
{
Uint8_t RES;
If (USART_GetITStatus (USART1, USART_IT_RXNE)!=RESET)
{
RES=USART_ReceiveData (USART1);
USART_SendData (USART1, RES);
}
If (USART_GetFlagStatus (USART1, USART_IT_RXNE)!=RESET)
{
USART_ClearITPendingBit (USART1, USART_IT_RXNE);
}
}

Int fputc (int ch, FILE * F)
{
USART_SendData (USART1, (unsigned char) ch);
While (USART_GetFlagStatus (USART1, USART_FLAG_TXE)==RESET);
Return ch;
}

Int fgetc (FILE * F)
{
While (USART_GetFlagStatus (USART1, USART_FLAG_RXNE)==RESET);
Return (int), USART_ReceiveData (USART1);
}


 
USART. H file

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull