<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[SPI模拟时序波形]]></title><description><![CDATA[<h1>1. 版本</h1>
<p dir="auto">Config Tool Version：2.7.8<br />
ME05 SDK version：1.4.0<br />
EVB version: YTM32B1ME0-EVB-Q144 Rev.C</p>
<h1>2.前言</h1>
<p dir="auto">有客户需要用MCU引脚输出特定波形进行通信，如下图：<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/9d7acd0f-8dc0-4bab-823d-7e04de834669.png" alt="54fe2b5d-4f3f-43d4-83e2-a5cf1d39d48c-image.png" class=" img-fluid img-markdown" /><br />
MCU没有特定的硬件外设可以输出这种波形，使用IO模拟会很占用CPU资源，但是<strong>用SPI进行组帧可以模拟出这种波形</strong>。<br />
通过调整SPI的波特率和帧间隔时间去满足它的时序要求。</p>
<h1>3.方案</h1>
<p dir="auto">固定发送特定的组帧，即用一个SPI帧去模拟一bit时序，如下图：<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/3f5bb605-0985-411a-9605-7536841783bc.png" alt="c1612f8c-76fe-46d0-ba39-c568f64b541f-image.png" class=" img-fluid img-markdown" /><br />
设定SPI的帧长度（Framesize）为6，0码 高电平/低电平时间：1/2；1码 高电平/低电平时间：2/1.</p>
<h2>3.1 波特率计算</h2>
<p dir="auto">如上时序中1bit的理想时间是720ns，我们假设是750ns，即SPI一帧750ns，<br />
那SPI的1bit就是 750ns/6 = 125ns，可得SPI的波特率为1 / 125ns = 1 / 0.000 000 125 = 8M.即设定SPI的波特率为8M最合适。</p>
<h1>4.  示例工程配置</h1>
<h2>4.1 SPI时钟配置</h2>
<p dir="auto">功能时钟选择PLL, 120M时钟, 3分频，所以SPI的功能时钟为40M.<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/0ca6009e-8177-4e93-96a6-b1288d561163.png" alt="278d4ba8-cd11-4da1-acd5-6dbf5778f475-image.png" class=" img-fluid img-markdown" /></p>
<h2>4.2 SPI功能配置</h2>
<p dir="auto">这里只考虑主机发送的配置：<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/04a8d3ac-b67c-43db-83e9-785f34bbd28b.png" alt="fde763e0-db49-4f03-92d5-bb3a8fc4a656-image.png" class=" img-fluid img-markdown" /><br />
因为要尽量满足时钟波形连续无间隔，需要对CS2CLK,CLK2CS,Frame2Frame进行微调，这里都设置1。<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/6656cd93-85f0-4db3-aaa5-412d7af20838.png" alt="1bdf13d4-bad8-4daf-9b43-187bd7247988-image.png" class=" img-fluid img-markdown" /><br />
设置为Frame2Frame讲个刚好为60ns，与时钟线的负脉宽基本一样<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/b4dad4ba-73f3-4021-82e8-e02aec3d83ec.png" alt="b8834884-cfc8-48c4-97ae-91e783fa09b5-image.png" class=" img-fluid img-markdown" /></p>
<h2>4.3 码元转换函数</h2>
<p dir="auto">此函数可将16进制数据转化为对应的码元数据，方便SPI发送函数传参。<br />
比如说0x23，它的二进制数据是0010 0011，转换后的数据数组就是<br />
{0x30， 0x30，0x3C， 0x30， 0x30， 0x30，0x3C， 0x3C}<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/1c55ac14-dbe7-47b0-bce5-da2bab6d2f35.png" alt="e35dc1bd-fddb-44c8-877b-15305751dd52-image.png" class=" img-fluid img-markdown" /></p>
<h1>5. 实测波形</h1>
<h2>5.1 发送全0数据：</h2>
<p dir="auto">T0H典型值：250ns。<br />
T0L典型值：500ns。<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/622228dd-d472-4703-a024-87a2f75c7f90.png" alt="5f946a40-374b-46a4-ab9d-a9daf0cc8f83-image.png" class=" img-fluid img-markdown" /></p>
<h2>5.2 发送全1数据：</h2>
<p dir="auto">T1H典型值：500ns。<br />
T1L典型值：250ns。<br />
<img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/53f3969a-1486-4171-b6ac-9b2673d594fe.png" alt="d79c86bd-3f64-4827-b6dd-3f1b48a23ef5-image.png" class=" img-fluid img-markdown" /></p>
<h2>5.3 随机数据</h2>
<p dir="auto"><img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/47c1b3fd-28c1-45f1-abd3-3606ef4fee40.png" alt="12f2b216-ff1b-4829-84fc-fb75ba6ab282-image.png" class=" img-fluid img-markdown" /></p>
<h2>5.4 Reset码</h2>
<p dir="auto"><img src="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/b64dfcf0-80fd-48af-96a8-dca144296907.png" alt="249495ab-18ee-414f-8cfa-1859fa161ae5-image.png" class=" img-fluid img-markdown" /></p>
<h1>6. 示例工程</h1>
<p dir="auto"><a href="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/671/d8bd9adf-66ea-438d-b9f5-a1949029f1d7.zip" rel="nofollow ugc">SPI模拟时序波形.zip</a></p>
]]></description><link>https://forum.ytmicro.com/topic/1908/spi模拟时序波形</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Apr 2026 14:04:28 GMT</lastBuildDate><atom:link href="https://forum.ytmicro.com/topic/1908.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Apr 2026 08:52:28 GMT</pubDate><ttl>60</ttl></channel></rss>