当前位置:网站首页>STM32 reads the data value of biaxial remote sensing
STM32 reads the data value of biaxial remote sensing
2022-07-18 10:57:00 【ValentineHP】
One . brief introduction
In terms of key control , Remote sensing with two axis buttons is far more convenient than buttons , And it's very easy to use . It consists of three data pins , Namely X Analog input of shaft ,Y Analog input and key input of axis , There's another one GND and VCC. here VCC Is a reference voltage , Can connect 5V, You can also pick up 3.3V. If the answer is 5V Words , that X The analog input voltage of the shaft is 0-5V.

Two . STM32 Read biaxial remote sensing data
Because the input is an analog value , So we need to use ADC Conduct analog acquisition . You can know from the data book that ,ADC Is the additional function of its pin , Reuse configuration is not required . Only need to GPIO_Mode configure AN that will do , Then configure ADC Relevant information is ok .
- GPIO initialization
/*GPIO Init*/
void XYRocker1GPIOInit(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
/*XY GPIO*/
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN; /" Additional features "/
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA,&GPIO_InitStruct);
/*rocker key Button for dual axis remote sensing */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct);
}
- ADC initialization
void XYRockerADCInit(uint8_t num)
{
ADC_InitTypeDef ADC_InitStruct;
ADC_CommonInitTypeDef ADC_ComminInitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADC_DeInit();
ADC_ComminInitStruct.ADC_Mode = ADC_Mode_Independent;
ADC_ComminInitStruct.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles;
ADC_ComminInitStruct.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_ComminInitStruct.ADC_Prescaler = ADC_Prescaler_Div4;
ADC_CommonInit(&ADC_ComminInitStruct);
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ScanConvMode = DISABLE;
ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;// Right alignment
ADC_InitStruct.ADC_NbrOfConversion = num;
/* Dual axis has two analog inputs , So this is set to 2, If it is two remote sensing , Use the same ADC Words , I'm going to set it to 4*/
ADC_Init(ADC1,&ADC_InitStruct);
ADC_Cmd(ADC1,ENABLE);
}
- data fetch
uint16_t getX1Value()
{
/* Set the channel for conversion */
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_480Cycles );
ADC_SoftwareStartConv(ADC1); // Enable to designate ADC1 Software conversion start function
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));// Wait for the conversion to finish
return ADC_GetConversionValue(ADC1); // Go back to the last time ADC1 Conversion result of rule group
}
After a few steps above , You can read the two axis remote sensing .
Reset status value is 2200 about . When biaxial remote sensing goes up, it is only 0 about , When down , Namely 4096 Around the (16bit 0-4096). The same is true in the left and right directions . Its actual voltage value , Will be 0-4096 Mapping to 0-VCC Come on (VCC It is the voltage value you connect it ).
It's very good to control the flight control or car , Let's try !
Welcome to WeChat official account. FPGA The journey Get more information .
边栏推荐
- [detailed tutorial] a thorough article on mongodb aggregation query
- P1088 [noip2004 popularity group question 4] Martians ← next_ permutation
- class path resource [xxx.properties] cannot be opened because it does not exist
- JUST k
- LeetCode_ 513_ Find the value in the lower left corner of the tree
- Paul Holland: predicting the trend of the financial market
- Reinforcement learning (II)
- 以太网开发与测试,这一步你做对了吗 (3)
- [MySQL must know and know] conditional statement
- Ethernet development and testing, have you done this step right (3)
猜你喜欢

2022 mathematical modeling "May Day Cup" question B
![class path resource [xxx.properties] cannot be opened because it does not exist](/img/e3/5e5a568dbf2fcceae8b2d4a7249763.png)
class path resource [xxx.properties] cannot be opened because it does not exist

以太网开发与测试,这一步你做对了吗 (2)

多御安全浏览器怎么移除密码?
![NC19910 [CQOI2007]矩形RECT](/img/92/49ec3a079a5e8bf61c0bd4bcb669af.gif)
NC19910 [CQOI2007]矩形RECT

MGRE及GRE综合实验

Heartless sword Chinese translation of Michael's definition of algebra

Ethernet development and testing, have you done this step right (3)
[email protected] | Uio-66 / graphene oxide (uio-66 / go) |pt [email protected] |

Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块
随机推荐
Buckle practice - 14 simplified path
编程语言学习和使用的观点
Repent of greed stonk
What is the real HTAP? (1) Background article
(手工)【sqli-labs44、45】POST字符型注入、盲注、堆叠注入
可落地的DDD(7)-战术设计上的一些误区
How to solve the problem of APP being rejected for collecting personal information?
ASEMI整流桥GBJ2510规格,GBJ2510封装,GBJ2510特性
Do you want to be an engineer or a product manager?
力扣练习——22 买卖股票的最佳时机
We overestimate the value of coding
漫谈软件缺陷管理
[MySQL must know and know] conditional statement
Deep understanding of modern web browsers (3)
Ethernet development and testing, have you done this step right (2)
codeforces每日5题(均1500)-第十六天
P1085 [NOIP2004 普及组第一题] 不高兴的津津 ← 模拟题
Execution plan of SQL statement
JVM 问题定位工具
Nc19910 [cqoi2007] rectangular rect