当前位置:网站首页>[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 …
边栏推荐
- Devaxpress Chinese description --tcxpropertiesstore (property store recovery control)
- Delphi implements adding a column of serial number to the CXGRID list
- Cmake has no obvious error after compilation, but prompts that pthread cannot be found
- Decompression and compression of chrome resource file Pak
- Restful interface specification annotation of pringboot (2)
- Stm32 3*3 matrix key (register version)
- Numpy multidimensional array transpose transpose
- Installing pytorch geometric
- Note: common gadgets in project architecture
- ng-tv-focusable
猜你喜欢

Devaxpress Chinese description -- tdxgallerycontrol object (gallery component)

matplotlib画图中文乱码

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

pringboot之restfull接口规范注解(二)

Devexpress implementation flow chart

dfs与bfs解决宝岛探险

Interruption of 51 single chip microcomputer learning notes (external interruption, timer interruption, interrupt nesting)

万字讲清 synchronized 和 ReentrantLock 实现并发中的锁

Opencv camera calibration (1): internal and external parameters, distortion coefficient calibration and 3D point to 2D image projection

TensorFlow2的Conv1D, Conv2D,Conv3D机器对应的MaxPooling详解
随机推荐
Vs how to enter chromium subprocess debugging
六、出库管理功能的实现
Pyflink implements custom sourcefunction
Run Presto under docker to access redis and Bi presentation
Startup, connection and stop of MySQL service
Delphi Google API text to speech MP3 file
What is Google plus large text ads? How to use it?
Magics 23.0 how to activate and use the slice preview function of the view tool page
Server installation jupyterab and remote login configuration
Devaxpress Chinese description --tcximagelist (enhanced image list control)
Read routing table
一种不带CPU的DPU架构:Hyperion
【软考】软件设计师知识点整理(待更新)
Logging system in chromium
Introduction to Google unit testing tools GTEST and gmoke
Plumber game
[printf function and scanf function] (learning note 5 -- standard i/o function)
How many smart bids does Google have?
Use of Arduino series pressure sensors and detected data displayed by OLED (detailed tutorial)
Combining strings and numbers using ssstream