本文章介紹利用WS2812燈條來製作一個大型的七段式顯示器,用來顯示SHT40的溫濕度。利用Rotary encoder來設定七段式顯示器的顏色。MCU 使用STM32F103C8T6。
WS2812每個0或1的編碼方式與時序。
SPI baud rate:
SPI GPIO:
Rotary Encoder Timer設定:
成果展示:
程式碼:
main.c/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "ws2812.h"
#include "sht40.h"
#include "math.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef hi2c1;
SPI_HandleTypeDef hspi1;
DMA_HandleTypeDef hdma_spi1_tx;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;
/* USER CODE BEGIN PV */
// 7-segment digit
uint8_t digit[13][7] = {
{1,1,1,1,1,1,0}, //0
{1,0,0,0,0,1,0}, //1
{0,1,1,0,1,1,1}, //2
{1,1,0,0,1,1,1}, //3
{1,0,0,1,0,1,1}, //4
{1,1,0,1,1,0,1}, //5
{1,1,1,1,1,0,1}, //6
{1,0,0,0,1,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,0,0,1,1,1,1}, //9
{0,0,0,1,1,1,1}, // degree
{0,1,1,1,1,0,0}, // C
{1,1,1,0,0,0,1}, // low%
};
uint8_t rgb_color[3] = {128,128,128};
enum {
SET_RED=0,
SET_GREEN=1,
SET_BLUE=2,
SET_COUNT=3,
};
uint8_t rgb_set_index=SET_RED;
int16_t rgb_set_start_counter=0;
uint8_t sw_state=1;
uint8_t set_color_mode=0;
uint8_t long_press_count=0;
int16_t counter=0;
ws2812_pixel_color_t pixels_color;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_SPI1_Init(void);
static void MX_I2C1_Init(void);
static void MX_TIM2_Init(void);
static void MX_TIM3_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void display_digit(uint8_t number) {
for (int i=0; i < 7; i++) {
if (digit[number][i] == 1) {
for (int k=0; k < 3;k++) ws2812_display_pixel(&pixels_color,1);
}
else {
for (int k=0; k < 3;k++) ws2812_display_pixel(&pixels_color,0);
}
}
}
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim) {
if (set_color_mode) {
counter = (int16_t)__HAL_TIM_GET_COUNTER(htim);
rgb_color[rgb_set_index] += (counter - rgb_set_start_counter);
rgb_set_start_counter = counter;
ws2812_set_pixel_color(&pixels_color,0,0,rgb_color[SET_BLUE]);
display_digit(1);
ws2812_set_pixel_color(&pixels_color,0,rgb_color[SET_GREEN],0);
display_digit(1);
ws2812_set_pixel_color(&pixels_color,rgb_color[SET_RED],0,0);
display_digit(1);
ws2812_set_pixel_color(&pixels_color,rgb_color[SET_RED],rgb_color[SET_GREEN],rgb_color[SET_BLUE]);
display_digit(1);
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){
if (HAL_GPIO_ReadPin(RT_SW_GPIO_Port, RT_SW_Pin) == GPIO_PIN_SET) {
HAL_TIM_Base_Stop_IT(&htim2);
if (long_press_count > 20) {
set_color_mode = !set_color_mode;
}
long_press_count=0;
sw_state = 1;
rgb_set_index = (rgb_set_index+1) % SET_COUNT;
rgb_set_start_counter = (int16_t)__HAL_TIM_GET_COUNTER(&htim3);
if (set_color_mode){
ws2812_set_pixel_color(&pixels_color,0,0,rgb_color[SET_BLUE]);
display_digit(1);
ws2812_set_pixel_color(&pixels_color,0,rgb_color[SET_GREEN],0);
display_digit(1);
ws2812_set_pixel_color(&pixels_color,rgb_color[SET_RED],0,0);
display_digit(1);
ws2812_set_pixel_color(&pixels_color,rgb_color[SET_RED],rgb_color[SET_GREEN],rgb_color[SET_BLUE]);
display_digit(1);
}
} else {
long_press_count++;
}
}
void HAL_GPIO_EXTI_Callback(uint16_t gpio) {
if (gpio == RT_SW_Pin && sw_state) {
sw_state=0;
HAL_TIM_Base_Start_IT(&htim2);
}
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_SPI1_Init();
MX_I2C1_Init();
MX_TIM2_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Encoder_Start_IT(&htim3, TIM_CHANNEL_ALL);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
ws2812_set_pixel_color(&pixels_color,rgb_color[SET_RED],rgb_color[SET_GREEN],rgb_color[SET_BLUE]);
uint8_t temp, digit0, digit1;
float sht40_temp, sht40_humi;
while (1)
{
sht40_get_th_data(&sht40_temp, &sht40_humi);
temp = (uint8_t) round(sht40_temp);
digit0 = temp%10;
digit1 = temp/10;
if(!set_color_mode) {
display_digit(11);
display_digit(10);
display_digit(digit0);
display_digit(digit1);
HAL_Delay(2000);
}
temp = (uint8_t) round(sht40_humi);
digit0 = temp%10;
digit1 = temp/10;
if(!set_color_mode) {
display_digit(12);
display_digit(10);
display_digit(digit0);
display_digit(digit1);
HAL_Delay(2000);
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL5;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief I2C1 Initialization Function
* @param None
* @retval None
*/
static void MX_I2C1_Init(void)
{
/* USER CODE BEGIN I2C1_Init 0 */
/* USER CODE END I2C1_Init 0 */
/* USER CODE BEGIN I2C1_Init 1 */
/* USER CODE END I2C1_Init 1 */
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 100000;
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C1_Init 2 */
/* USER CODE END I2C1_Init 2 */
}
/**
* @brief SPI1 Initialization Function
* @param None
* @retval None
*/
static void MX_SPI1_Init(void)
{
/* USER CODE BEGIN SPI1_Init 0 */
/* USER CODE END SPI1_Init 0 */
/* USER CODE BEGIN SPI1_Init 1 */
/* USER CODE END SPI1_Init 1 */
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */
/* USER CODE END SPI1_Init 2 */
}
/**
* @brief TIM2 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM2_Init(void)
{
/* USER CODE BEGIN TIM2_Init 0 */
/* USER CODE END TIM2_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM2_Init 1 */
/* USER CODE END TIM2_Init 1 */
htim2.Instance = TIM2;
htim2.Init.Prescaler = 2000-1;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 1000-1;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM2_Init 2 */
/* USER CODE END TIM2_Init 2 */
}
/**
* @brief TIM3 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
TIM_Encoder_InitTypeDef sConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 65535;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
sConfig.IC1Polarity = TIM_ICPOLARITY_FALLING;
sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
sConfig.IC1Filter = 0;
sConfig.IC2Polarity = TIM_ICPOLARITY_FALLING;
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
sConfig.IC2Filter = 0;
if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
}
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin : RT_SW_Pin */
GPIO_InitStruct.Pin = RT_SW_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(RT_SW_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
ws2812.c
#include "main.h"
#include "ws2812.h"
#include "string.h"
extern SPI_HandleTypeDef hspi1;
extern DMA_HandleTypeDef hdma_spi1_tx;
void ws2812_set_pixel_color(ws2812_pixel_color_t *ws2812_pixels_color, uint8_t red, uint8_t green, uint8_t blue) {
ws2812_pixels_color->green.bit0 = green >> 0 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->green.bit1 = green >> 1 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->green.bit2 = green >> 2 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->green.bit3 = green >> 3 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->green.bit4 = green >> 4 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->green.bit5 = green >> 5 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->green.bit6 = green >> 6 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->green.bit7 = green >> 7 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->red.bit0 = red >> 0 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->red.bit1 = red >> 1 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->red.bit2 = red >> 2 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->red.bit3 = red >> 3 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->red.bit4 = red >> 4 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->red.bit5 = red >> 5 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->red.bit6 = red >> 6 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->red.bit7 = red >> 7 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->blue.bit0 = blue >> 0 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->blue.bit1 = blue >> 1 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->blue.bit2 = blue >> 2 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->blue.bit3 = blue >> 3 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->blue.bit4 = blue >> 4 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->blue.bit5 = blue >> 5 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->blue.bit6 = blue >> 6 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
ws2812_pixels_color->blue.bit7 = blue >> 7 & 0x01 ? WS2812_BIT_1:WS2812_BIT_0;
}
void ws2812_display_pixel(ws2812_pixel_color_t *ws2812_pixels_color,uint8_t show) {
if (show) {
HAL_SPI_Transmit(&hspi1, (uint8_t*)ws2812_pixels_color, WS2812_PIXEL_BYTES, 1000);
} else {
ws2812_pixel_color_t black;
ws2812_set_pixel_color(&black, 0, 0, 0);
HAL_SPI_Transmit(&hspi1, (uint8_t*)&black , WS2812_PIXEL_BYTES, 1000);
}
}
ws2812.h
#ifndef INC_WS2812_H_
#define INC_WS2812_H_
#define WS2812_BIT_1 0b110
#define WS2812_BIT_0 0b100
#define WS2812_PIXEL_BYTES 12 // 3*4, 4 bytes for red, green or blue
typedef struct {
uint8_t bit6:4; //low nibble
uint8_t bit7:4; //high nibble for byte one
uint8_t bit4:4;
uint8_t bit5:4;
uint8_t bit2:4;
uint8_t bit3:4;
uint8_t bit0:4;
uint8_t bit1:4;
} ws2812_color_bits_t;
typedef struct {
ws2812_color_bits_t green;
ws2812_color_bits_t red;
ws2812_color_bits_t blue;
}ws2812_pixel_color_t;
void ws2812_display_pixel(ws2812_pixel_color_t *ws2812_pixels_color,uint8_t show);
void ws2812_set_pixel_color(ws2812_pixel_color_t *ws2812_pixels_color, uint8_t red, uint8_t green, uint8_t blue);
#endif /* INC_WS2812_H_ */
sht40.c
#include "sht40.h"
void sht40_get_th_data(float *temp, float *humi) {
uint8_t buff[8];
float t_ticks, rh_ticks, t_degC, rh_pRH;
buff[0] = 0xFD;
//ret = i2c_write_blocking(I2C_SHT40_PORT, 0x44, buff,1,false);
HAL_I2C_Master_Transmit(&hi2c1, 0x44<<1, buff, 1, 1000);
HAL_Delay(10);
//ret = i2c_read_blocking(I2C_SHT40_PORT, 0x44, buff, 6, false);
HAL_I2C_Master_Receive(&hi2c1, 0x44<<1, buff, 6,1000);
t_ticks = buff[0] * 256 + buff[1];
//checksum_t = rx_bytes[2]
rh_ticks = buff[3] * 256 + buff[4];
//checksum_rh = rx_bytes[5]
t_degC = -45 + 175 * t_ticks/65535;
rh_pRH = -6 + 125 * rh_ticks/65535;
if (rh_pRH > 100)
rh_pRH = 100;
if (rh_pRH < 0)
rh_pRH = 0;
*temp = t_degC;
*humi = rh_pRH;
//printf("temp:%f, himidity:%f\n", t_degC, rh_pRH);
}
sht40.h
#ifndef __SHT40_H__
#define __SHT40_H__
#include "main.h"
extern I2C_HandleTypeDef hi2c1;
void sht40_get_th_data(float* temp, float* humi);
#endif
WS2812_F103.ioc
#MicroXplorer Configuration settings - do not modify
CAD.formats=
CAD.pinconfig=
CAD.provider=
Dma.Request0=SPI1_TX
Dma.RequestsNb=1
Dma.SPI1_TX.0.Direction=DMA_MEMORY_TO_PERIPH
Dma.SPI1_TX.0.Instance=DMA1_Channel3
Dma.SPI1_TX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE
Dma.SPI1_TX.0.MemInc=DMA_MINC_ENABLE
Dma.SPI1_TX.0.Mode=DMA_NORMAL
Dma.SPI1_TX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
Dma.SPI1_TX.0.PeriphInc=DMA_PINC_DISABLE
Dma.SPI1_TX.0.Priority=DMA_PRIORITY_LOW
Dma.SPI1_TX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
File.Version=6
GPIO.groupedBy=Group By Peripherals
KeepUserPlacement=false
Mcu.CPN=STM32F103C8T6
Mcu.Family=STM32F1
Mcu.IP0=DMA
Mcu.IP1=I2C1
Mcu.IP2=NVIC
Mcu.IP3=RCC
Mcu.IP4=SPI1
Mcu.IP5=SYS
Mcu.IP6=TIM2
Mcu.IP7=TIM3
Mcu.IPNb=8
Mcu.Name=STM32F103C(8-B)Tx
Mcu.Package=LQFP48
Mcu.Pin0=PD0-OSC_IN
Mcu.Pin1=PD1-OSC_OUT
Mcu.Pin10=PB7
Mcu.Pin11=VP_SYS_VS_Systick
Mcu.Pin12=VP_TIM2_VS_ClockSourceINT
Mcu.Pin2=PA5
Mcu.Pin3=PA7
Mcu.Pin4=PA13
Mcu.Pin5=PA14
Mcu.Pin6=PB3
Mcu.Pin7=PB4
Mcu.Pin8=PB5
Mcu.Pin9=PB6
Mcu.PinsNb=13
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F103C8Tx
MxCube.Version=6.12.0
MxDb.Version=DB.6.0.120
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.DMA1_Channel3_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.EXTI3_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
NVIC.TIM2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.TIM3_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
PA13.Mode=Serial_Wire
PA13.Signal=SYS_JTMS-SWDIO
PA14.Mode=Serial_Wire
PA14.Signal=SYS_JTCK-SWCLK
PA5.Mode=Simplex_Bidirectional_Master
PA5.Signal=SPI1_SCK
PA7.Mode=Simplex_Bidirectional_Master
PA7.Signal=SPI1_MOSI
PB3.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
PB3.GPIO_Label=RT_SW
PB3.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
PB3.GPIO_PuPd=GPIO_PULLUP
PB3.Locked=true
PB3.Signal=GPXTI3
PB4.Signal=S_TIM3_CH1
PB5.Signal=S_TIM3_CH2
PB6.Mode=I2C
PB6.Signal=I2C1_SCL
PB7.Mode=I2C
PB7.Signal=I2C1_SDA
PD0-OSC_IN.Mode=HSE-External-Oscillator
PD0-OSC_IN.Signal=RCC_OSC_IN
PD1-OSC_OUT.Mode=HSE-External-Oscillator
PD1-OSC_OUT.Signal=RCC_OSC_OUT
PinOutPanel.RotationAngle=0
ProjectManager.AskForMigrate=true
ProjectManager.BackupPrevious=false
ProjectManager.CompilerOptimize=6
ProjectManager.ComputerToolchain=false
ProjectManager.CoupleFile=false
ProjectManager.CustomerFirmwarePackage=
ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=true
ProjectManager.DeviceId=STM32F103C8Tx
ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.6
ProjectManager.FreePins=false
ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true
ProjectManager.LibraryCopy=1
ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=
ProjectManager.ProjectBuild=false
ProjectManager.ProjectFileName=WS2812_F103.ioc
ProjectManager.ProjectName=WS2812_F103
ProjectManager.ProjectStructure=
ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_SPI1_Init-SPI1-false-HAL-true,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_TIM2_Init-TIM2-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true
RCC.ADCFreqValue=20000000
RCC.AHBFreq_Value=40000000
RCC.APB1CLKDivider=RCC_HCLK_DIV2
RCC.APB1Freq_Value=20000000
RCC.APB1TimFreq_Value=40000000
RCC.APB2Freq_Value=40000000
RCC.APB2TimFreq_Value=40000000
RCC.FCLKCortexFreq_Value=40000000
RCC.FamilyName=M
RCC.HCLKFreq_Value=40000000
RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value
RCC.MCOFreq_Value=40000000
RCC.PLLCLKFreq_Value=40000000
RCC.PLLMCOFreq_Value=20000000
RCC.PLLMUL=RCC_PLL_MUL5
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
RCC.SYSCLKFreq_VALUE=40000000
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.TimSysFreq_Value=40000000
RCC.USBFreq_Value=40000000
RCC.VCOOutput2Freq_Value=8000000
SH.GPXTI3.0=GPIO_EXTI3
SH.GPXTI3.ConfNb=1
SH.S_TIM3_CH1.0=TIM3_CH1,Encoder_Interface
SH.S_TIM3_CH1.ConfNb=1
SH.S_TIM3_CH2.0=TIM3_CH2,Encoder_Interface
SH.S_TIM3_CH2.ConfNb=1
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16
SPI1.CalculateBaudRate=2.5 MBits/s
SPI1.Direction=SPI_DIRECTION_1LINE
SPI1.IPParameters=VirtualType,Mode,Direction,BaudRatePrescaler,CalculateBaudRate
SPI1.Mode=SPI_MODE_MASTER
SPI1.VirtualType=VM_MASTER
TIM2.IPParameters=Prescaler,Period
TIM2.Period=1000-1
TIM2.Prescaler=2000-1
TIM3.EncoderMode=TIM_ENCODERMODE_TI12
TIM3.IC1Polarity=TIM_ICPOLARITY_FALLING
TIM3.IC2Polarity=TIM_ICPOLARITY_FALLING
TIM3.IPParameters=EncoderMode,IC1Polarity,IC2Polarity
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_TIM2_VS_ClockSourceINT.Mode=Internal
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
board=custom
isbadioc=false