Compare commits

...

2 Commits

Author SHA1 Message Date
a55ef6efcc 微调 2025-01-18 12:50:27 +08:00
6a594d6cdc ADC 接入板正确检测 2025-01-18 12:41:57 +08:00
4 changed files with 69 additions and 16 deletions

View File

@ -201,7 +201,7 @@ CONFIG_RT_USING_I2C_BITOPS=y
# CONFIG_RT_I2C_BITOPS_DEBUG is not set
# CONFIG_RT_USING_SOFT_I2C is not set
# CONFIG_RT_USING_PHY is not set
# CONFIG_RT_USING_ADC is not set
CONFIG_RT_USING_ADC=y
# CONFIG_RT_USING_DAC is not set
# CONFIG_RT_USING_NULL is not set
# CONFIG_RT_USING_ZERO is not set
@ -1691,7 +1691,9 @@ CONFIG_BSP_USING_SPI=y
CONFIG_BSP_USING_SPI2=y
# CONFIG_BSP_SPI2_TX_USING_DMA is not set
# CONFIG_BSP_SPI2_RX_USING_DMA is not set
# CONFIG_BSP_USING_ADC is not set
CONFIG_BSP_USING_ADC=y
CONFIG_BSP_USING_ADC1=y
# CONFIG_BSP_USING_ADC3 is not set
CONFIG_BSP_USING_I2C=y
# CONFIG_BSP_USING_I2C1 is not set
CONFIG_BSP_USING_I2C2=y

View File

@ -1,4 +1,10 @@
#include "indicator_led.h"
#include "rtdevice.h"
#define ADC_DEV_NAME "adc1" /* ADC 设备名称 */
#define ADC_DEV_CHANNEL 5 /* ADC 通道 */
#define REFER_VOLTAGE 330 /* 参考电压 3.3V,数据精度乘以100保留2位小数*/
#define CONVERT_BITS (1 << 12) /* 转换位数为12位 */
#define LED_NUM 24 // LED灯珠个数
@ -20,15 +26,15 @@ const RGBColor_TypeDef LED_ON = {255, 255, 255};
void LED_BreathTurn(uint8_t LedBreath_state)
{
LED_Breath_State = LedBreath_state;
if (LedBreath_state == LED_BREATH_OFF)
{
// rt_thread_suspend(led_breath_thread);
LED_SetMore(LED_BREATH_ID(1), LED_BREATH_ID(12), LED_OFF);
}
else if (LedBreath_state == LED_BREATH_ON)
{
// rt_thread_resume(led_breath_thread);
}
// if (LedBreath_state == LED_BREATH_OFF)
// {
// // rt_thread_suspend(led_breath_thread);
// LED_SetMore(LED_BREATH_ID(1), LED_BREATH_ID(12), LED_OFF);
// }
// else if (LedBreath_state == LED_BREATH_ON)
// {
// // rt_thread_resume(led_breath_thread);
// }
}
/**
* @brief LED的颜色或开关
@ -148,19 +154,63 @@ void led_breath_entry(void *parameter)
break;
}
RGB_Reflash();
rt_thread_mdelay(500);
rt_thread_delay(40);
}
count = (count + 1) % 3;
}
}
// MSH_CMD_EXPORT_ALIAS(led_breath_thread,BREATH, "BREATH LIGHT");
#define BORAD_NOT_CORRECT 25
/**
* @brief
*/
static int borad_check(void)
{
rt_adc_device_t adc_dev;
rt_uint32_t value, vol;
rt_err_t ret = RT_EOK;
/* 查找设备 */
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
if (adc_dev == RT_NULL)
{
rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
return RT_ERROR;
}
/* 使能设备 */
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL);
/* 读取采样值 */
value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);
/* 转换为对应电压值 */
vol = value * REFER_VOLTAGE / CONVERT_BITS;
if(vol>=0.25*100)
{
rt_kprintf("NOT correct borad!\n");
rt_kprintf("the value is :%d \n", value);
rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100);
return BORAD_NOT_CORRECT;
}
/* 关闭通道 */
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL);
return ret;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(borad_check, adc voltage convert sample);
/**
* @brief LED的初始化
*/
int led_init(void)
{
if (borad_check()==BORAD_NOT_CORRECT)
{
return 0;
}
led_blink_thread = rt_thread_create("led blink control thread", led_blink_entry, RT_NULL, 1024, 20, 20);
if (led_blink_thread == RT_NULL)
{

View File

@ -619,8 +619,6 @@ void my_project(void)
serial_init();
led_blink_init();
led_breath_init();
led_init();
}
MSH_CMD_EXPORT_ALIAS(my_project, myproject, run my project);

View File

@ -133,6 +133,7 @@
#define RT_SERIAL_RB_BUFSZ 64
#define RT_USING_I2C
#define RT_USING_I2C_BITOPS
#define RT_USING_ADC
#define RT_USING_PWM
#define RT_USING_RTC
#define RT_USING_SOFT_RTC
@ -655,6 +656,8 @@
#define BSP_USING_ON_CHIP_FLASH
#define BSP_USING_SPI
#define BSP_USING_SPI2
#define BSP_USING_ADC
#define BSP_USING_ADC1
#define BSP_USING_I2C
#define BSP_USING_I2C2
#define BSP_I2C2_SCL_PIN 81