×

阿霍霍伊!We wanted to let you know that 必威娱乐登录平台SparkFun is closed due to an extreme weather forecast,3/13/2019.We hate to leave you out int he cold - just because we won't be in the office doesn't mean you should not place your order!请使用代码“Goneskiing”享受10%的折扣,today only!We will resume normal operations on 3/14/2019.对于给您带来的不便,我们深表歉意!

welcome to the lab

抛光速度

Sparkx产品并不像普通的SparkFun产品那样闪亮或抛光;必威娱乐登录平台我们可以更快地进入市场。你对一个没有经过完全用户测试的电路板满意吗?你能看一下说明书吗?SparkX is for you.

不失败

SparkX doesn't care if something isn't quite finished.Shoot,we're only pretty sure an idea will work.We'll let you know exactly what's known and what's tested,剩下的由你决定。Are you ok with a green wire and no beginner's guide?SparkX is for you.

去吧!

Sparkx追逐闪亮。If there's a product or 必威娱乐登录平台project that appeals to us we'll do it regardless of market considerations.想玩一些可能永远无法上市的东西吗?SparkX is for you.

SparkX Products


Experimental Products:SparkX products are rapidly produced to bring you the most cutting edge technology as it becomes available.这些产品经过测试,但没有保证。Sparkx产品不提供实时技术betway手机投注支持。
原型竖琴

原型竖琴

SPX-14799
59.95美元
7
A111脉冲雷达突破

A111脉冲雷达突破

SPX-14811
49.95美元
GPS U形接头Sam-M8Q(QWIIC)

GPS U形接头Sam-M8Q(QWIIC)

SPX-15106
29.95美元
Qwiic AS3935 Lightning Detector

Qwiic AS3935 Lightning Detector

SPX-1557
19.95美元
QWIIC构思工具包

QWIIC构思工具包

SPX-1474
$199.95
原子钟

原子钟

SPX-14830
1995美元
Magnetic Imaging Tile - 8x8

Magnetic Imaging Tile - 8x8

SPX-14652
149.95美元
QWIIC射频识别ID-XXLA

QWIIC射频识别ID-XXLA

SPX-14867
$54.95

SparkX Blog Posts


保存缓冲区

一个愚蠢的解决方案的愚蠢问题的细节:如何在使用Arduino核心库时不覆盖传出的SPI数据缓冲区

喜爱的 最喜欢的

As many fledgling makers,修补工和业余爱好者会这样做,I became deeply imprinted on addressable LEDs.我是说,即使只点亮一盏灯,也会让人感觉像是你自己的迪斯科派对,所以什么是不爱约100…500…1000 +?在我的项目中,LED的数量呈指数级增长和少量完美主义之间,必威娱乐登录平台我开始关注更新LED数据的最有效方法。这是一个关于硬件修复如何在Arduino IDE周围工作以追求最大速度的故事。

LED和速度的基础知识

After abandoning any pretense of "real world applications" and just admitting that we are obsessed with maximum performance,让我们决定如何最快地输出LED数据。这个问题从选择LED条开始。有两种主要类型的LED条带-那些具有双线控制,就像APA102,而那些只有一根电线控制的,like the WS2812B.One-wire control only uses one data line and relies on the master (your Arduino) and the slave (in this case the LEDs) to agree on a data frequency.双线控制,另一方面,uses a clock line to tell the LED exactly when the incoming data is valid.This allows much faster and more flexible communication to occur.以下是对相似和不同之处的简要概述:

双线(APA102) One Wire (WS2812B)
颜色深度(位) 二十四 二十四
亮度 Stunning Dazzling
通信 同步的 异步的
最小比特率 0赫兹 800千赫
Maximum bitrate 10 MHz+ 800千赫
60赫兹时的理论最大LED 5208 四百一十七

在很多方面,these two technologies are comparable - they're both very beautiful to look at.However,对于高速应用,双线控制方法更为优越。Next we need to consider how to actually send data out of the master as quickly as possible.

Perhaps the most obvious way to send out the data is to 'bit-bang' or toggle the pins manually.This method can be executed pretty quickly by using assembly instructions and directly accessing pin control registers,but as we 必威手机登陆learned inGo Speed Racer...Arduino Speed Test,使用ArduinodigitalWrite()函数有很多开销。Don't fret,most micros come with an easier and more reliable method.

The SPI peripheral built into microcontrollers can often output data at nearly the speed of the CPU clock,and can be configured to any combination of clock polarity and data phase - this is called theSPI Mode.通过检查APA102 Datasheetwe can see that螺旋模式3(CPHA = 1,cpol=1)是一个完美的匹配。可以,now we've figured out how to best send out data from the microcontroller.下一步是确保数据是我们想要的,so we need a way to specify the LED pixel info.这将使我们讨论我在Arduino环境中发现的问题。

模式0-3的SPI时序图

Arduino的问题

We're prepared to send data out as fast as we can,but we definitely have some strong opinions on what that data should be.尽管有很多独特的方法可以指定和存储这些数据,最简单的方法是在内存中创建一个字节数组。我甚至倾向于在脑海中想象它们沿着我的LED灯带的长度排列!To control the LEDs we will need to send out each byte in that array in order.

在最底层,everything in a microcontroller is configured,controlled and evaluated by writing data to specific places in memory called "registers." The beauty of an IDE is that it provides an interface to those registers that is far more intuitive and easier to use.The Arduino environment has a built-in library to betway手机投注support the SPI peripherals on whatever board you are using.函数传递()是Arduino提供的在SPI外围设备上发送(和接收)数据的方法。

In theArduino Reference你可以找到那个传递()有两种方法可以发送字节大小的数据。第一个是单字节写入,第二个将把每个字节写入一个称为“缓冲区”的长度为“大小”的数组。

My intuition told me that making only one function call would be more efficient,but I soon discovered an irritating problem: When using the buffer-write version,the data in your buffer will be overwritten by whatever was on the MISO line when the data was clocked out.This is intentional,当然,but it obliterates the LED data that you had just so carefully set up to display an image of a cat!下面是Arduino内部的代码:

内联静态空隙转移(空隙*buf,大小如果(count==0)返回;uint8_t *p = (uint8_t *)buf;SPDR=*P;而(--count>0)uint8_t out=*(p+1);而(!)(SPSR&BV(SPIF));uint8_t in=spdr;SPDR=OUT;* p++=in;}    while (!(SPSR & _BV(SPIF)));*p = SPDR;}

The offending snippets are (in combination)uint8_t in=spdr;* p++=in;.第一个将值从SPSR由于SPI外围设备的工作方式,需要注册和。第二个代码段覆盖缓冲区值(他们怎么敢?).

Having identified the cause of the overwrite you might see an obvious solution: Comment out* p++=in;so that your data is not overwritten,或定义调用的新函数转移输出()transferIN()按你喜欢的方式工作。This is a totally viable way to get your 必威娱乐登录平台project working,but it is not acceptable for development of Arduino libraries.

在开发库(如RGB OLED 64x64库)时,it is important to keep the "guts" of Arduino vanilla so your software can be easily used by others.Another solution could be to join the Arduino developer's email list and propose a change,but this is a process that requires a lot of consideration and agreement between other parties.Instead I needed a fast solution.

问题的代价

Do as I say,不像我做的那样。尽管我匆忙地提出了解决方案,但通常很好的做法是确保问题确实存在,好,有问题的我很幸运,在事后找到了一个合理的解决办法。在这里,我会假装我是按正确的顺序做的!

这个问题的可能解决方案是什么?

  1. 每次发送前都要填写一个缓冲区(我通常的解决方案,但感觉恶心)。
  2. Use传递()one byte at a time because it preserves the value of that byte.
  3. 开发自动保存缓冲区内容的硬件解决方案。
对于(uint16_t indi=0;indi < NUM_BYTES;indi++)buffer[indi]=value;spi.transfer(unprotectedbuffer,NUMYBACK字节;
对于(uint16_t indi=0;indi < NUM_BYTES;indi++){    SPI.tansfer(unprotectedBuffer[indi]);}
3
SPI.transfer(protectedBuffer,NUMYBACK字节;

We can define the cost of the problem as the difference between existing solutions and the most ideal solution.如果问题的成本足够大,then it is worthwhile to develop the ideal solution.在这种情况下,理想的解决方案是使用传递()function on a buffer without having to re-enforce each data value every time.I created an Arduino benchmarking sketch that tests the time it takes for these three methods to complete for a given number of bytes to transfer.

Download benchmarking sketch

我尝试使用Desmos图形计算器来可视化结果,但是对于任何数量的LED(大于约10个),结果都会变得非常线性,显示以每字节传输微秒为单位的数据速率表更有意义:

Arduino UNO Arduino UNO 青少年3.6 青少年3.6
(美国/字节) (LED/60Hz帧) (美国/字节) (LED/60Hz帧)
1,预执行 二点七二四 1529 1.022 四千零七十六
2,个人写作 2.984 一千三百九十六 零点八四三 四千九百四十
3,缓冲区保护程序 1.400 二千九百七十六 0.808 5154

I found it interesting that the rank of methods one and two switched between the two platforms,but that is a topic for another article.在毒品和犯罪问题办公室和青少年的案例中,我们看到第三种方法的速度更快——几乎是毒品和犯罪问题办公室预执行方法的两倍。

解决方案

Havingtotally证明这是一个值得利用的时间beforehand是时候提出解决方案了。The way this came to me was a lot like pure inspiration.基本上我认为,“我需要的数据显示在针脚11上,需要进入第12针…我们能把它们挂在一起吗?”我很快证明了它可以与跳线一起工作(忽略任何SPI模式和相位等的分析),然后开始比赛。My main concern was that simply connecting MOSI to MISO would prevent that SPI bus from being used for other sensors.This told me that we needed a way to electrically decide if the two lines would be connected.Atri-state buffer在低激活状态下,使能销是正确的齿轮。Here's how it looks in the schematic:

Buffer Saver schematic

Some other design features I included were the ability to force the enable pin low with a jumper,and allow for an extremely compact footprint by chopping off the part above the dashed line by placing a 5V passthrough pad on the back of the board.这些特性使Buffersaver非常适合与数据和电源线直接连接到LED灯带或单向,SPI控制显示。

替换文本

Verification

确定解决方案后,最后一步是验证解决方案。我需要确定两件事:

  • 高速(10MHz)信号可以通过缓冲区
  • That MOSI data did not affect MISO when the buffer was disabled

我写的测试草图表明,缓冲保护程序通过将APA102 LED条放置在与lis3dh加速度计相同的SPI总线上来完成它设计的工作。The Buffer Saver protects the LED data instead of having to re-write it all each time,but still allows the accelerometer to control the MISO line to send data back to the microcontroller.

下载测试草图

替换文本

This is the Buffer Saver in action!While testing everything out I realized that it was really odd to have sensors connected to the same lines as an LED strip and it got me thinking.在缓冲区保护程序的下一个版本上,将有第二个三态缓冲区,在未选择时将LED条从mosi线断开。This will allow you to control multiple unique LED strips with just one SPI port!

替换文本

I've also provided a DLA capture that shows the input and output signals when driving the LEDs at 5 MHz.如果您想更仔细地检查捕获,可以在下面下载并用打开它萨莱埃逻辑.

下载逻辑捕获

现在我很想知道是否有人想到了另一个解决方案传递()problem?您认为在一个SPI端口上可以使用两个不同的LED条带吗?

信用卡刷卡器改进:加垫片

警探又来敲门了,and this time they brought a new toy!

继续阅读

Sparkx最新最好的产品

If we've 必威手机登陆learned one thing at 必威娱乐登录平台SparkFun it's that geeks love to talk about their 必威娱乐登录平台projects!我们迫不及待地想分享我们做的菜。看看这堆新产品,sensors and breakout boards!

继续阅读

When 必威娱乐登录平台SparkFun got a shipment of 1:8 scan rate panels,it fell on me to make them work with the wrong library.

继续阅读

通过参考库传递软件I2c流

它并不漂亮,但我们已经想出了一种方法,使基于I2c的库更加灵活。现在您可以将软件I2c端口传送到库中!

继续阅读

Pretty Magnetic Fields and Pretty Labels

我们有磁砖的存货,第一块用Buzzard制造的木板也在里面!

继续阅读