当前位置:网站首页>STM32 drive relay stm32f103rct6 drives IO port based on register and library function
STM32 drive relay stm32f103rct6 drives IO port based on register and library function
2022-06-09 22:52:00 【Youxin Electronics】
STM32 Drive relay STM32F103RCT6 Based on register and library function driver IO mouth
Description of the relay

Relay is a kind of small voltage control large voltage device , The input is a switch , There will be no output voltage , The specific wiring method depends on how you use the switch ;
For the specific working principle of the relay, please refer to the previous article “51 The single chip microcomputer drives the relay module to light up ”
Parameter test of relay
Take the relay module of our own store as an example , When the trigger voltage of the relay is higher than a certain value , The relay will be triggered , The trigger light comes on
When measured here 1.3V about , The actual trigger voltage is the best 2V above ,5.5V following ;
When the trigger signal is below a certain value , The relay will reset , Will not be triggered , The trigger light goes out , When measured here 1V, However, the actual trigger signal is recommended to be lower than 0.5V;
STM32F103 Register versioning IO mouth
1: Procedural phenomena 
The signal control pin is STM32F103RCT6 Of PA11 Pin ;
STM32 Control relay - Register version
1. from STM32F10 Series of reference manuals ,GPIO The clock is enabled by APB2 Controlled by peripheral devices ;
As can be seen from the figure above , Only need to IOPA Set as 1, Set others to zero , You can open it GPIOA Enabled by ,
2. Then the configuration port is selected as universal push-pull output , Speed 50MHZ;
As can be seen from the figure CNF11 Configure to 00,MODE11 Configure to 11, Others are set to 0 that will do ;
3. control GPIOA11 output ;
ODR11 Set as 1 Output high level ;
4. Code demonstration ,
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main(void)
{
RCC->APB2ENR = 0x00000004; // open GPIOA Can make
GPIOA->CRH = 0x00003000; // To configure PA11 The pin is in universal push-pull output mode
while(1)
{
GPIOA->ODR = 0x00000800; //PA11 Output high level
Delay_ms(1000);
GPIOA->ODR = 0x00000000; //PA11 Output low level
Delay_ms(1000);
}
}
STM32 Control relay - Library function version
The library function has packed all the registers , We can use it directly ;
Main code :
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure; // Defining structure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); // To configure GPIOA Peripheral clock
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // To configure GPIOA For universal push-pull output
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // Configure the corresponding port
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Configure the speed
GPIO_Init(GPIOA,&GPIO_InitStructure); // Transfer the position of the structure
while(1)
{
GPIO_SetBits(GPIOA,GPIO_Pin_11); // The port is set to high level
Delay_ms(1000); // Time delay 1s
GPIO_ResetBits(GPIOA,GPIO_Pin_11); // The port is set to low level
Delay_ms(1000); // Time delay 1s
}
}
summary
1. The code phenomena of register version and library function version are the same ;
2.IO The port mode should be configured as push-pull output mode , Open drain output mode cannot drive the relay ;
3. This use is 5V Relay version , Required for power supply 5V, If the development board does not 5V Input pin , It can be powered by additional power supply , But the ground of the power supply should be connected with the ground of the single chip microcomputer ;
边栏推荐
- Block certification in Mina
- 【图像分割】基于各向异性热扩散方程的图像分割附matlab代码
- 新人程序员入职,该如何过试用期
- Que se passe - t - il si vous appliquez 8G sur une machine avec 4go de mémoire physique?
- [image denoising] image denoising based on Gaussian, mean, median and bilateral filtering, including Matlab source code
- 还在怀疑数字藏品么?国家队都开始入局了
- 【Jmeter】Jmeter从入门到精通
- C语言0长度数组(可变数组/柔性数组)详解
- M-Arch(番外14)GD32L233评测-驱动段码LCD
- On a machine with 4GB of physical memory, how about applying for 8g of memory?
猜你喜欢

【刷题篇】跳跃游戏

Boolean operation

AI助力,释放法务势能——法大大iTerms合同智审系统正式发布

【刷题篇】最长递增子序列

Some thoughts on matrix chain of design memo solution (dynamic programming method)

【图像重建】基于正则化的图像超分辨重建附matlab代码

关于mongodb的那些安装、配置、报错处理、CRUD操作等再总结

On a machine with 4GB of physical memory, how about applying for 8g of memory?
![[bearing fault decomposition] realize bearing fault signal decomposition based on ITD, including Matlab source code](/img/d6/98a30ab74a402c169cdc44e8057a77.png)
[bearing fault decomposition] realize bearing fault signal decomposition based on ITD, including Matlab source code

Find my technology | in the era of Internet of things, apple find my realizes real intelligent loss prevention
随机推荐
Maximum value and subscript of acquisition matrix of C language test question 168
This book has won the 2022 Beijing college entrance examination composition
这家估值25亿的公司,破产了?
先睹为快!Benji Bananas 第一季奖励活动数据一览!
华泰证券开户安全吗
GUI 用户登录
如何实现高效的IM即时通讯长连接自适应心跳保活机制
原来树状数组可以这么简单?
Getting to know websocket
[image reconstruction] regularization based image super-resolution reconstruction with matlab code
sparksql源码系列 | ResolveReferences规则count(*)详解
Sparksql source code series | the most complete logical plan optimization rules (spark2.3)
AQUANEE将在近期登陆Gate以及BitMart,低位布局的良机
Explanation of leetcode UHF questions (I)
【轴承故障分解】基于 ITD实现轴承故障信号分解含Matlab源码
Experience in database optimization
YUV格式与RGB格式
Learn how to parse SQL from kernel code
Explanation of leetcode UHF questions (III)
All inherited features