1.前言
第一次用Ai-M61-32S,中途可能有失误,请多多指教
1.1 准备工作
1.2 硬件连接
使用一根可以传输数据的Type-C数据线连接开发板与电脑即可,如图所示
![IMG_20240502_131417](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/IMG_20240502_131417.jpg)
2 开始点灯
2.1 原理图
写程序之前先看一下原理图
![image-20240502131800107](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502131800107.png)
由图可得信息:
- B、R、G三个LED灯的引脚分别为IO15、IO12、IO14
- B、R、G三个LED灯接在一个地上,所以欲使LED灯点亮,IO15、IO12、IO14给一个高电平
2.2打开项目案例
首先进入GPIO案例的目录
\AiPi-Open-Kits\aithinker_Ai-M6X_SDK\examples\peripherals\gpio
然后会看到目录下有两个文件夹
![image-20240502132329290](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502132329290.png)
根据文件夹的名字可知,gpio_input_output文件夹是符合我们需要的,接下来复制该文件夹
![image-20240502132457364](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502132457364.png)
并重命名为gpio_input_outputRGB
![image-20240502132520271](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502132520271.png)
然后进入gpio_input_outputRGB文件夹,会发现如下文件
![image-20240502132624155](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502132624155.png)
然后打开CMakeLists.txt文件,修改其中的项目名称
![image-20240502132722267](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502132722267.png)
![image-20240502132808426](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502132808426.png)
将该名称修改为文件夹名称,然后点击保存(或Ctrl+S)
2.3编写mian.c
#include "bflb_gpio.h"
#include "board.h"
struct bflb_device_s *gpio;
int main(void)
{
board_init();
gpio = bflb_device_get_by_name("gpio");
bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_0);
bflb_gpio_init(gpio, GPIO_PIN_14, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_0);
bflb_gpio_init(gpio, GPIO_PIN_15, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_0);
while (1) {
bflb_gpio_set(gpio, GPIO_PIN_12);
bflb_mtimer_delay_ms(500);
bflb_gpio_reset(gpio, GPIO_PIN_12);
bflb_mtimer_delay_ms(500);
bflb_gpio_set(gpio, GPIO_PIN_14);
bflb_mtimer_delay_ms(500);
bflb_gpio_reset(gpio, GPIO_PIN_14);
bflb_mtimer_delay_ms(500);
bflb_gpio_set(gpio, GPIO_PIN_15);
bflb_mtimer_delay_ms(500);
bflb_gpio_reset(gpio, GPIO_PIN_15);
bflb_mtimer_delay_ms(500);
}
}
写完main.c之后保存关闭。
2.4 编译
点击资源管理器的地址栏
![image-20240502132957277](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502132957277.png)
接着删除地址栏内的内容
![image-20240502133051782](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502133051782.png)
然后输入CMD(全大写或者全小写均可,其他混用没试过)
![image-20240502133444165](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502133444165.png)
然后回车(Enter),打开终端
![image-20240502133553320](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502133553320.png)
然后输入make clean
![image-20240502133636077](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502133636077.png)
接着输入make
![image-20240502133859781](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502133859781.png)
发现出现两个错误
2.5 排错(无错则跳过该章节)
我们向上查看,发现错误地方
![image-20240502134021860](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502134021860.png)
根据 新手小白Ai-M61-32S各类报错解决汇总及点灯获取排错方法:
首先打开目录E:\aitkink\AiPi-Open-Kits\aithinker_Ai-M6X_SDK\bsp\board\bl616dk
高亮区域为SDK下的目录,会看到如下文件和文件夹
![image-20240502134513681](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502134513681.png)
然后打开board.c,注释掉#include "lwip/dns.h"
![image-20240502134608944](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502134608944.png)
接着再注释掉ip_addr_t dns_addr;(注意行号)
![image-20240502134651952](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502134651952.png)
然后保存关闭
接着我们回到刚刚的gpio_input_outputRGB文件夹,按照刚刚的方法打开CMD(没有关掉可以不用再打开)
接着先make clean
![image-20240502134904059](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502134904059.png)
然后再输入make
![image-20240502135006466](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502135006466.png)
看到Built target combine代表编译成功
2.6 烧录程序
保持着CMD不要关闭,然后回到桌面,鼠标右键此电脑
![image-20240502135252573](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502135252573.png)
点击管理,然后按照下图方式查看串口号
![image-20240502135526102](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502135526102.png)
由图可知我的串口号是COM7
然后我们在刚刚的命令行下输入make flash COMX=COM7,切记!不要回车!不要回车!不要回车!
然后我们按下单片机的右侧按钮,按钮左上角写着IO2的丝印,按下不要松开
然后再按下左边的按钮,按钮右上角写着EN的丝印,按一下之后松开即可,(IO2此时可以松开)
然后回车命令行开始下载
![image-20240502140005998](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/image-20240502140005998.png)
2.7 实验结果
接下来我们拔下数据线,再重新插上,实现一个物理意义的复位
就可以看到我们的代码效果,三种颜色的灯轮流点亮
![1714629773275](https://raw.githubusercontent.com/xiaoyuxuanran/images/main/1714629773275.gif)
感谢查看