STM32驱动SYN6288语音合成模块实现语音播报

news/2024/12/15 19:39:22/

SYN6288语音合成模块使用说明

请跳转该专栏:SYN6288语音合成模块使用说明(MicroPython、STM32、Arduino)-CSDN博客

最终效果

未完待续

接线

STM32

SYN6288

3.3

VDD

G

G

PA2

RXD

代码

工程文件:

https://download.csdn.net/download/qq_44955826/90131372?spm=1001.2014.3001.5503

main.c

#include "stm32f10x.h"  
#include "serial.h"
#include "USART2.h"
#include "voice.h"
#include "Delay.h"int main(void)
{	Serial_Init();USART2_Init();voice_output_fingerprint_input("请放手指");Delay_s(3);voice_output_fingerprint_input("指纹录入成功");Delay_s(3);voice_output_fingerprint_input("指纹录入失败");Delay_s(3);voice_output_fingerprint_input("手指接触不良");Delay_s(3);voice_output_fingerprint_identify("指纹识别成功");Delay_s(3);voice_output_fingerprint_identify("无效指纹");Delay_s(3);voice_output_QR("请提供二维码");Delay_s(3);voice_output_QR("二维码录入成功");Delay_s(3);voice_output_QR("二维码识别成功");Delay_s(3);voice_output_QR("无效二维码");Delay_s(3);voice_output_RFID("请放卡片");Delay_s(3);voice_output_RFID("射频卡录入成功");Delay_s(3);voice_output_RFID("射频卡识别成功");Delay_s(3);voice_output_RFID("无效卡片");while(1){		}	
}

voice.c

#include<stdio.h>
#include "serial.h"
#include "USART2.h"
#include <string.h>		//字符串处理/*
指纹录入中,请放手指
指纹录入成功
指纹录入失败
手指接触不良
指纹识别成功 
无效指纹 
二维码扫描中,请提供二维码
二维码录入成功
二维码识别成功 
无效二维码 
射频卡录入成功 
射频卡识别成功 
无效卡片 
*///写4个函数是因为1个函数查找太慢void voice_output_fingerprint_input(char s[])
{	if(strcmp(s,"指纹录入成功") == 0 ){uint8_t Array[18]={253, 0, 15, 1, 0, 214, 184, 206, 198, 194, 188, 200, 235, 179, 201, 185, 166, 173};USART2_SendArray(Array, 18);}if(strcmp(s,"指纹录入失败") == 0 ){uint8_t Array[18]={253, 0, 15, 1, 0, 214, 184, 206, 198, 194, 188, 200, 235, 202, 167, 176, 220, 201};USART2_SendArray(Array, 18);}if(strcmp(s,"手指接触不良") == 0 ){uint8_t Array[18]={253, 0, 15, 1, 0, 202, 214, 214, 184, 189, 211, 180, 165, 178, 187, 193, 188, 138};USART2_SendArray(Array, 18);}if(strcmp(s,"请放手指") == 0 ){uint8_t Array[14]={253, 0, 11, 1, 0, 199, 235, 183, 197, 202, 214, 214, 184, 219};USART2_SendArray(Array, 14);}
}void voice_output_fingerprint_identify(char s[])
{	if(strcmp(s,"指纹识别成功") == 0 ){uint8_t Array[18]={253, 0, 15, 1, 0, 214, 184, 206, 198, 202, 182, 177, 240, 179, 201, 185, 166, 205};USART2_SendArray(Array, 18);}if(strcmp(s,"无效指纹") == 0 ){uint8_t Array[14]={253, 0, 11, 1, 0, 206, 222, 208, 167, 214, 184, 206, 198, 246};USART2_SendArray(Array, 14);}
}void voice_output_QR(char s[])
{	if(strcmp(s,"请提供二维码") == 0 ){uint8_t Array[18]={253, 0, 15, 1, 0, 199, 235, 204, 225, 185, 169, 182, 254, 206, 172, 194, 235, 225};USART2_SendArray(Array, 18);}if(strcmp(s,"二维码录入成功") == 0 ){uint8_t Array[20]={253, 0, 17, 1, 0, 182, 254, 206, 172, 194, 235, 194, 188, 200, 235, 179, 201, 185, 166, 214};USART2_SendArray(Array, 20);}if(strcmp(s,"二维码识别成功") == 0 ){uint8_t Array[20]={253, 0, 17, 1, 0, 182, 254, 206, 172, 194, 235, 202, 182, 177, 240, 179, 201, 185, 166, 182};USART2_SendArray(Array, 20);}if(strcmp(s,"无效二维码") == 0 ){uint8_t Array[16]={253, 0, 13, 1, 0, 206, 222, 208, 167, 182, 254, 206, 172, 194, 235, 149};USART2_SendArray(Array, 16);}
}void voice_output_RFID(char s[])
{	if(strcmp(s,"请放卡片") == 0 ){uint8_t Array[14]={253, 0, 11, 1, 0, 199, 235, 183, 197, 191, 168, 198, 172, 212};USART2_SendArray(Array, 14);}if(strcmp(s,"射频卡录入成功") == 0 ){uint8_t Array[20]={253, 0, 17, 1, 0, 201, 228, 198, 181, 191, 168, 194, 188, 200, 235, 179, 201, 185, 166, 156};USART2_SendArray(Array, 20);}if(strcmp(s,"射频卡识别成功") == 0 ){ uint8_t Array[20]={253, 0, 17, 1, 0, 201, 228, 198, 181, 191, 168, 202, 182, 177, 240, 179, 201, 185, 166, 252};USART2_SendArray(Array, 20);}if(strcmp(s,"无效卡片") == 0 ){uint8_t Array[14]={253, 0, 11, 1, 0, 206, 222, 208, 167, 191, 168, 198, 172, 237};USART2_SendArray(Array, 14);}
}

voice.h

#ifndef __VOICE_H
#define __VOICE_Hvoid voice_output_fingerprint_input(char s[]);
void voice_output_fingerprint_identify(char s[]);
void voice_output_QR(char s[]);
void voice_output_RFID(char s[]);#endif

serial.c

//串口1打印和输入#include "stm32f10x.h"                  
#include <stdio.h>
#include <stdarg.h>void Serial_Init(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);USART_InitTypeDef USART_InitStructure;USART_InitStructure.USART_BaudRate = 9600;USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;USART_InitStructure.USART_Parity = USART_Parity_No;USART_InitStructure.USART_StopBits = USART_StopBits_1;USART_InitStructure.USART_WordLength = USART_WordLength_8b;USART_Init(USART1, &USART_InitStructure);USART_Cmd(USART1, ENABLE);
}void Serial_SendByte(uint8_t Byte)
{USART_SendData(USART1, Byte);while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);	//当其置1(SET) 标志着串口1接收完成
}//重定向c库函数printf到串口
int fputc(int ch, FILE *f)
{Serial_SendByte(ch);return ch;
}uint8_t Serial_ReceiveByte(void)
{uint8_t Byte;Byte = USART_ReceiveData(USART1);while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);	//当其置1(SET) 标志着串口1发送完成return Byte;
}//重定向c库函数scanf到串口,重写后可使用scanf、getchar等函数
int fgetc(FILE *f)
{uint8_t ch;ch = Serial_ReceiveByte();return ch;
}

serial.h

//串口1打印和输入#ifndef __SERIAL_H
#define __SERIAL_H#include "stm32f10x.h" 
#include <stdio.h>void Serial_Init(void);
void Serial_SendByte(uint8_t Byte);
uint8_t Serial_ReceiveByte(void);#endif

USART2.c

#include "stm32f10x.h"                  
#include <stdio.h>
#include <stdarg.h>void USART2_Init(void)
{RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;		GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);USART_InitTypeDef USART_InitStructure;USART_InitStructure.USART_BaudRate = 9600;USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;USART_InitStructure.USART_Parity = USART_Parity_No;USART_InitStructure.USART_StopBits = USART_StopBits_1;USART_InitStructure.USART_WordLength = USART_WordLength_8b;USART_Init(USART2, &USART_InitStructure);USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);NVIC_InitTypeDef NVIC_InitStructure;NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;NVIC_Init(&NVIC_InitStructure);USART_Cmd(USART2, ENABLE);
}void USART2_SendByte(uint8_t Byte)
{USART_SendData(USART2, Byte);while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
}void USART2_SendArray(uint8_t *Array, uint16_t Length)
{uint16_t i;for (i = 0; i < Length; i ++){USART2_SendByte(Array[i]);}
}char USART2_RxData[100];		//全局变量,用于储存USART2获得的文本数据,最多100个字符
uint8_t USART2_RxFlag;		//全局变量,串口接收标志位/*
下面的中断服务函数只会向USART2_RxData[]数组中储存第1对{}之间的内容
如  fdgh{"lamp": 77,"curtain": 3},"airConditioner": {2}frgtr  发送至USART2后,USART2_RxData[]数组中的内容为  {"lamp": 77,"curtain": 3}
如果只有 { 而没有 } ,USART2_RxData[]数组的'\0'结束符的位置就未被重置,后续处理就会出错
*/void USART2_IRQHandler(void)
{static uint8_t RxState = 0;static uint8_t count = 0;	//USART2_RxData[]数组的下标if (USART_GetITStatus(USART2, USART_IT_RXNE) == SET){uint8_t RxData = USART_ReceiveData(USART2);if (RxState == 0){if (RxData == '{' && USART2_RxFlag == 0){RxState = 1;count = 0;}}if (RxState == 1){if (RxData == '}'){USART2_RxData[count] = '}';USART2_RxData[count + 1] = '\0';	//标志数组的结束,方便后续处理RxState = 0;USART2_RxFlag = 1;count = 0;}			else{USART2_RxData[count] = RxData;count ++;	}}USART_ClearITPendingBit(USART2, USART_IT_RXNE);}
}

USART2.h

#ifndef __USART2_H
#define __USART2_H#include <stdio.h>extern char USART2_RxData[100];		
extern uint8_t USART2_RxFlag;		void USART2_Init(void);
void USART2_SendByte(uint8_t Byte);
void USART2_SendArray(uint8_t *Array, uint16_t Length);#endif

Delay.c

#include "stm32f10x.h"/*** @brief  微秒级延时* @param  xus 延时时长,范围:0~233015* @retval 无*/
void Delay_us(uint32_t xus)
{SysTick->LOAD = 72 * xus;				//设置定时器重装值SysTick->VAL = 0x00;					//清空当前计数值SysTick->CTRL = 0x00000005;				//设置时钟源为HCLK,启动定时器while(!(SysTick->CTRL & 0x00010000));	//等待计数到0SysTick->CTRL = 0x00000004;				//关闭定时器
}/*** @brief  毫秒级延时* @param  xms 延时时长,范围:0~4294967295* @retval 无*/
void Delay_ms(uint32_t xms)
{while(xms--){Delay_us(1000);}
}/*** @brief  秒级延时* @param  xs 延时时长,范围:0~4294967295* @retval 无*/
void Delay_s(uint32_t xs)
{while(xs--){Delay_ms(1000);}
} 

Delay.h

#ifndef __DELAY_H
#define __DELAY_Hvoid Delay_us(uint32_t us);
void Delay_ms(uint32_t ms);
void Delay_s(uint32_t s);#endif


http://www.ppmy.cn/news/1555388.html

相关文章

Dual-Write Problem 双写问题(微服务)

原文链接https://www.confluent.io/blog/dual-write-problem/ 双写问题发生于当两个外部系统必须以原子的方式更新时。 问题 说有人到银行存了一笔钱&#xff0c;触发 DepositFunds 命令&#xff0c;DepositFunds 命令被发送到Account microservice。 Account microservice需…

vscode无密码远程登录,不用输密码

客户端配置 生成ssh密钥&#xff0c;得到私钥id_rsa和公钥id_rsa.pub文件 在用户目录下找到.ssh/config文件&#xff0c;这是vscode远程配置文件 一般内容如下&#xff1a; Host 192.168.1.10HostName 192.168.1.10User xxxx这个配置文件描述了目标主机和用户名 需要添加私…

【潜意识Java】期末考试可能考的选择题(附带答案解析)

目录 选择题一&#xff1a;Java 数据类型 选择题二&#xff1a;Java 控制结构 选择题三&#xff1a;面向对象编程 选择题四&#xff1a;Java 集合框架 选择题五&#xff1a;Java 异常处理 选择题六&#xff1a;Java 方法 选择题七&#xff1a;Java 流程控制 选择题八&a…

b站视频爬虫-词云分析

一、设置爬虫程序 # requests 请求b站视频 import jsonimport fake_useragent import requests from lxml import etreeif __name__ == __main__:# UA伪装head = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like …

fastadmin集成kindeditor编辑器解决段后距问题--全网唯一

背景 由于项目的需求使用fastadmin推荐的编辑器kindeditor&#xff0c;使用过程中发现没有段后距这个bug。查询搜索了所有的网上来源&#xff0c;都没有解决方案。鉴宇客户非常需要该功能&#xff0c;奋战几天写端代码实现了该功能。 插件实现 KindEditor.plugin(paragra…

机器视觉 (深度学习 - 目标查找Faster R-CNN)

深度学习目标搜索&#xff0c;在工业上常被用于目标跟踪、缺陷定位等应用。 Faster R-CNN是目标查找算法中更高精度的应用。Faster R-CNN很多都是用Python来实现&#xff0c;下面发一个TensorFlow 实现Faster R-CNN的代码。 import tensorflow as tf from tensorflow.keras i…

Mac上安装illustrator 2025/2024总是提示130/131/已损坏等解决方法

最近总有人问我&#xff0c;重装illustrator 2025/2024版本的时候&#xff0c;第一次安装特别顺利&#xff0c;第二次重装就是各种错误不断&#xff0c;怎么也安装不上&#xff1f;今天给大家汇总下常出现的错误提示解决方法&#xff1a; 1."xxx"已损坏&#xff0c;无…

C#_泛型方法的定义及使用

在C#语言中泛型方法是指通过泛型来约束方法中的参数类型&#xff0c;也可以理解为对数据类型设置了参数。 如果没有泛型&#xff0c;每次方法中的参数类型都是固定的&#xff0c;不能随意更改。 在使用泛型后&#xff0c;方法中的数据类型则有指定的泛型来约束&#xff0c;既…