ws2812x data transmission time
T0H 0 code, high level time 220ns~380ns
T0L 0 code, low level time 580ns~1.6µs
T1H 1 code, high level time 580ns~1.6µs
T1L 1 code, low level time 220ns~420µs
RES frame unit, low level time>280µs or more
For ARM_M platform @24M
1 NOP: (1/24000000)100010001000==41.67ns
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
5 NOPs 41.675 = 208.35ns (plus code execution time, barely reaches the ws2812x standard)
For n76e003 platform @16M
1 nop takes 87ns
while(1) takes 194ns
Function call takes 570ns
Note:
If the light does not change when the white light is turned on or mixed colors are turned on, you need to check whether the power supply is sufficient. If an external battery is connected, the demand is met.
If multiple lights appear to be the wrong color, first check for power supply issues.
This example is written based on 24M. Please recalculate for other frequencies.
[MCU Framework] [app_led] [WS2812x] Using soft timer to implement WS2812x flashing and breathing lighting modes
pseudocode:
temp[0] = 0xF0;
temp[1] = 0x3B;
temp[2] = 0x0F;
onewire_send_data(0, temp, 3);
1
2
3
4
/********************************************************************************
* @file onewire.c
* @author jianqiang.xue
* @Version V1.0.0
* @Date 2020-12-07
* @brief can be used for ws2812x, etc.
ws2812x data transmission time
T0H 0 code, high level time 220ns~380ns
T0L 0 code, low level time 580ns~1.6µs
T1H 1 code, high level time 580ns~1.6µs
T1L 1 code, low level time 220ns~420µs
RES frame unit, low level time>280µs or more
For ARM_M platform @16M
1 NOP: (1/24000000)*1000*1000*1000==41.67ns
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
For n76e003 platform @16M
1 nop takes 87ns
while(1) takes 194ns
Function call takes 570ns
Note: 1. If the light does not change when the white light or mixed colors are turned on, you need to check whether the power supply is sufficient. Connecting an external battery can meet the needs.
2. If multiple lights have incorrect colors, first check for power supply problems.
************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "bsp_gpio.h"
#include "sys_api.h"
#include "os_api.h"
#include "onewire.h"
#include "business_gpio.h"
#include "business_function.h"
/* Private Define ------------------------------------------------------------*/
#if 1
#define T0_BIT_SIGNAL(GPIOX, PIN)
GPIOX->ODSET=PIN;
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
GPIOX->ODCLR=PIN;
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
#define T1_BIT_SIGNAL(GPIOX, PIN)
GPIOX->ODSET=PIN;
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
GPIOX->ODCLR=PIN;
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
#define RESET_SIGNAL(GPIOX, PIN)
bsp_gpio_set_pin(GPIOX, PIN, BSP_GPIO_PIN_RESET);
delay(500);
#endif
/* Private Function Prototypes -----------------------------------------------*/
static void delay(uint16_t cnt)
{
while (cnt--)
{
__NOP();
}
}
void onewire_init(void)
{
#if BS_WS2812_CH0_EN
BS_ONEWIRE_CH0_GPIO_CLK_ENABLE();
bsp_gpio_init_output(ONEWIRE_CH0_PORT, ONEWIRE_CH0_PIN, BSP_GPIO_PIN_OUT_PP);
bsp_gpio_set_pin(ONEWIRE_CH0_PORT, ONEWIRE_CH0_PIN, BSP_GPIO_PIN_RESET);
#endif
#if BS_WS2812_CH1_EN
BS_ONEWIRE_CH1_GPIO_CLK_ENABLE();
bsp_gpio_init_output(ONEWIRE_CH1_PORT, ONEWIRE_CH1_PIN, BSP_GPIO_PIN_OUT_PP);
bsp_gpio_set_pin(ONEWIRE_CH1_PORT, ONEWIRE_CH1_PIN, BSP_GPIO_PIN_RESET);
#endif
#if BS_WS2812_CH2_EN
BS_ONEWIRE_CH2_GPIO_CLK_ENABLE();
bsp_gpio_init_output(ONEWIRE_CH2_PORT, ONEWIRE_CH2_PIN, BSP_GPIO_PIN_OUT_PP);
bsp_gpio_set_pin(ONEWIRE_CH2_PORT, ONEWIRE_CH2_PIN, BSP_GPIO_PIN_RESET);
#endif
#if BS_WS2812_CH3_EN
BS_ONEWIRE_CH3_GPIO_CLK_ENABLE();
bsp_gpio_init_output(ONEWIRE_CH3_PORT, ONEWIRE_CH3_PIN, BSP_GPIO_PIN_OUT_PP);
bsp_gpio_set_pin(ONEWIRE_CH3_PORT, ONEWIRE_CH3_PIN, BSP_GPIO_PIN_RESET);
#endif
}
void onewire_deinit(void)
{
#if BS_WS2812_CH0_EN
bsp_gpio_deinit(ONEWIRE_CH0_PORT, ONEWIRE_CH0_PIN);
#endif
#if BS_WS2812_CH1_EN
bsp_gpio_deinit(ONEWIRE_CH1_PORT, ONEWIRE_CH1_PIN);
#endif
#if BS_WS2812_CH2_EN
bsp_gpio_deinit(ONEWIRE_CH2_PORT, ONEWIRE_CH2_PIN);
#endif
#if BS_WS2812_CH3_EN
bsp_gpio_deinit(ONEWIRE_CH3_PORT, ONEWIRE_CH3_PIN);
#endif
}
bool flag = false;
void onewire_send_data(uint8_t ch, uint8_t *data, uint8_t len)
{
uint8_t temp = 0;
if (ch == 0)
{
#if BS_WS2812_CH0_EN
if (flag)
{
return;
}
flag = true;
uint32_t val = SysTick->CTRL;
SysTick->CTRL &= ~0x00000003; // Disable SysTick interrupt
sys_disable_irq();
RESET_SIGNAL(ONEWIRE_CH0_PORT, ONEWIRE_CH0_PIN);
for (uint8_t n = 0; n < BS_WS2812_CH0_NUM; n++)
{
for (uint8_t i = 0; i < len; i++)
{
temp = data[i];
for (uint8_t j = 0; j < 8; j++)
{
if (temp & 0x80)
{
T1_BIT_SIGNAL(ONEWIRE_CH0_PORT, ONEWIRE_CH0_PIN)
}
else
{
T0_BIT_SIGNAL(ONEWIRE_CH0_PORT, ONEWIRE_CH0_PIN);
}
temp <<= 1;
}
}
}
RESET_SIGNAL(ONEWIRE_CH0_PORT, ONEWIRE_CH0_PIN);
SysTick->CTRL = val;
sys_enable_irq();
flag = false;
#endif
}
}
/********************************************************************************
* @file onewire.h
* @author jianqiang.xue
* @Version V1.0.0
* @Date 2020-11-23
* @brief NULL
************************************************************************************/
#ifndef __ONEWIRE_H
#define __ONEWIRE_H
/* Includes ------------------------------------------------------------------*/
#include /* Public Function Prototypes ------------------------------------------------*/ void onewire_init(void); void onewire_deinit(void); void onewire_send_data(uint8_t ch, uint8_t *data, uint8_t len); #endif /* __ONEWIRE_H */
Previous article:[MCU Framework] [app_led] [WS2812x] Using soft timer to implement WS2812x flashing and breathing lighting modes
Next article:C language macro definition and macro definition function
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- LM27762 Charge Pump with Integrated Positive and Negative LDO
- Transfer a video "There is a kind of beauty called mathematics"
- Let novices quickly understand Zigbee----Zigbee Overview
- #RecommendChinaCore# Activity sharing summary
- STM32F030 MCU ADC cannot be interrupted after DMA is enabled
- 5 yuan a clamp meter
- Classic foreign power electronics tutorials
- 2.4G antenna design reference on PCB board
- Why do I think Jiali Chuang’s marketing has failed?
- I have some questions about CORTEX-M TARGET DRIVER SETUP.