CH32V103 gpio 範例
时间: 2023-08-10 13:06:48 浏览: 157
CH32V103核心板资料.rar
CH32V103的GPIO示例可以参考以下代码:
```c
#include "ch32v103.h"
void GPIO_Init(void) {
// 使能GPIOA和GPIOB的时钟
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN;
// 配置PA4、PA5、PA6、PA7为复用功能
GPIOA->CRL &= ~(GPIO_CRL_MODE4 | GPIO_CRL_MODE5 | GPIO_CRL_MODE6 | GPIO_CRL_MODE7);
GPIOA->CRL |= GPIO_CRL_CNF4_1 | GPIO_CRL_CNF5_1 | GPIO_CRL_CNF6_1 | GPIO_CRL_CNF7_1;
// 配置PB13、PB14、PB15为复用功能
GPIOB->CRH &= ~(GPIO_CRH_MODE13 | GPIO_CRH_MODE14 | GPIO_CRH_MODE15);
GPIOB->CRH |= GPIO_CRH_CNF13_1 | GPIO_CRH_CNF14_1 | GPIO_CRH_CNF15_1;
}
```
这段代码初始化了CH32V103的GPIO功能。其中,PA4、PA5、PA6、PA7被配置为复用功能,而PB13、PB14、PB15也被配置为复用功能。这样,你就可以使用这些引脚进行SPI通信了。
#### 引用[.reference_title]
- *1* [国产沁恒CH32F103C8T6使用指南](https://blog.csdn.net/qq_52127343/article/details/120803973)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [STM32F103RB 实作笔记(九)- PWM + SPI +MAX6675 整合试验 (正点原子 STM32F103 nano开发板)程式解析](https://blog.csdn.net/weixin_45889834/article/details/124173753)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文