stm32 learning nine

Publisher:Huanle666Latest update time:2016-10-14 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
USART real-time display voltage value:

Mainly the writing of adc.h and adc.c files (written as add.h and add.c during the experiment)

After debugging for a whole morning, I found that the clock was set wrongly. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_ADC1,ENABLE);

It is set to APB1, so only 0v can appear. Beware! ! !

The add.h code is as follows:

#ifndef _ADD_H
#define _ADD_H

#include "stm32f10x.h"

void ADC_Configure();

#endif

 

The add.c code is as follows:

#include "add.h"
#define ADC1_DR_Address ((u32)0x40012400 + 0x4C)

__IO uint16_t ADC_ConvertedValue;


static void ADC_GPIO_Config()
{
  
 GPIO_InitTypeDef GPIO_InitStructure;

 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 ,ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_ADC1,ENABLE);

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
 GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_1;
    GPIO_Init(GPIOC,&GPIO_InitStructure);

}
static void ADC_DMA_Config()
{
 ADC_InitTypeDef ADC_InitStructure;
 DMA_InitTypeDef  DMA_InitStructure;

 DMA_DeInit(DMA1_Channel1);
 DMA_InitStructure.DMA_BufferSize = 1; 
 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
 DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;
 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
 DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
 DMA_InitStructure.DMA_PeripheralInc =  DMA_PeripheralInc_Disable;
 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
 DMA_Init(DMA1_Channel1,&DMA_InitStructure);
 DMA_Cmd(DMA1_Channel1, ENABLE);
 
 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
 ADC_InitStructure.ADC_NbrOfChannel = 1;
 ADC_InitStructure.ADC_ScanConvMode = DISABLE;
 ADC_Init(ADC1,&ADC_InitStructure);


 
 RCC_ADCCLKConfig(RCC_PCLK2_Div8);
 ADC_RegularChannelConfig(ADC1,ADC_Channel_11,1,ADC_SampleTime_55Cycles5);

    ADC_DMACmd(ADC1,ENABLE);
 ADC_Cmd(ADC1,ENABLE);

 ADC_ResetCalibration(ADC1);
 while(ADC_GetResetCalibrationStatus(ADC1));

 ADC_StartCalibration(ADC1);
 while(ADC_GetCalibrationStatus(ADC1));

 ADC_SoftwareStartConvCmd(ADC1,ENABLE);
}


void ADC_Configure()
{
 ADC_GPIO_Config();
 ADC_DMA_Config();
}

 

The usart.h code is as follows:

#ifndef _USART_H
#define _USAET_H
#include
void Usart_GPIO_Config(void);
int fputc(int ch,FILE *f);

#endif


The usart.c code is as follows:

#include "usart.h"
#include "stm32f10x.h"

void Usart_GPIO_Config()
{
 USART_InitTypeDef USART_InitStructure;
 GPIO_InitTypeDef GPIO_InitStructure;
 
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA,&GPIO_InitStructure);

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
 GPIO_Init(GPIOA,&GPIO_InitStructure); //Note that this must be added for unclear reasons

 USART_InitStructure.USART_BaudRate = 115200;
 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 
 USART_InitStructure.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;
    USART_InitStructure.USART_Parity = USART_Parity_No;
 USART_InitStructure.USART_StopBits = USART_StopBits_1;
 USART_InitStructure.USART_WordLength = USART_WordLength_8b;
 USART_Init(USART1,&USART_InitStructure);
    USART_Cmd(USART1,ENABLE);
}


int fputc(int ch,FILE *f)
{
   USART_SendData(USART1,(unsigned char)ch);
   while(!(USART1->SR & USART_FLAG_TXE));
   return ch;
}


The main.c code is as follows:

/******************** (C) COPYRIGHT 2013 ******************************
 * File name: main.c
 * Description: Project template built with version 3.5.0.         
 * Experimental platform: WildFire STM32 development board
 * Library version: ST3.5.0
 *
 
 * Version: v1.0
**********************************************************************************/
#include "stm32f10x.h"
#include "add.h"  
#include "usart.h"
void delay(__IO uint32_t count);

extern __IO uint16_t ADC_ConvertedValue;

float ADC_ConvertedValueLocal;

/* 
 * Function name: main
 * Description: Main function
 * Input: None
 * Output: None
 */
int main(void)
{
   Usart_GPIO_Config();
   ADC_Configure();        
  
     while(1)
   {
      ADC_ConvertedValueLocal =(float) ADC_ConvertedValue/4096*3.3; // Read the converted AD value
 
   printf("\r\n The current AD value = 0x%04X \r\n", ADC_ConvertedValue); 
   printf("\r\n The current AD value = %f V \r\n",ADC_ConvertedValueLocal); 
   delay(0x01fffff0);

   }
   // add your code here ^_^。
}
/******************* (C) COPYRIGHT 2013 *****END OF FILE************/
void delay(__IO uint32_t count)
{
 for(;count>0;count--);
}

 

stm32 learning nine - yuanzhaoming901030@126 - wit_yuans space
Keywords:STM32 Reference address:stm32 learning nine

Previous article:stm32 learning ten
Next article:STM32 learning six

Recommended ReadingLatest update time:2024-11-15 23:56

STM32 emulates I2C
Use STM32 to access ferroelectric memory of I2C interface, FM24CL16, 2K bytes ====================================  I2C pin configuration:  /* Configure I2C1 pins: SCL and SDA */    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;    GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz;    GPIO_InitStructur
[Microcontroller]
STM32F2 series USART learning
Notes on F2 series USART initialization: The peripheral files needed are: stm32f2xx_usart.c; //Serial port corresponding function stm32f2xx_gpio.c; //GPIO initialization stm32f2xx_rcc.c; //Clock initialization misc.c; //Interrupt initialization Initialization mainly includes 8 parts. 1. Enable GPIO clock: RCC_AHB1Peri
[Microcontroller]
STM32 timer (basic timer) operation register version
Timer Nature The essence of a timer: a counter The composition of the timer: clock source + counter + reload value 1. Timer of stm32    The number of stm32 timers is large and the functions are powerful; different timers have different functions.    The timers of stm32 are divided into three categories: ① ba
[Microcontroller]
STM32 timer (basic timer) operation register version
STM32_TIM timing-interrupt
Today we will explain the timing-interrupt function of the STM32F103 timer. We will add the TIM3 timing function to yesterday’s timer delay software project. You can also try to add and modify yesterday’s project.   Today's software engineering download address (360 cloud disk): https://yunpan.cn/cPnJ9KYcXbPsP   Acce
[Microcontroller]
STM32_TIM timing-interrupt
STM32-External Interrupt Study Notes
Interrupt Classification                                                                                                                                          The STM32 EXTI controller supports 19 external interrupt/event requests. Each interrupt has a status bit, and each interrupt/event has independent trigger an
[Microcontroller]
STM32-External Interrupt Study Notes
Comparing stm32 and arm9 research direction
During the winter break of my sophomore year, I was invited by my teacher to go to Dongguan for an internship for 10 days. Although it was not my first time, the experience this time was very different from the last time. I wanted to write this article after returning from Dongguan, but I have been putting it off unti
[Microcontroller]
Stm32 floating point operation crash solution
I need to build some floating point operations in the soft core (PS) of the SOC, but I found that the system crashed after 6 simulations. How you simulate, how you die! Modify the code as follows alright!
[Microcontroller]
Stm32 floating point operation crash solution
Design of digital encryption recording pen based on STM32
  With the widespread application of digital signal processing technology in electronic products, the confidentiality of voice information has also become an important research direction in the field of information processing. The digitization process of analog audio signals includes sampling, quantization and encodin
[Microcontroller]
Design of digital encryption recording pen based on STM32
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components
Guess you like

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号