相关连接
需求
接收RF433和红外信号,根据信号内容控制舵机
硬件设计
主控采用stm32F103c6
STM32
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-aTpXZCoT-1676130507363)(picture/1.png)]](https://i-blog.csdnimg.cn/blog_migrate/bec951f0e7ac5f9184de808decc4bdec.png)
433接收
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WsUmue6W-1676130507364)(picture/2.png)]](https://i-blog.csdnimg.cn/blog_migrate/31a607b61785404048cb065e2f13d443.png)
其他接口
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YsV5ZBTM-1676130507365)(picture/3.png)]](https://i-blog.csdnimg.cn/blog_migrate/0667e69303619c98f4ed0529d516c8cc.png)
软件设计
接收RF433/红外的信号,并完成动作即可
相关链接
HAL初始化
定时器1
红外和RF433的计时
设置为分频后1us,默认溢出数,开中断
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-c2OQ8G8J-1676130507366)(picture/4.png)]](https://i-blog.csdnimg.cn/blog_migrate/e5be15a53423899379a684849d7ff5a9.png)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XVvEdjgQ-1676130507366)(picture/5.png)]](https://i-blog.csdnimg.cn/blog_migrate/99eb39721f8ca2570ebc3d2bbcd14181.png)
定时器2
用作舵机控制的PWM生成
每隔20us触发一次中断
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nUCDJHnG-1676130507367)(picture/6.png)]](https://i-blog.csdnimg.cn/blog_migrate/b11c1ee3e4190a373d18ea72e2b4e243.png)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Ev25gVpu-1676130507367)(picture/7.png)]](https://i-blog.csdnimg.cn/blog_migrate/c8b1df29f5840a88d589ae374dd2bfa4.png)
GPIO
LED:用作指示灯,推挽输出即可
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Gvf7unPe-1676130507368)(picture/8.png)]](https://i-blog.csdnimg.cn/blog_migrate/57acb2520f86852a02e08cb54f6ebce8.png)
GPIO
舵机控制信号
配置为开漏浮空(外部接上拉电阻到5V),配置为最高等级(避免复位时让电机出现误动作)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VH8MdGJy-1676130507369)(picture/9.png)]](https://i-blog.csdnimg.cn/blog_migrate/c858929b076f74bbed706fcc7cc86934.png)
GPIO
RF433输入
配置为边沿中断模式
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fDlh0Fhr-1676130507369)(picture/10.png)]](https://i-blog.csdnimg.cn/blog_migrate/196d3c1d8afd9bb4dcbd875651da3385.png)
GPIO
红外输入
配置为下降沿中断模式
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nXLOmsyv-1676130507370)(picture/11.png)]](https://i-blog.csdnimg.cn/blog_migrate/ac1a4c71a839af46a986672e9b80ed81.png)
硬件看门狗
32分频,溢出值4000
每(32/40k*4000=3.2s)触发一次
本程序目的是让程序每3.2s重启一次,因此只在需要操作舵机时喂狗,主循环无喂狗
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zbCFn7g3-1676130507370)(picture/12.png)]](https://i-blog.csdnimg.cn/blog_migrate/418d29510402cddb7e1c5a01184a40db.png)
程序
中断回调函数
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim == &Steering_Engine_TIM)
{
if (M_EN == 1)
Steering_Engine_Action();
else
HAL_GPIO_WritePin(Steering_Engine_GPIOx, Steering_Engine_GPIO_Pin, GPIO_PIN_SET);
}
else if (htim == &htim3)
{
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == GPIO_PIN_2)
{
if (IR_NEC_Read_ins == 0)
RF_Read_Decode();
}
else if (GPIO_Pin == GPIO_PIN_3)
{
IR_NEC_Read_Decode(air);
}
}
主循环处理函数
if (IR_NEC_Read_OK)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
// printf("%02X%02X%02X%02X\r\n", IR_NEC_Read_Dat[0], IR_NEC_Read_Dat[1], IR_NEC_Read_Dat[2], IR_NEC_Read_Dat[3]);
if (IR_NEC_Read_Dat[0] == 0x4D && IR_NEC_Read_Dat[1] == 0xb2 && IR_NEC_Read_Dat[2] == 0xa3 && IR_NEC_Read_Dat[3] == 0x5C)
OPEN();
else if (IR_NEC_Read_Dat[0] == 0x4D && IR_NEC_Read_Dat[1] == 0xb2 && IR_NEC_Read_Dat[2] == 0x59 && IR_NEC_Read_Dat[3] == 0xa6)
CLOSE();
if (IR_NEC_Read_Dat[0] == 0x84 && IR_NEC_Read_Dat[1] == 0xff && IR_NEC_Read_Dat[2] == 0x81 && IR_NEC_Read_Dat[3] == 0x7e)
OPEN();
else if (IR_NEC_Read_Dat[0] == 0x84 && IR_NEC_Read_Dat[1] == 0xff && IR_NEC_Read_Dat[2] == 0x01 && IR_NEC_Read_Dat[3] == 0xfe)
CLOSE();
HAL_IWDG_Refresh(&hiwdg);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
IR_NEC_Read_Dat[0] = 0;
IR_NEC_Read_Dat[1] = 0;
IR_NEC_Read_Dat[2] = 0;
IR_NEC_Read_Dat[3] = 0;
IR_NEC_Read_OK = 0;
}
if (RF_READ_OK)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
// printf("%02X%02X%02X\r\n", RF_READ_data[0], RF_READ_data[1], RF_READ_data[2]);
if (RF_READ_data[0] == 0xac && RF_READ_data[1] == 0x22 && RF_READ_data[2] == 0x00)
OPEN();
else if (RF_READ_data[0] == 0xac && RF_READ_data[1] == 0x22 && RF_READ_data[2] == 0xff)
CLOSE();
HAL_IWDG_Refresh(&hiwdg);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
RF_READ_data[0] = 0;
RF_READ_data[1] = 0;
RF_READ_data[2] = 0;
RF_READ_OK = 0;
// __set_FAULTMASK(1);
// NVIC_SystemReset();
}
开关灯控制函数
void OPEN()
{
M_EN = 1;
HAL_IWDG_Refresh(&hiwdg);
Steering_Engine_360(0, 30);
HAL_Delay(500);
HAL_IWDG_Refresh(&hiwdg);
Steering_Engine_360(1, 40);
HAL_Delay(80);
HAL_IWDG_Refresh(&hiwdg);
Steering_Engine_Stop();
M_EN = 0;
}
void CLOSE()
{
M_EN = 1;
HAL_IWDG_Refresh(&hiwdg);
Steering_Engine_360(1, 30);
HAL_Delay(500);
HAL_IWDG_Refresh(&hiwdg);
Steering_Engine_360(0, 30);
HAL_Delay(80);
HAL_IWDG_Refresh(&hiwdg);
Steering_Engine_Stop();
M_EN = 0;
}
成品
另外app开发很简单,百度凑凑就行了,源码同样在GitHub上,请自行查看即可
该系统使用STM32F103C6作为主控,通过HAL库处理RF433和红外信号,根据接收到的信号控制舵机动作。硬件设计包括433MHz接收模块和舵机接口,软件设计中利用定时器进行PWM生成和信号解析,GPIO配置为中断模式来检测信号。主循环处理接收到的红外信号,执行相应的开关灯操作,并通过硬件看门狗确保程序稳定性。
4051

被折叠的 条评论
为什么被折叠?



