请选择 进入手机版 | 继续访问电脑版

你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【NUCLEO-L496ZG评测】+ 2)GPIO测试方法

[复制链接]
beebird 提问时间:2017-4-3 16:41 /
本帖最后由 beebird 于 2017-4-3 16:45 编辑


【NUCLEO-L496ZG评测】+ 1)开发环境搭建
【NUCLEO-L496ZG评测】+ 2)GPIO测试方法

    我本小菜,所以写的测评也比较low,还望各位大神指导。对于GPIO的测试有两种方法。一.使用【NUCLEO-L496ZG评测】+ 1) 开发环境搭建中所介绍的使用STM32CubeMX生成基本的项目代码,然后在Keil uVision5中根据功能需求改代码。二.直接使用官网下载的GPIO例程,如图“例程所在的位置”。点击Project.uvprojx打开工程后编译即可。
剪切项目中的代码如下:
  1. int main(void)
  2. {
  3.   /* This sample code shows how to use GPIO HAL API to toggle LED1 and LED2 IOs
  4.     in an infinite loop. */

  5.   /* STM32L4xx HAL library initialization:
  6.        - Configure the Flash prefetch
  7.        - Systick timer is configured by default as source of time base, but user
  8.          can eventually implement his proper time base source (a general purpose
  9.          timer for example or other time source), keeping in mind that Time base
  10.          duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  11.          handled in milliseconds basis.
  12.        - Set NVIC Group Priority to 4
  13.        - Low Level Initialization
  14.      */
  15.   HAL_Init();

  16.   /* Configure the system clock to 80 MHz */
  17.   SystemClock_Config();
  18.   
  19.   /* -1- Enable GPIO Clock (to be able to program the configuration registers) */
  20.   LED1_GPIO_CLK_ENABLE();
  21.   LED2_GPIO_CLK_ENABLE();

  22.   /* -2- Configure IO in output push-pull mode to drive external LEDs */
  23.   GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;
  24.   GPIO_InitStruct.Pull  = GPIO_PULLUP;
  25.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  26.   GPIO_InitStruct.Pin = LED1_PIN;
  27.   HAL_GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStruct);
  28.   GPIO_InitStruct.Pin = LED2_PIN;
  29.   HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);

  30.   /* -3- Toggle IO in an infinite loop */
  31.   while (1)
  32.   {
  33.     HAL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN);
  34.     /* Insert delay 100 ms */
  35.     HAL_Delay(100);
  36.     HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
  37.     /* Insert delay 100 ms */
  38.     HAL_Delay(100);
  39.   }
  40. }
复制代码
    例程实现的功能时LED1亮灭交替,100ms后LED2亮灭交替,100ms后LED1亮灭交替...如此循环。





例程所在的位置.jpg
工程的结构.jpg
收藏 1 评论1 发布时间:2017-4-3 16:41

举报

1个回答
黑溱郎 回答时间:2017-6-27 10:33:02
谢谢分享。。。。。。

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版