ADUCM331开发笔记(一)GPIO的使用与Blinky例程

2023-11-01 21:59

本文主要是介绍ADUCM331开发笔记(一)GPIO的使用与Blinky例程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

ADUCM331开发笔记(一)GPIO的使用与Blinky例程

  • ADUCM331开发笔记(一)GPIO的使用与Blinky例程
    • GPIO的使用说明
      • GENERAL-PURPOSE DIGITAL INPUTS/OUTPUTS OVERVIEW
      • GENERAL-PURPOSE DIGITAL INPUTS/OUTPUTS FEATURES
      • GENERAL-PURPOSE DIGITAL PORT MULTIPLEX
      • GENERAL PURPOSE DIGITAL INPUT/OUTPUT OPERATION
        • Digital Port Multiplexed Configuration多种模式配置
        • GPIO Pull-Up Enable上拉使能
        • GPIO Data In输入
        • Open Circuit Enable开路使能
        • GPIO Data Out输出
        • Bit Set位置位
        • Bit Clear位清零
        • Bit Toggle位翻转
        • GPIO Data Output Enable输出使能
      • GPIO MEMORY MAPPED REGISTERS寄存器列表及其内存映射
        • GPIO Configuration Register配置寄存器GP0CON
        • GPIO Output Enable Register输出使能寄存器GP0OEN
        • GPIO Output Pull-Up Enable Register上拉使能寄存器GP0UPL
        • GPIO Open Circuit Enable Register开路使能寄存器GP0OCE
        • GPIO Input Data Register输入数据寄存器GP0INR
        • GPIO Data Out Register输出寄存器GP0OUT
        • GPIO Data Out Set RegisterGP0SET输出置位寄存器GP0SET
        • GPIO Data Out Clear Register输出清零寄存器GP0CLR
        • GPIO Pin Toggle Register输出翻转寄存器GP0TGL
    • Blinky例程代码
      • RTE设置
      • RTE代码
      • 芯片头文件
      • 绝对地址使用
      • GPIO初始化设置
      • 中断时钟
      • 中断处理函数

ADUCM331开发笔记(一)GPIO的使用与Blinky例程

ADUCM331开发笔记,记录每天的进展。

GPIO的使用说明

ADuCM330/ADuCM331 Hardware Reference Manual UG-716

GENERAL-PURPOSE DIGITAL INPUTS/OUTPUTS OVERVIEW

The ADuCM330/ADuCM331 feature six, bidirectional, general-purpose input/output (GPIO) pins. All of the GPIO pins have multiple
functions, configurable by user code. These features are described in Table 143.
Each GPIO pin can be configured as an input, output, or open circuit. These pins also have an internal, pull-up, programmable resistor.
See the ADuCM330/ADuCM331 data sheet for logic input voltages and absolute maximum values. For optimum low power operation,
the GPIOs must be configured as inputs (using GP0OEN) and with pull-up resistors enabled (using GP0PUL).
When the ADuCM330/ADuCM331 enter a power saving mode, the GPIO pins retain their state.
Note that a driving peripheral is not able to drive these pins.

GENERAL-PURPOSE DIGITAL INPUTS/OUTPUTS FEATURES

• Six, bidirectional, general-purpose input/output (GPIO) pins
• Internally multiplexed with SPI and LIN configurations available

GENERAL-PURPOSE DIGITAL PORT MULTIPLEX

This block provides control over the GPIO functionality of specified pins, because some of the pins can work as GPIOs or have other
specific functions. The following tables detail the configuration modes for each GPIO.

Table 143. GPIO Multiplex
某产品GPIO电路如下,可见该产品的GPIO没有使用。如果后续需要使用GPIO0口,即Pin4,作为一路数字量输入,则需要电路上稍作变更,并把GPIO0的Configuration Modes设置为00。
某产品ADUCM331芯片GPIO电路

GENERAL PURPOSE DIGITAL INPUT/OUTPUT OPERATION

Digital Port Multiplexed Configuration多种模式配置

The pin functions are configured using the GP0CON register. The GP0CON register configures Port 0. External interrupts and input level signals (GP0IN) are available in any configuration modes, except when the GPIOs are configured as open circuit and as outputs (GP0OE = 1 and GP0OCE = 1).
引脚功能使用 GP0CON 寄存器进行配置。GP0CON 寄存器配置端口 0。除非 GPIO 配置为开路和输出 (GP0OE = 1 和 GP0OCE = 1)之外,其他任何配置模式中外部中断和输入电平信号 (GP0IN) 均可用
GP0CON寄存器用于配置Port0,包括P0.0到P0.5六个Pin脚。

GPIO Pull-Up Enable上拉使能

All GPIO pins have an internal pull-up resistor. Using the GP0PUL register, it is possible to enable/disable pull-up registers on the pins
when they are configured as inputs. The pull-up resistors are automatically disabled when the pad is set as an output or when open circuit
is enabled.
所有 GPIO 引脚都有一个内部上拉电阻。当引脚配置为输入时。使用 GP0PUL 寄存器可以启用/禁用引脚上的上拉寄存器。当引脚设置为输出或开路时,上拉电阻自动禁用。

GPIO Data In输入

When configured as an input (by default), the GPIO input levels are available in GP0IN.

Open Circuit Enable开路使能

This disables the input paths if the pin is set as output. To disable the input and not drive the pin, the open circuit must be set and drive
Logic 1. External interrupts interrupt are not available when open circuit is enabled.

GPIO Data Out输出

When the GPIOs are configured as outputs, the values in GP0OUT are reflected on the GPIOs.

Bit Set位置位

Bit set is used to set one or more GPIO data outputs without affecting others within a port. Only the GPIO corresponding with the write
data bit equal to one is set; the remaining GPIOs are unaffected.

Bit Clear位清零

Bit clear is used to clear one or more GPIO data outputs without affecting others within a port. Only the GPIO corresponding with the
write data bit equal to one is cleared; the remaining GPIOs are unaffected.

Bit Toggle位翻转

Bit toggle is used to toggle one or more GPIO data outputs without affecting others within a port. Only the GPIO corresponding with the
write data bit equal to one is toggled; the remaining GPIOs are unaffected.

GPIO Data Output Enable输出使能

The data output path is enabled; the values in GP0OUT are reflected on the GPIOs.

GPIO MEMORY MAPPED REGISTERS寄存器列表及其内存映射

ADUCM331芯片GPIO寄存器列表及其内存映射

GPIO Configuration Register配置寄存器GP0CON

Address: 0x40006000, Reset: 0x0000, Name: GP0CON
默认模式都设置为00。
ADUCM331芯片GPIO配置寄存器GP0CON位描述

GPIO Output Enable Register输出使能寄存器GP0OEN

Address: 0x40006004, Reset: 0x00, Name: GP0OEN
默认都设置为输入
ADUCM331芯片GPIO输出使能寄存器GP0OEN位描述

GPIO Output Pull-Up Enable Register上拉使能寄存器GP0UPL

Address: 0x40006008, Reset: 0x3F, Name: GP0PUL
0x3F = 0B 0011 111103,默认使能上拉电阻
上拉使能寄存器

GPIO Open Circuit Enable Register开路使能寄存器GP0OCE

Address: 0x4000600C, Reset: 0x00, Name: GP0OCE
开路使能寄存器

GPIO Input Data Register输入数据寄存器GP0INR

Address: 0x40006014, Reset: 0xX1, Name: GP0INR
输入数据寄存器

GPIO Data Out Register输出寄存器GP0OUT

Address: 0x40006018, Reset: 0x00, Name: GP0OUT
数据输出寄存器

GPIO Data Out Set RegisterGP0SET输出置位寄存器GP0SET

Address: 0x4000601C, Reset: 0x00, Name: GP0SET
数据输出置位寄存器

GPIO Data Out Clear Register输出清零寄存器GP0CLR

Address: 0x40006020, Reset: 0x00, Name: GP0CLR
数据输出清零寄存器

GPIO Pin Toggle Register输出翻转寄存器GP0TGL

Address: 0x40006024, Reset: 0x00, Name: GP0TGL
数据输出翻转寄存器

Blinky例程代码

Blinky.c主函数比较简单

// includes
#include "RTE_Components.h"             // Component selection
#include <absacc.h>const unsigned int iPage0CS[2] __at(0x07f8) = {0xffffffff,0x16400000};	// for direct startup from Kernel
void GPIO_INIT(void);
//=====================================================================
// 						main
//=====================================================================
int main (void)
{T3CON = 0;  								// Turn off watchdogGPIO_INIT();SysTick_Config(0x320000);while(1){}
}

RTE设置

前面包含"RTE_Components.h" ,这个文件是通过下列设置自动添加到路径、并且复制实体文件到的。
Manage Run-Time Environment设置本地Project文件夹下自动添加RTE目录及相关文件
工程中自动添加RTE文件

RTE代码

主要是引用芯片头文件

#ifndef RTE_COMPONENTS_H
#define RTE_COMPONENTS_H/** Define the Device Header File: */
#define CMSIS_device_header "ADuCM331.h"/* AnalogDevices::Device:Startup:1.0.0 */
#include <ADuCM331.h>#endif /* RTE_COMPONENTS_H */

芯片头文件

ADuCM331.h文件位置在Keil安装目录下,导入芯片Pack包的时候复制过去的。
ADuCM331.h位置
打开芯片头文件ADuCM331.h,可以看到GPIO寄存器的名称和地址定义。

// GPIO#define          GPIOBASE                                   (*(volatile unsigned long      *) 0x40006000)
#define          GPIOBASE_A                                 0x40006000
// GPIO Port 0 configuration
#define          GP0CON                                     (*(volatile unsigned short int *) 0x40006000)
#define          GP0CON_A                                   0x40006000
// GPIO Port 0 output enable
#define          GP0OEN                                     (*(volatile unsigned char      *) 0x40006004)
#define          GP0OEN_A                                   0x40006004
// GPIO Port 0 output pull up enable
#define          GP0PUL                                     (*(volatile unsigned char      *) 0x40006008)
#define          GP0PUL_A                                   0x40006008
// GPIO Port 0 open circuit enable
#define          GP0OCE                                     (*(volatile unsigned char      *) 0x4000600C)
#define          GP0OCE_A                                   0x4000600C
#if           ALLOW_DEPRECATED_NAMES
// "GP0ODE" has been deprecated. Use "GP0OCE" instead.
#define          GP0ODE                                     (*(volatile unsigned char      *) 0x4000600C)
#define          GP0ODE_A                                   0x4000600C
#endif
// GPIO Port 0 input data
#define          GP0INR                                     (*(volatile unsigned char      *) 0x40006014)
#define          GP0INR_A                                   0x40006014
// GPIO Port 0 data out
#define          GP0OUT                                     (*(volatile unsigned char      *) 0x40006018)
#define          GP0OUT_A                                   0x40006018
// GPIO Port 0 data out set
#define          GP0SET                                     (*(volatile unsigned char      *) 0x4000601C)
#define          GP0SET_A                                   0x4000601C
// GPIO Port 0 data out clear
#define          GP0CLR                                     (*(volatile unsigned char      *) 0x40006020)
#define          GP0CLR_A                                   0x40006020
// GPIO Port 0 pin toggle
#define          GP0TGL                                     (*(volatile unsigned char      *) 0x40006024)
#define          GP0TGL_A                                   0x40006024
#if           ALLOW_DEPRECATED_NAMES
// "GP0TOG" has been deprecated. Use "GP0TGL" instead.
#define          GP0TOG                                     (*(volatile unsigned char      *) 0x40006024)
#define          GP0TOG_A                                   0x40006024
#endif

绝对地址使用

头文件absacc.h定义了绝对地址的调用语法。

#ifndef __at
#define __at(_addr)  __attribute__ ((at(_addr)))#endif#ifndef __section
#define __section(_name)  __attribute__ ((section(_name)))#endif

也就是说,下面两句话是一样的

const unsigned int iPage0CS[2]  __at(0x07f8) = {0xffffffff,0x16400000}
const unsigned int iPage0CS[2]  __attribute__ ((at(0x07f8))) = {0xffffffff,0x16400000}

GPIO初始化设置

再看一眼主函数

int main (void)
{T3CON = 0;  								// Turn off watchdogGPIO_INIT();SysTick_Config(0x320000);while(1){}
}

可以看到,主函数的内容,主要是调用GPIO_INIT(),以及设置中断时钟。

GPIO_INIT()的主要内容,是设置 GP0CON、GP0PUL、GP0OEN三个寄存器。

//=====================================================================
void GPIO_INIT(void)
{
// 将P0.0到P0.5的配置模式设置为GPIOGP0CON = 0x00;	   						// Enable as GPIOs// 0x33=0B0011 0011,将P0.2和P0.3的上拉使能关闭GP0PUL = 0x33;							// Activate pull ups// 0x0C = 0B 0000 1100,将P0.2和P0.3设置为输出GP0OEN = 0x0C;							// Enable GPIOs as o/p's
}

参考开发板实物和说明文档,GPIO1, GPIO2, GPIO3 接了LED灯.
ADUCM331开发板实物
开发板GPIO跳线说明

中断时钟

头文件AduCM331.h中,在第84行引用了core_cm3.h

#include <core_cm3.h>                       /*!< Cortex-M3 processor and core peripherals */
#include "system_ADUCM331.h"               /*!< ADUCM331 System                      */

core_cm3.h是ARM M3核的标准库文件,里面关于中断部分的功能代码如下。

/* ##################################    SysTick function  ############################################ */
/**\ingroup  CMSIS_Core_FunctionInterface\defgroup CMSIS_Core_SysTickFunctions SysTick Functions\brief    Functions that configure the System.@{*/#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)/**\brief   System Tick Configuration\details Initializes the System Timer and its interrupt, and starts the System Tick Timer.Counter is in free running mode to generate periodic interrupts.\param [in]  ticks  Number of ticks between two interrupts.\return          0  Function succeeded.\return          1  Function failed.\note    When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then thefunction <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>must contain a vendor-specific implementation of this function.*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk){return (1UL);                                                   /* Reload value impossible */}SysTick->LOAD  = (uint32_t)(ticks - 1UL);                         /* set reload register */NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */SysTick->VAL   = 0UL;                                             /* Load the SysTick Counter Value */SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |SysTick_CTRL_TICKINT_Msk   |SysTick_CTRL_ENABLE_Msk;                         /* Enable SysTick IRQ and SysTick Timer */return (0UL);                                                     /* Function successful */
}#endif/*@} end of CMSIS_Core_SysTickFunctions */

中断处理函数

中断处理函数将GPIO2和GPIO3输出电平翻转,实现亮灭。

//=====================================================================
// 						SYSTICK handler
//=====================================================================
void SysTick_Int_Handler(void)
{GP0TGL = 0x08;                             // 0x08 = 0B 0000 1000,将P0.3翻转GP0TGL = 0x04;                             // 0x08 = 0B 0000 0100,将P0.2翻转
}

时钟和中断的处理,准备另外再写一篇。

这篇关于ADUCM331开发笔记(一)GPIO的使用与Blinky例程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/326032

相关文章

使用Python实现可恢复式多线程下载器

《使用Python实现可恢复式多线程下载器》在数字时代,大文件下载已成为日常操作,本文将手把手教你用Python打造专业级下载器,实现断点续传,多线程加速,速度限制等功能,感兴趣的小伙伴可以了解下... 目录一、智能续传:从崩溃边缘抢救进度二、多线程加速:榨干网络带宽三、速度控制:做网络的好邻居四、终端交互

Python中注释使用方法举例详解

《Python中注释使用方法举例详解》在Python编程语言中注释是必不可少的一部分,它有助于提高代码的可读性和维护性,:本文主要介绍Python中注释使用方法的相关资料,需要的朋友可以参考下... 目录一、前言二、什么是注释?示例:三、单行注释语法:以 China编程# 开头,后面的内容为注释内容示例:示例:四

Go语言数据库编程GORM 的基本使用详解

《Go语言数据库编程GORM的基本使用详解》GORM是Go语言流行的ORM框架,封装database/sql,支持自动迁移、关联、事务等,提供CRUD、条件查询、钩子函数、日志等功能,简化数据库操作... 目录一、安装与初始化1. 安装 GORM 及数据库驱动2. 建立数据库连接二、定义模型结构体三、自动迁

ModelMapper基本使用和常见场景示例详解

《ModelMapper基本使用和常见场景示例详解》ModelMapper是Java对象映射库,支持自动映射、自定义规则、集合转换及高级配置(如匹配策略、转换器),可集成SpringBoot,减少样板... 目录1. 添加依赖2. 基本用法示例:简单对象映射3. 自定义映射规则4. 集合映射5. 高级配置匹

Spring 框架之Springfox使用详解

《Spring框架之Springfox使用详解》Springfox是Spring框架的API文档工具,集成Swagger规范,自动生成文档并支持多语言/版本,模块化设计便于扩展,但存在版本兼容性、性... 目录核心功能工作原理模块化设计使用示例注意事项优缺点优点缺点总结适用场景建议总结Springfox 是

嵌入式数据库SQLite 3配置使用讲解

《嵌入式数据库SQLite3配置使用讲解》本文强调嵌入式项目中SQLite3数据库的重要性,因其零配置、轻量级、跨平台及事务处理特性,可保障数据溯源与责任明确,详细讲解安装配置、基础语法及SQLit... 目录0、惨痛教训1、SQLite3环境配置(1)、下载安装SQLite库(2)、解压下载的文件(3)、

使用Python绘制3D堆叠条形图全解析

《使用Python绘制3D堆叠条形图全解析》在数据可视化的工具箱里,3D图表总能带来眼前一亮的效果,本文就来和大家聊聊如何使用Python实现绘制3D堆叠条形图,感兴趣的小伙伴可以了解下... 目录为什么选择 3D 堆叠条形图代码实现:从数据到 3D 世界的搭建核心代码逐行解析细节优化应用场景:3D 堆叠图

Springboot如何正确使用AOP问题

《Springboot如何正确使用AOP问题》:本文主要介绍Springboot如何正确使用AOP问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录​一、AOP概念二、切点表达式​execution表达式案例三、AOP通知四、springboot中使用AOP导出

Navicat数据表的数据添加,删除及使用sql完成数据的添加过程

《Navicat数据表的数据添加,删除及使用sql完成数据的添加过程》:本文主要介绍Navicat数据表的数据添加,删除及使用sql完成数据的添加过程,具有很好的参考价值,希望对大家有所帮助,如有... 目录Navicat数据表数据添加,删除及使用sql完成数据添加选中操作的表则出现如下界面,查看左下角从左

python 常见数学公式函数使用详解(最新推荐)

《python常见数学公式函数使用详解(最新推荐)》文章介绍了Python的数学计算工具,涵盖内置函数、math/cmath标准库及numpy/scipy/sympy第三方库,支持从基础算术到复杂数... 目录python 数学公式与函数大全1. 基本数学运算1.1 算术运算1.2 分数与小数2. 数学函数