当前位置:网站首页>[the fourth day of actual combat of stm32f401ret6 smart lock project in 10 days] voice control is realized by externally interrupted keys
[the fourth day of actual combat of stm32f401ret6 smart lock project in 10 days] voice control is realized by externally interrupted keys
2022-06-13 01:50:00 【It's Beichen bupiacra】
External interrupt keys realize voice control
One 、 Realize voice function
1、 Voice module information
The first thing we need to do is to understand how the voice module is used , Then you need to find the data manual of the voice module , Here are the parameters of the voice module 




2、 Code implementation
STM32F401RET6 Interface with voice module 
After reading the above materials, we can follow the data manual and STM32F401RET6 With the schematic diagram of the voice module to complete our code
Let's write our code , How the specific project is established , Not here , No, you can go back to the front and have a look , Let's go straight to the code
voice.c Code
#include "voice.h"
#include "delay.h"
void Voice_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;// Declare struct variables
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);// open GPIOC The clock of
// initialization PB8 and PB9
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;// General output
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;// Push pull output
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;// The first 5 Pin No
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;// No up and down
GPIO_InitStruct.GPIO_Speed = GPIO_Fast_Speed;// Speed 50Mhz
GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;// Universal input
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;// The first 4 Pin No
GPIO_Init(GPIOC, &GPIO_InitStruct);
}
void Data_H(void)
{
Voice_Data_H;
Delay_us(1500);
Voice_Data_L;
Delay_us(500);
}
void Data_L(void)
{
Voice_Data_H;
Delay_us(500);
Voice_Data_L;
Delay_us(1500);
}
void Voice_SendData(u8 data)
{
u8 i;
Voice_Data_H;
Delay_ms(8);
Voice_Data_L;
Delay_ms(1);
for(i = 0;i < 8;i++)
{
if(data & (0x80 >> i))
{
Data_H();
}
else
{
Data_L();
}
}
}
voice.h Code , It contains a bit band operation header file and a delay header file
#ifndef _VOICE_H
#define _VOICE_H
#include "stm32f4xx.h"
#include "delay.h"
#include "io_bit.h"
#define Voice_Data_H PCout(5) = 1
#define Voice_Data_L PCout(5) = 0
#define Voice_BUSY PCin(4)
void Voice_Config(void);
void Voice_SendData(u8 data);
#endif
main.h Also include voice.h
#ifndef _MAIN_H
#define _MAIN_H
#include "stm32f4xx.h"
#include "stdio.h"
#include "led.h"
#include "delay.h"
#include "key.h"
#include "usart.h"
#include "voice.h"
#include "systick.h"
#include "exit.h"
#endif
main.c Code for
#include "main.h"
int main()
{
Voice_Config();
Delay_ms(500);
Voice_SendData(0x18);
Delay_ms(100);
while(Voice_BUSY);
while(1);
}
In this way, the voice module can sound , Now let's use external interrupts and buttons to realize voice control
Two 、 External interrupt keys realize voice control
The code of the voice module remains unchanged , We add the external interrupt code and change the code of the main program
exit.h Code
#ifndef _EXIT_H
#define _EXIT_H
#include "stm32f4xx.h"
void Exit_Config(void);
#endif
exit.c Code
#include "exit.h"
#include "voice.h"
#include "led.h"
void Exit_Config(void)
{
EXTI_InitTypeDef exit_InitTypeDef;
NVIC_InitTypeDef nvic_InitTypeDef;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC,EXTI_PinSource13);
exit_InitTypeDef.EXTI_Line = EXTI_Line13;
exit_InitTypeDef.EXTI_Trigger = EXTI_Trigger_Falling;
exit_InitTypeDef.EXTI_Mode = EXTI_Mode_Interrupt;
exit_InitTypeDef.EXTI_LineCmd = ENABLE;
EXTI_Init(&exit_InitTypeDef);
nvic_InitTypeDef.NVIC_IRQChannel=EXTI15_10_IRQn;
nvic_InitTypeDef.NVIC_IRQChannelCmd=ENABLE;
nvic_InitTypeDef.NVIC_IRQChannelPreemptionPriority=2;
nvic_InitTypeDef.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&nvic_InitTypeDef);
}
// External interrupt
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
LED1 = 0;
Delay_ms(500);
Voice_SendData(0x18);
Delay_ms(100);
while(Voice_BUSY);
}
EXTI_ClearITPendingBit(EXTI_Line13);
}
main.h Include voice.h and exit.h
#ifndef _MAIN_H
#define _MAIN_H
#include "stm32f4xx.h"
#include "stdio.h"
#include "led.h"
#include "delay.h"
#include "key.h"
#include "usart.h"
#include "voice.h"
#include "systick.h"
#include "exit.h"
#endif
main.c Code
#include "main.h"
int main()
{
Led_Config();//LED initialization
Voice_Config();
Exit_Config();
Key_Init();// Key initialization
while(1)
{
}
}
In this way, we use external interrupt buttons to realize voice control
If this blog post is helpful to you, please pay attention to it 、 give the thumbs-up 、 Collect it , Thank you for your support !
There will be related experiments on the system tick timer later , Keep updating... Every day …
边栏推荐
- Cmake has no obvious error after compilation, but prompts that pthread cannot be found
- VI keyboard diagram
- DFS and BFS to solve Treasure Island exploration
- [official document summary] writing standards for academic dissertations of National University of science and technology
- 30: Kakfa simulates JSON data generation and transmission
- Detailed understanding of white noise
- Service creation and operation example of ROS
- rsync 傳輸排除目錄
- 服务器安装jupyterlab以及远程登录配置
- 【软考】软件设计师知识点整理(待更新)
猜你喜欢

Detailed explanation of maxpooling corresponding to conv1d, conv2d and conv3d machines of tensorflow2

Magics 23.0 how to activate and use the slice preview function of the view tool page

About tkinter Canvas does not display pictures

微服务开发环境搭建

关于tkinter.Canvas 不显示图片的问题

matplotlib画图中文乱码

Establishment of microservice development environment

Startup, connection and stop of MySQL service

Vscode configuration header file -- Take opencv and its own header file as an example

Restful interface specification annotation of pringboot (2)
随机推荐
Devexpress implementation flow chart
[Andoid][踩坑]CTS 11_r3开始出现的testBootClassPathAndSystemServerClasspath_nonDuplicateClasses FAIL问题分析
PyFlink实现自定义SourceFunction
[MathType] use MathType to output latex style formula
This of phaser3 add. sprite
JSON and protobuf Any interchange
Detailed understanding of white noise
6、 Implementation of warehouse out management function
Magics 23.0 how to activate and use the slice preview function of the view tool page
Unity JsonUtility 无法序列化List
[sequence structure, branch structure, loop structure, continue statement, break statement, return statement] (learning Note 6 -- C language process control)
MySQL download and installation
微服务开发环境搭建
Anims of phaser3
The first cell of devaxpress CXGRID after inserting a row is in focus editing status
Alertwindowmanager pop up prompt window help (Part 1)
[learn FPGA programming from scratch -22]: Advanced chapter - Architecture - Design and modeling of FPGA internal hardware circuit
水管工游戏
How do you use your own data to achieve your marketing goals?
How to learn C language and share super detailed experience (learning note 1 -- basic data types of C language)