Arm Community
Arm Community
  • Site
  • User
  • Site
  • Search
  • User
  • Groups
    • Research Collaboration and Enablement
    • DesignStart
    • Education Hub
    • Innovation
    • Open Source Software and Platforms
  • Forums
    • AI and ML forum
    • Architectures and Processors forum
    • Arm Development Platforms forum
    • Arm Development Studio forum
    • Arm Virtual Hardware forum
    • Automotive forum
    • Compilers and Libraries forum
    • Graphics, Gaming, and VR forum
    • High Performance Computing (HPC) forum
    • Infrastructure Solutions forum
    • Internet of Things (IoT) forum
    • Keil forum
    • Morello Forum
    • Operating Systems forum
    • SoC Design and Simulation forum
    • 中文社区论区
  • Blogs
    • AI and ML blog
    • Announcements
    • Architectures and Processors blog
    • Automotive blog
    • Graphics, Gaming, and VR blog
    • High Performance Computing (HPC) blog
    • Infrastructure Solutions blog
    • Innovation blog
    • Internet of Things (IoT) blog
    • Operating Systems blog
    • Research Articles
    • SoC Design and Simulation blog
    • Tools, Software and IDEs blog
    • 中文社区博客
  • Support
    • Arm Support Services
    • Documentation
    • Downloads
    • Training
    • Arm Approved program
    • Arm Design Reviews
  • Community Help
  • More
  • Cancel
中文社区
中文社区
中文社区博客 NucleoF429 基础应用1: TIM1+ADC+USART 波形显示
  • Blogs
  • Forum
  • 视频和文件
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • Jump...
  • Cancel
  • New
中文社区 requires membership for participation - click to join
More blogs in 中文社区
  • ARM中国大学计划博客

  • Arm新闻

  • 中文mbed博客

  • 中文社区博客

  • 恩智浦汽车电子MCU讨论区博客

 

Tags
  • chinese
  • nucleof429
  • tim
  • adc
  • 中文
  • usart
  • stm32f4
Actions
  • RSS
  • More
  • Cancel
Related blog posts
Related forum threads

NucleoF429 基础应用1: TIM1+ADC+USART 波形显示

Xiaoya
Xiaoya
June 7, 2016
1 minute read time.

  上次竞答获赠的NucleoF429到手好几天了,陆续看了一些资料,180MHz的主频比起之前48MHz/72MHz的芯片来说,性能提升不少,外设功能也一应俱全。但也没玩什么高端的(比如图像处理,跑OS等),也体现不出180M的性能优势来。所以还是按照惯例,先跑一个简单的Demo再说。(上次拿到F031K6时,说要做一个USART的波形显示,后来一忙也忘了,这次顺便补上。)

  这个Demo主要功能是使用Timer定时触发ADC采样,通过USART发送数据到PC显示波形。

一、初始化和外设选择

  1.1、还是使用STM32CubeMX,选中NucleoF429,ADC选择IN0,对应PA0脚

  

  1.2、时钟输入选择Bypass。开发板默认没有焊接外部高速晶振,Bypass的时钟是STlink的那颗芯片输出的,这里也可以不选,默认使用16MHz的内部RC震荡,但Datasheet上说最大有1%的偏差。

     

  1.3、Timer选择TIM1,最基本的计时功能,也可以选择Systick做计时

     

  1.4、USART选择Usart3,但开发板上连接STlink虚拟串口的TX和RX是PD8和PD9,所以手动修改PD8和PD9为Usart3的TX和RX

     

OK,外设选择完毕,接下来配置时钟和外设参数。

二、时钟和外设参数配置

  1、STM32CubeMX的时钟树配置起来简单明了,需要注意的是F429的时钟MCO输入的,所以Input Frequency改为8Mhz,其他时钟按需选择,频率越高功耗越大,因为ADC使用的是PCLK2,所以注意选择PCLK2的频率,关系到采样速度,后面讲怎么算ADC采样率。我的时钟配置如下图:

     

2、配置单个外设的参数:

     

  2.1、USART3

  参数分别为:115200bps、8bit、无校验、1个停止位。

     

  2.2、ADC

  因为我只需要一路ADC,所以不需要多通道扫描(另有规则通道和注入通道方式,详情参照相关Datasheet和书籍)。为了方便控制采样率,使用定时器触发,不需要连续转换,即转换一次停止,等待下一次启动转换。

    ADC有主要的几个参数:

2.2.1 、ADC时钟:PCLK2的4分频。之前PCLK2已被配置为了90MHz,所以这里的ADC时钟周期为90/4= 22.5Mhz,一个时钟周期为1/22.5Mhz = 0.0444444... us

ADC的总转换时间Tconv = 采样时间+12个周期,采样时间可选,比如这里ADC时钟为22.5M,采样时间选择56个周期,则一次AD转换时间为 Tconv =(1/22.5)*(56+12)= 3.0222..us

2.2.2、ADC分辨率:12Bit。另外还有10/8/6Bit可选,位数越低转换时间越短。

2.2.3、数据对齐:右对齐

2.2.4、其他选项都选Disabled,

2.3、Timer1

TIM1是为了定时触发ADC转换,事实上TIM1可以直接配置为ADC触发源,自动触发,但这里还是使用原始的方式,即TIM定时时间到,手动启动ADC转换,

  

  TIM1是在APB2总线上,APB2总线为180M,通过180分频后为1M,即1us,再累加计时1000次,则TIM1每次中断为1ms,TIM1中断为Update 类型

    

  2.4、NVIC:

       NVIC中只需要开启RCC、TIM1和ADC中断即可。

    

通过以上简单的设置,所需要的功能都已具备,设置输出目录和IDE类型,即可生成Project(我使用的是Keil)

三、Keil编程

用Keil打开上面生成的Project,先编译一边,无误。在STM32F4xx_it.c文件中找到TIM1和ADC中断服务程序

再顺着中断找到各自的回调函数:

这是ADC转换完成的函数,在这个函数中读出ADC的值即可。void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){} 可以Copy到main.c或者其他文件中。

TIM中断中包含不同的中断类型,这里只需用到了 TIM Update event 这个类型,同样 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){}可以Copy到main.c或其他文件中。

在这两个中断函数中添写程序完成相应的功能。在HAL_TIM_PeriodElapsedCallback中用HAL_ADC_Start_IT(&hadc1);开启ADC中断,启动转换,转换一次后停止,等待下次启动,

转换结束后会发生ADC中断,在HAL_ADC_ConvCpltCallback中读取ADC的值,读取ADC的值做简单滤波后通过USART发送到PC(我做了个简单的IIR滤波),PC端的软件接收特定格式的数据后显示波形即可,下图是波形显示效果图。

波形显示软件和此Demo Code在附件中,通信格式在程序中,查看便知。PS:这个波形显示软件在需要实时看一些数据变化时,会比较直观,可以收藏备用。

以上只是一个简单的Demo,也体现不了F429的优势,尤其是数据处理方面的,期待各位同学的分享。

再P个S:感谢 ARM中文社区 赠送的开发板和版主songbin 辛苦辛苦。

我们还有一个微信群:中文社区微信交流群 欢迎加入!

6296.zip
Anonymous
中文社区博客
  • Arm A-Profile构架2022扩展

    Zenon Xiu (修志龙)
    Zenon Xiu (修志龙)
    原文:Arm A-Profile Architecture Developments 2022 - Architectures and Processors blog - Arm Community blogs - Arm Community  作者:Martin Weidmann翻译:修志龙(Zenon Xiu) 与arm构架授权和生态伙伴一起,arm持续演进其构架,开发新功能以满足现有和新市场的要求…
    • October 17, 2022
  • 深入理解 Arm A-profile的non-maskable interrupt -NMI

    Zenon Xiu (修志龙)
    Zenon Xiu (修志龙)
    原文: https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/a-profile-non-maskable-interrupts  翻译: 修志龙 Zenon Xiu Arm A-profile构架一个长久以来的局限性是:缺乏对non-maskable interrupt (NMI…
    • August 24, 2022
  • Arm A-Profile 构架2021扩展

    Zenon Xiu (修志龙)
    Zenon Xiu (修志龙)
    原文: https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-a-profile-architecture-developments-2021 Martin Weidmann September 8, 2021 翻译注释:Zenon Xiu Arm与arm构架授权公司及生态伙伴一起…
    • August 17, 2022