当前位置:网站首页>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
边栏推荐
- Fifth uncle's thinking
- KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
- JS linked list 02
- 资本「断供」两年,我只能把公司卖了
- leetcode 题目
- Temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
- R language uses file of FS package_ Delete function deletes the specified file under the specified folder, draw inferences from one instance, dir_ Delete function, link_ The delete function can be use
- 激光测距仪非接触式地表裂缝监测仪
- IFD-x 微型红外成像仪(模块)的温度测量和成像精度
- JS priority queue
猜你喜欢

JS array (summary)

Roson的Qt之旅#101 Qt Quick中的模型和视图

High precision absolute angle sensor application high speed angle monitoring

A tour of grp:05 - GRP server streaming service end stream

Duty cycle switch output high speed pulse counter rtumodbus module ibf63

便携式钻孔测斜仪数据采集仪测量原理与测斜探头的连接及使用方法

两种特殊函数(箭头函数和方法)

解决电脑恶意广告弹窗的思路

【Multisim仿真】LM339过零电路仿真

Application of optical rain gauge to rainfall detection
随机推荐
深入理解Istio流量管理的熔断配置
JS priority queue
Remember the common JS methods of projects
Duty cycle switch output high speed pulse counter rtumodbus module ibf63
高精度绝对角度传感器应用高速度角度监测
js 队列
Data real-time feedback technology
2021 肯特面试题3
Have you seen the management area decoupling architecture? Can help customers solve big problems
5 亿用户,比微信还早四年……这个运营了 15 年的 APP 即将永久停服
Use py to automatically generate weekly reports based on log records
2021 Yahong pen test question 2
Knowledge points qwer
Food safety | these two kinds of melons and fruits should be improved, especially for pregnant women with constipation
仅需三步 轻松实现远程办公
分体式测斜探头安装要点及注意事项
Detectron2 installation and testing
I'll show you a little chat! Summary of single merchant function modules
Note: numerical accumulation animation
Ffmpeg get the first frame