当前位置:网站首页>Stm32cube infrared remote control: input capture
Stm32cube infrared remote control: input capture
2022-07-28 16:21:00 【Chop Hua】
STM32Cube infrared remote control : Input capture
The principle of infrared remote control :https://blog.csdn.net/yangyang_1024/article/details/82999694
chip :stm32f030F4PX
Capture channels :TIM3_CH1
- Use the internal clock , when ,stm32f030F4PX The maximum clock frequency is 48MHz, The clock frequency of this configuration is 48MHz, The clock configuration is as follows :

- Configure the input capture channel , There is no need to check the external clock to select the internal clock Internal Clock, Select the channel 1Channel1, The model is Inp Captur direct mode.

- Timer parameter configuration ,48 frequency division , Count up , prescale 65535 namely 0xFFFF, This is a 16 Bit count, so the maximum value is 65535. No counting unit is 1us, Enable update interrupt .



- The generated code

- Source code reference punctual atom , The code is as follows
-1. Turn on input capture
__HAL_TIM_SET_CAPTUREPOLARITY(&htim3,TIM_CHANNEL_1,TIM_INPUTCHANNELPOLARITY_RISING);
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1);
2. Input capture processing
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM3)
{
if (RmtSta & 0x80) // Last time data was received
{
RmtSta &= ~0X10; // Cancel rising edge has been marked by capture
if ((RmtSta & 0X0F) == 0X00)
RmtSta |= 1 << 6; // Mark that the key value information collection of a key has been completed
if ((RmtSta & 0X0F) < 14)
RmtSta++;
else
{
RmtSta &= ~(1 << 7); // Clear the guide sign
RmtSta &= 0XF0; // Clear the counter
}
}
}
}
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if (TIM3 == htim->Instance)
{
if (HAL_TIM_ACTIVE_CHANNEL_1 == htim->Channel)
{
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_6))// Judge the level of the capture pin
{
__HAL_TIM_SET_CAPTUREPOLARITY(&htim3, TIM_CHANNEL_1, TIM_INPUTCHANNELPOLARITY_FALLING);// Falling edge capture
__HAL_TIM_SET_COUNTER(&htim3, TIM_CHANNEL_1); // Set the value of the count register to 0
RmtSta |= 0x10;
}
else
{
Dval = HAL_TIM_ReadCapturedValue(&htim3, TIM_CHANNEL_1);// Get the time from falling edge to rising edge
g_recvIRTime = __HAL_TIM_GET_COMPARE(&htim3, TIM_CHANNEL_1);
__HAL_TIM_SET_CAPTUREPOLARITY(&htim3, TIM_CHANNEL_1, TIM_INPUTCHANNELPOLARITY_RISING);// Rising edge capture
if (RmtSta & 0x10)
{
if (RmtSta & 0x80)
{
uint8_t Index = g_recvIndex / 8;
if ((Dval > 300) && (Dval < 800))// position 1
{
if (g_recvIndex != 0)
g_recvBuf[Index] <<= 1;
g_recvBuf[Index] &= 0xfe;
g_recvIndex++;
// g_recvIndex_0 ++;
}
else if ((Dval > 1400) && (Dval < 1800))// position 0
{
g_recvIndex++;
g_recvBuf[Index] <<= 1;
g_recvBuf[Index] |= 1;
}
else if ((Dval > 2000) && (Dval < 2500))
{
RmtCnt++; // Repeat code
RmtSta &= 0xf0;
}
}
else if ((Dval > 4200) && (Dval < 4700))
{
RmtSta |= 1 << 7; // Indicates that the synchronization header has been received
RmtCnt = 0; // Reset the number of keys
RmtRec = 0;
g_recvIndex = 0;
}
}
RmtSta &= ~(1 << 4);
}
}
}
}
void Remote_Scan(void)
{
uint8_t flag, state = 0;
flag = ~g_recvBuf[1];
static int staLCDstate = 0;
staLCDstate = ~staLCDstate;
if (g_recvIndex == 32)// Completion of reception
{
if (g_recvBuf[0] == flag)// User judgment
{
flag = ~g_recvBuf[3];
if (g_recvBuf[2] == flag)// Key code judgment
{
switch (g_recvBuf[2])
{
case KEY_POWER:
if (RmtCnt < 12)// Long press
{
LCD_ON;
}
else
{
LCD_OFF;
}
break;
default:
break;
}
}
}
}
}
STM32Cube Engineering and code connections :https://download.csdn.net/download/jjjjjj0000/15659644?spm=1001.2014.3001.5501
边栏推荐
- 【微信小程序开发(七)】订阅消息
- 深入理解Istio流量管理的熔断配置
- [live broadcast reservation] a new challenge under the evolution of data architecture - Shanghai railway station
- Dynamic programming -- digital statistics DP
- Pyqt5 rapid development and practice 5.2 container: load more controls
- QT QString详解
- Use py to automatically generate weekly reports based on log records
- JS array (summary)
- leetcode 题目
- 振弦采集模块测量振弦传感器的流程步骤?
猜你喜欢

2021 Kent interview question 2

mysql查询 limit 1000,10 和limit 10 速度一样快吗?如果我要分页,我该怎么办?
![[wechat applet development (VII)] subscription message](/img/aa/f0c68bc0c068ac208820df42cce3db.png)
[wechat applet development (VII)] subscription message

js 队列

Zhengda cup hacker marathon data analysis competition

光学雨量计应用降雨量检测

Image semantic segmentation practice: tensorflow deeplobv3+ train your own dataset

LabVIEW Linx toolkit controls Arduino equipment (expansion-1)

Shell programming specifications and variables

js 双向链表 01
随机推荐
Temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
五舅的思考
leetcode 题目
2021 Yahong pen test question 2
QT打包
Zhaoqi scientific innovation and entrepreneurship competition platform, activity roadshow, investment and financing docking
疫情红利消失,「居家健身」泡沫消散
QT QString详解
Remember the common JS methods of projects
动态规划 --- 数位统计DP
2021 Yahong pen test questions
兆骑科创创新创业大赛人才引进平台,双创赛事高层次人才引进
JS stack
Event express | Apache Doris Performance Optimization Practice Series live broadcast course is open at the beginning. You are cordially invited to participate!
为什么学编程的人大多数都去了深圳和北京?
The deep displacement monitoring system wk813 is used to measure the deep displacement of slopes, dams, embankments, railways and building foundation pit excavation
R language ggplot2 visually draws line plots, and uses gghighlight package to highlight the lines that meet the combination judgment conditions in the line graphs (satisfies both condition a and b)
One channel encoder, two channels Di speed measurement, RS485 serial port connected to one channel do alarm module ibf151
ffmpeg获取首帧
Multipurpose mixed signal 8ai/4di/do to serial port rs485/232modbus acquisition module ibf30