<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SPI on 吾思 梦阁</title><link>https://wstek.win/tags/spi/</link><description>Recent content from 吾思 梦阁</description><generator>Hugo</generator><language>zh-cn</language><managingEditor>wusitech@qq.com (WuSi09)</managingEditor><webMaster>wusitech@qq.com (WuSi09)</webMaster><copyright>本博客所有文章除特别声明外，均采用 BY-NC-SA 许可协议。转载请注明出处！</copyright><lastBuildDate>Fri, 06 Nov 2026 23:59:00 +0800</lastBuildDate><atom:link href="https://wstek.win/tags/spi/index.xml" rel="self" type="application/rss+xml"/><item><title>STM32 SPI：四线协议、四种模式与 W25Q64 读写</title><link>https://wstek.win/posts/stm32-spi/</link><pubDate>Wed, 04 Nov 2026 19:30:00 +0800</pubDate><author>wusitech@qq.com (WuSi09)</author><guid>https://wstek.win/posts/stm32-spi/</guid><description>
<![CDATA[<h1>STM32 SPI：四线协议、四种模式与 W25Q64 读写</h1><p>作者：WuSi09（wusitech@qq.com）</p>
        
          <p>总结自：<a href="https://www.bilibili.com/video/BV1th411z7sn">STM32入门教程-2023版</a> 第 11 章前半（11-1 ~ 11-3）。</p>
<p>代码基于 <strong>STM32F103C8T6 + STM32F10x 标准外设库 3.5.0</strong>（API 已按 STM32F10x StdPeriph 3.5 头文件核对；Delay/OLED/Key 为课程配套驱动），不包含新建工程和接线步骤。</p>
<table>
  <thead>
      <tr>
          <th>视频</th>
          <th>视频里讲了什么</th>
          <th>本文对应</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>11-1</td>
          <td>SPI 通信、硬件电路、移位示意图、时序基本单元（模式 0~3）</td>
          <td>0x00 ~ 0x20</td>
      </tr>
      <tr>
          <td>11-2</td>
          <td>W25Q64 简介、容量/引脚/框图、指令表、状态寄存器、时序</td>
          <td>0x30</td>
      </tr>
      <tr>
          <td>11-3</td>
          <td>软件 SPI 读写 W25Q64（代码）</td>
          <td>0x40 ~ 0x60</td>
      </tr>
  </tbody>
</table>
<p>视频之外还补了：多从机片选、时钟频率与建立保持时间、页写跨页、数据校验、测速、ID/UID、12 条故障排查。</p>
<h2 id="0x00-spi-是什么">
<a class="header-anchor" href="#0x00-spi-%e6%98%af%e4%bb%80%e4%b9%88"></a>
0x00 SPI 是什么
</h2><p><a class="article-gallery-item" href="/images/posts/stm32-spi/spi-intro.webp"><img src="/images/posts/stm32-spi/spi-intro.webp" alt="SPI 总线与常见模块" loading="lazy" decoding="async" onload="this.parentNode.dataset.pswpWidth=this.naturalWidth;this.parentNode.dataset.pswpHeight=this.naturalHeight"></a>
</p>
<p>SPI（Serial Peripheral Interface）是 Motorola 开发的一种<strong>同步、全双工</strong>串行总线，四根线：</p>
<ul>
<li><strong>SCK</strong>（Serial Clock）：时钟，由主机产生；</li>
<li><strong>MOSI</strong>（Master Output Slave Input）：主机发、从机收；</li>
<li><strong>MISO</strong>（Master Input Slave Output）：从机发、主机收；</li>
<li><strong>SS</strong>（Slave Select）：片选，低电平有效。</li>
</ul>
<p>和 I2C 相比：SPI 没有地址、没有应答，靠<strong>独立的片选线</strong>选设备；速度快（几十 MHz）、协议简单，但引脚多。</p>
        
        <hr><p>本文2026-11-04首发于<a href='https://wstek.win/'>吾思 梦阁</a>，最后修改于2026-11-06</p>]]></description><category>STM32</category></item><item><title>STM32 硬件 SPI：外设、连续传输、DMA 与 W25Q64</title><link>https://wstek.win/posts/stm32-spi-hw/</link><pubDate>Wed, 04 Nov 2026 21:00:00 +0800</pubDate><author>wusitech@qq.com (WuSi09)</author><guid>https://wstek.win/posts/stm32-spi-hw/</guid><description>
<![CDATA[<h1>STM32 硬件 SPI：外设、连续传输、DMA 与 W25Q64</h1><p>作者：WuSi09（wusitech@qq.com）</p>
        
          <p>总结自：<a href="https://www.bilibili.com/video/BV1th411z7sn">STM32入门教程-2023版</a> 第 11 章后半（11-4、11-5）。</p>
<p>代码基于 <strong>STM32F103C8T6 + STM32F10x 标准外设库 3.5.0</strong>（API 已按 STM32F10x StdPeriph 3.5 头文件核对；Delay/OLED/Key 为课程配套驱动），不包含新建工程和接线步骤。</p>
<table>
  <thead>
      <tr>
          <th>视频</th>
          <th>视频里讲了什么</th>
          <th>本文对应</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>11-4</td>
          <td>SPI 外设简介、框图、主模式全双工连续传输、非连续传输、状态寄存器</td>
          <td>0x00 ~ 0x50</td>
      </tr>
      <tr>
          <td>11-5</td>
          <td>硬件 SPI 读写 W25Q64（代码、与软件对比）</td>
          <td>0x50 ~ 0x70</td>
      </tr>
  </tbody>
</table>
<p>视频之外还补了：CR1/CR2/SR 逐位说明、NSS 软件模式、DMA 刷屏、SPI 中断、W25Q64 完整驱动、12 条故障排查。</p>
<h2 id="0x00-硬件-spi-与软件-spi">
<a class="header-anchor" href="#0x00-%e7%a1%ac%e4%bb%b6-spi-%e4%b8%8e%e8%bd%af%e4%bb%b6-spi"></a>
0x00 硬件 SPI 与软件 SPI
</h2><p>软件 SPI 用 GPIO 翻转 SCK，每个位都要 CPU 执行几条指令；硬件 SPI 把移位、时钟、采样都交给外设，CPU 只读写 <code>DR</code>、等标志。</p>
<p>F103C8T6 有 <strong>SPI1 和 SPI2</strong>：</p>
<table>
  <thead>
      <tr>
          <th>外设</th>
          <th>总线</th>
          <th>默认引脚</th>
          <th>重映射</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>SPI1</td>
          <td>APB2（72 MHz）</td>
          <td>PA4(NSS)、PA5(SCK)、PA6(MISO)、PA7(MOSI)</td>
          <td>PB3/PB4/PB5</td>
      </tr>
      <tr>
          <td>SPI2</td>
          <td>APB1（36 MHz）</td>
          <td>PB12(NSS)、PB13(SCK)、PB14(MISO)、PB15(MOSI)</td>
          <td>—</td>
      </tr>
  </tbody>
</table>
<p>SPI1 重映射到 PB3/PB4/PB5 会和 JTAG 冲突，需要先关 JTAG（保留 SWD），否则 PB3/PB4 被占用。</p>
        
        <hr><p>本文2026-11-04首发于<a href='https://wstek.win/'>吾思 梦阁</a>，最后修改于2026-11-06</p>]]></description><category>STM32</category></item></channel></rss>