我有带1兆赫时钟的ATTiny。我在试着点亮一些ws2812b引导的条子。我把所有没有电阻和电容的东西汇合在一起。我认为一切都应该正常工作,但并不是这样:)我正在使用light_ws2812库https://github.com/cpldcpu/light_ws2812。下面是示例代码。我只挂F_CPU频率,输出引脚的数字和重置时间在配置文件中。你能帮我找出问题并给我建议怎么解决吗?
主
#define F_CPU 1000000
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "ws2812_config.h"
#include "light_ws2812.h"
struct cRGB led[2];
int main(void)
{
uint8_t pos=0;
uint8_t direction=1;
uint8_t i;
#ifdef __AVR_ATtiny10__
CCP=0xD8; // configuration change protection, write signature
CLKPSR=0; // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10)
#endif
led[0].r=255;led[0].g=00;led[0].b=00; // LED 0 is red
led[1].r=255;led[1].g=16;led[1].b=16; // LED 1 is White
while(1)
{
for (i=0; i<pos; i++)
ws2812_sendarray((uint8_t *)&led[0],3); // Repeatedly send "red" to the led string.
// No more than 1-2µs should pass between calls
// to avoid issuing a reset condition.
for (i=0; i<(16-pos); i++)
ws2812_sendarray((uint8_t *)&led[1],3); // white
_delay_ms(50); // Issue reset and wait for 50 ms.
pos+=direction;
if ((pos==16)||(pos==0)) direction=-direction;
}
}配置
/*
* light_ws2812_config.h
*
* v2.4 - Nov 27, 2016
*
* User Configuration file for the light_ws2812_lib
*
*/
#ifndef WS2812_CONFIG_H_
#define WS2812_CONFIG_H_
///////////////////////////////////////////////////////////////////////
// Define Reset time in µs.
//
// This is the time the library spends waiting after writing the data.
//
// WS2813 needs 300 µs reset time
// WS2812 and clones only need 50 µs
//
///////////////////////////////////////////////////////////////////////
#define ws2812_resettime 50
///////////////////////////////////////////////////////////////////////
// Define I/O pin
///////////////////////////////////////////////////////////////////////
#define ws2812_port B // Data port
#define ws2812_pin 3 // Data out pin
#endif /* WS2812_CONFIG_H_ */发布于 2019-11-30 17:46:08
我认为1 1Mhz太慢,无法产生WS2812B所需的信号。
最关键的WS2812B信号-- TH0脉冲--必须小于500 is宽,在1 1Mhz时,每个单片机周期为1000 is。
更多关于WS2812B时间限制的信息.
https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
发布于 2019-11-30 23:50:32
串联电阻和并联电容器确实有助于减少噪音,造成莫名其妙的行为。但是你是对的,它不应该阻止WS2812bs完全工作。
我建议你在你的命运上再试试别针。插脚3用于usb通信。如果您是通过连接到您的计算机的usb电缆供电,这将造成麻烦。例如,试试引脚5和6。
您可以尝试Adafruit_NeoPixel库。我试着编译了attiny85,没有做任何修改。我实际上并没有试图运行它,因为我没有一个命运躺在周围。
此外,易趣上的一些更便宜的WS2812b分类条被他们的Din和Dout标签转换了。这意味着你必须连接达特销到你的命运。这件事其实曾经发生在我身上。
我不知道WS2812bs中的脉冲长度,但如果不是这个问题,我很确定这是我前面提到的三个问题之一。
希望这能有所帮助。
发布于 2019-12-04 05:41:39
解决方案
根据自述,我已经在我的主源代码文件中包括了头之前的配置文件。这是一个错误,因为这两个文件是不同编译单元的一部分,它们之间没有共享定义。这会导致我的配置设置被忽略,程序使用默认设置(在我的情况下不正确)。
要修复这个错误,您应该将ws2812_config.h包含在light_ws2812.h中。
https://stackoverflow.com/questions/59114513
复制相似问题