更改

跳转至: 导航搜索

NBDK-L4:基础实验教程

添加8,188字节2019年2月20日 (三) 17:29
实验20-外部Flash
基础实验中的其他例程,大部分都是使用的相同的时钟配置函数,有特殊的时钟使用,将会在对应例程的源码详解中做针对性说明。
==== gyu_usartc gyu_usart.c ====
串口初始化函数,配置串口协议:波特率115200,数据位8位,停止位1位,无校验位,无流控制。
# 使用miniUSB线及10pin排线,通过Jlink仿真器连接PC端和开发板。
# 使用miniUSB线,连接PC与开发板USB接口。
# 使用Keil打开基础实验的实验18使用Keil打开基础实验的实验19-独立看门狗。窗口看门狗。
# 下载程序,并完成功能测试。
</syntaxhighlight>
== 实验20-外部Flash ==
窗口看门狗实验,STM32L4内部自带两个看门狗,分别叫做“独立看门狗(IWDG)”以及“窗口看门狗(WWDG)”。这一章节给大家介绍一下窗口看门狗的使用,窗口看门狗相对于独立看门狗的好处在于喂狗的时间精确可控,但是需要使用PCLK1的时钟,而不是独立的时钟源。对于flash芯片大家想必都不陌生,我们在使用单片机的时候,经常需要保存一些较大的数据,导致我们MCU的内部flash不够使用,因此我们需要了解如何利用外部flash去保存我们的数据,我们开发板上集成的flash芯片为W25Q80,本章节我们给大家展示如何利用STM32L476去读写这个外部的flash芯片。
=== STM32L476 SPI简介 ===
SPI接口说明:
 
SPI接口可用于使用SPI协议与外部设备通信。SPI模式可由软件选择。 器件复位后,默认选择SPI Motorola模式。
串行外设接口(SPI)协议支持与外部设备的半双工,全双工和单工同步串行通信。 接口可以配置为主设备,在这种情况下,它为外部从设备提供通信时钟(SCK)。 该接口还能够在多主机配置中运行。
 
SPI主要功能:
 
•主或从操作
 
•三条线路上的全双工同步传输
 
•两条线路上的半双工同步传输(带双向数据线)
 
•两条线上的单工同步传输(带有单向数据线)
 
•4位至16位数据大小选择
 
•多主机模式功能
 
•8个主模式波特率预分频器,最高可达fPCLK / 2。
 
•从机模式频率高达fPCLK / 2。
 
•主机和从机的硬件或软件的NSS管理:动态变化
 
主/从操作
 
•可编程时钟极性和相位
 
•可编程数据顺序,具有MSB优先或LSB优先移位
 
•具有中断功能的专用传输和接收标志
 
•SPI总线忙状态标志
 
•SPI Motorola支持
 
•硬件CRC功能,可靠通信:
 
- CRC值可以在Tx模式下作为最后一个字节发送
 
- 自动CRC错误检查最后接收的字节
 
•主模式故障,具有中断功能的溢出标志
 
•CRC错误标志
 
•两个具有DMA功能的32位嵌入式Rx和Tx FIFO
 
•SPI TI模式支持
=== 外部Flash W25Q80简介 ===
''<span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span>''W25Q80内存:8M bit / 1M byte ''<span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span>''W25Q80数据接口:SPI ''<span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span>''W25Q80 Manufacturer ID:0x13 ''<span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span>''W25Q80 Device ID:0x4014 ''<span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span>''其他具体参数及寄存器接口请大家查看:W25Q80芯片手册_EN。 
=== 硬件设计 ===
选择STM32L4 SPI1引脚(PA5、PA6、PA7),选择PB2作为flash芯片W25Q80的CSN片选引脚。
# 使用miniUSB线及10pin排线,通过Jlink仿真器连接PC端和开发板。
# 使用miniUSB线,连接PC与开发板USB接口。
# 使用Keil打开基础实验的实验18将SW1拨到USB端,SW2拨到MCU。# 使用Keil打开基础实验的实验20-独立看门狗。外部Flash。# 使用Xshell打开miniUSB虚拟出的COM口
# 下载程序,并完成功能测试。
=== 实验验证 ===
下载完成后,可以看到LED保持常亮,说明我们的程序没有被复位。而当我们注释掉HAL_WWDG_EarlyWakeupCallback()回调函数中的喂狗函数HAL_WWDG_Refresh(hwwdg),重新编译下载,可以看到LED灯周期闪烁,说明程序一直被复位(因为没有喂狗)。下载完成后,大家直接按下S2和S3按键,可以看到Xshell上打印一些乱码(因为flash还未写值,所以都是0xFF,0xFF为不可视字符)。 当我们按下S1时,向flash的0x000000地址处写入一些A,此时按下S3,可以看到Xshell打印A。 当我们按下S4时,向flash的0x001000地址处写入一些B,此时按下S2,可以看到Xshell打印B。[[文件:NBDK-XSHELL-W25Q80.png|边框|居中|无框|759x759像素]]
=== 源码详解 ===
510
个编辑

本PDF由谷雨文档中心自动生成,点击下方链接阅读最新内容。

取自“http://doc.iotxx.com/特殊:移动版差异/1627

导航菜单