加入星計劃,您可以享受以下權益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴散
  • 作品版權保護
  • 300W+ 專業(yè)用戶
  • 1.5W+ 優(yōu)質創(chuàng)作者
  • 5000+ 長期合作伙伴
立即加入

STM32傳感器外設集-語音模塊(SYN6288)驅動代碼編寫

06/17 16:36
3508
服務支持:
技術交流群

完成交易后在“購買成功”頁面掃碼入群,即可與技術大咖們分享疑惑和經(jīng)驗、收獲成長和認同、領取優(yōu)惠和紅包等。

虛擬商品不可退

當前內(nèi)容為數(shù)字版權作品,購買后不支持退換且無法轉移使用。

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點資訊討論
放大
實物圖
相關方案
  • 方案介紹
    • 前言
    • ?代碼編寫
    • 參考
  • 相關文件
  • 推薦器件
  • 相關推薦
  • 電子產(chǎn)業(yè)圖譜
申請入駐 產(chǎn)業(yè)圖譜

前言

如何使用該模塊呢,首先,SYN6288是使用串口通訊的,很多模塊其實都是使用串口通訊,有助于指令的輸入,那么使用串口通訊就簡單了,首先配置串口等

?代碼編寫

SYN6288.h

這里的話我使用的是串口4,當然C8T6的話是只要三個串口的,如何需要使用,可以自行修改串口配置

#ifndef _SYN6288_H_
#define _SYN6288_H_
#include "stm32f10x.h"

/**  
  ******************************************************************************
  *  @File     SYN6288.h
  *  @Author   Velscode  
  *  @Email    velscode@gmail.com
  *  @Brief    TTS 芯片 SYN6288驅動頭文件(基于STM32F10x)
  *            使用了USART2(A2A3)
  ******************************************************************************
  */
	/****************************** SYN6288 引腳配置參數(shù)定義***************************************/
#define             SYN6288_GPIO_APBxClock_FUN              RCC_APB2PeriphClockCmd
#define             SYN6288_GPIO_CLK                        RCC_APB2Periph_GPIOC
#define             SYN6288_GPIO_PORT                       GPIOC
#define             SYN6288_GPIO_PIN                        GPIO_Pin_6
#define      				SYN6288_Read_GPIO_IN()	                GPIO_ReadInputDataBit ( SYN6288_GPIO_PORT, SYN6288_GPIO_PIN ) 
  // 串口4-UART4
#define  DEBUG_USARTx                   UART4
#define  DEBUG_USART_CLK                RCC_APB1Periph_UART4
#define  DEBUG_USART_APBxClkCmd         RCC_APB1PeriphClockCmd
#define  DEBUG_USART_BAUDRATE           9600

// USART GPIO 引腳宏定義
#define  DEBUG_USART_GPIO_CLK           (RCC_APB2Periph_GPIOC)
#define  DEBUG_USART_GPIO_APBxClkCmd    RCC_APB2PeriphClockCmd
    
#define  DEBUG_USART_TX_GPIO_PORT         GPIOC   
#define  DEBUG_USART_TX_GPIO_PIN          GPIO_Pin_10
#define  DEBUG_USART_RX_GPIO_PORT       GPIOC
#define  DEBUG_USART_RX_GPIO_PIN        GPIO_Pin_11

#define  DEBUG_USART_IRQ                UART4_IRQn
#define  DEBUG_USART_IRQHandler         UART4_IRQHandler

void SYN6288_GPIO_Config ( void );
void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch);
void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str );
void SYN688_USART_Config(void);
void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch);
void SYN_FrameInfo(char *HZdata);
void Usart_SendString( USART_TypeDef * pUSARTx, char *str);
/* 音量控制 */
void Volinme(uint8_t Y_L);
/* 語調控制 */
void Intonation(uint8_t Y_L);
/* 語速控制 */
void Speed_pacing(uint8_t Y_L);
/* 人控制 */
void speed_man(uint8_t Y_L);
#endif /*_SYN6288_H_*/
/* End of File ------------------------------------------------------------- */

SYN6288.c

這里的話就是配置參數(shù),還有給SYN6288發(fā)指令等

/**
******************************************************************************
*  @File     SYN6288.c
*  @Author   Velscode  
*  @Email    velscode@gmail.com
*  @Brief    TTS 芯片 SYN6288驅動源代碼文件(基于STM32F10x)
*            使用了USART2(A2A3)
******************************************************************************
*/

/* Internal Function Declaration ------------------------------------------- */
void usart2_Init(unsigned int bound);

/* Header Files ------------------------------------------------------------ */
#include "SYN6288.h"
#include "string.h"
#include "bsp_SysTick.h"
#include <string.h>


 /**
  * @brief  配置嵌套向量中斷控制器NVIC
  * @param  無
  * @retval 無
  */
static void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* 嵌套向量中斷控制器組選擇 */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  
  /* 配置USART為中斷源 */
  NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ;
  /* 搶斷優(yōu)先級*/
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  /* 子優(yōu)先級 */
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  /* 使能中斷 */
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  /* 初始化配置NVIC */
  NVIC_Init(&NVIC_InitStructure);
}
//讀忙
void SYN6288_GPIO_Config ( void )
{		
	/*定義一個GPIO_InitTypeDef類型的結構體*/
	GPIO_InitTypeDef GPIO_InitStructure;


	/* 配置 LED1 引腳 */
	SYN6288_GPIO_APBxClock_FUN(SYN6288_GPIO_CLK, ENABLE); 															   
	GPIO_InitStructure.GPIO_Pin = SYN6288_GPIO_PIN;	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
	GPIO_Init ( SYN6288_GPIO_PORT, & GPIO_InitStructure );	
	
}

 /**
  * @brief  USART GPIO 配置,工作參數(shù)配置
  * @param  無
  * @retval 無
  */
void SYN688_USART_Config(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;

	// 打開串口GPIO的時鐘
	DEBUG_USART_GPIO_APBxClkCmd(DEBUG_USART_GPIO_CLK, ENABLE);
	
	// 打開串口外設的時鐘
	DEBUG_USART_APBxClkCmd(DEBUG_USART_CLK, ENABLE);

	// 將USART Tx的GPIO配置為推挽復用模式
	GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_GPIO_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStructure);

  // 將USART Rx的GPIO配置為浮空輸入模式
	GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_GPIO_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStructure);
	
	// 配置串口的工作參數(shù)
	// 配置波特率
	USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
	// 配置 針數(shù)據(jù)字長
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	// 配置停止位
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	// 配置校驗位
	USART_InitStructure.USART_Parity = USART_Parity_No ;
	// 配置硬件流控制
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	// 配置工作模式,收發(fā)一起
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	// 完成串口的初始化配置
	USART_Init(DEBUG_USARTx, &USART_InitStructure);
	
	// 串口中斷優(yōu)先級配置
	NVIC_Configuration();
	
	// 使能串口接收中斷
	USART_ITConfig(DEBUG_USARTx, USART_IT_RXNE, ENABLE);	
	
	// 使能串口
	USART_Cmd(DEBUG_USARTx, ENABLE);		

  // 清除發(fā)送完成標志
	//USART_ClearFlag(USART1, USART_FLAG_TC);     
}
//其實是USART2_Send_Byte
/*****************  發(fā)送一個字符 **********************/
void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
{
	/* 發(fā)送一個字節(jié)數(shù)據(jù)到USART */
	USART_SendData(pUSARTx,ch);
		
	/* 等待發(fā)送數(shù)據(jù)寄存器為空 */
	while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);	
}
/*****************  發(fā)送字符串 **********************/
void Usart_SendString( USART_TypeDef * pUSARTx, char *str)
{
	unsigned int k=0;
  do 
  {
      Usart_SendByte( pUSARTx, *(str + k) );
      k++;
  } while(*(str + k)!='?');
  
  /* 等待發(fā)送完成 */
  while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
  {}
}

//語音合成
void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str )
{
	
	if(SYN6288_Read_GPIO_IN()==Bit_RESET)/* x us后仍為高電平表示數(shù)據(jù)“1” */
	{

				char * p = str;
		int len = 0,check=0xFD,i;
		
		while( *p++ != 0 )
		{
				len++;
		
		}
		
		len+=3;
		
		Usart_SendByte(DEBUG_USARTx,0xFD);
		
		Usart_SendByte( DEBUG_USARTx,len / 256 );
		Usart_SendByte( DEBUG_USARTx,len % 256 );
		check  = check ^ ( len / 256 ) ^ ( len % 256 );
		
		Usart_SendByte( DEBUG_USARTx,0x01 );
		Usart_SendByte( DEBUG_USARTx,0x01 );
		check = check ^ 0x01 ^ 0x01;
		
		for( i = 0; i < len-3; i++ )
		{
				Usart_SendByte(DEBUG_USARTx,*str);
				check ^= ( *str );
				str++;
		}
		Usart_SendByte(DEBUG_USARTx,check);   
				
		Delay_ms(150*len);	
	}

}
/* 音量控制 */
void Volinme(uint8_t Y_L)
{
		uint8_t num ;
	num = Y_L+48;
	Usart_SendByte(DEBUG_USARTx,0xFD);
	Usart_SendByte(DEBUG_USARTx,0x00);
	Usart_SendByte(DEBUG_USARTx,0x06);
	Usart_SendByte(DEBUG_USARTx,0x01);
	Usart_SendByte(DEBUG_USARTx,0x01);
	Usart_SendByte(DEBUG_USARTx,0x5B);
	Usart_SendByte(DEBUG_USARTx,0x76);
	//控制音量
	Usart_SendByte(DEBUG_USARTx,num);
	
	Usart_SendByte(DEBUG_USARTx,0x5D);
//	uint8_t num[9] ;
//	
//	num[0] = 0xFD;
//	num[1] = 0x00;
//	num[2] = 0x06;
//	num[3] = 0x01;
//	num[4] = 0x01;
//	num[5] = 0x5B;
//	num[6] = 0x76;
//	//控制音量
//	num[7] = Y_L+48;
//	num[8] = 0x5D;
//	
//	Usart_SendByte(DEBUG_USARTx,num[8]);
}
/* 語調控制 */
void Intonation(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SendByte(DEBUG_USARTx,0xFD);
	Usart_SendByte(DEBUG_USARTx,0x00);
	Usart_SendByte(DEBUG_USARTx,0x06);
	Usart_SendByte(DEBUG_USARTx,0x01);
	Usart_SendByte(DEBUG_USARTx,0x01);
	Usart_SendByte(DEBUG_USARTx,0x5B);
	Usart_SendByte(DEBUG_USARTx,0x74);
	//控制音量
	Usart_SendByte(DEBUG_USARTx,num);
	
	Usart_SendByte(DEBUG_USARTx,0x5D);
	

}
/* 語速控制 */
void Speed_pacing(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SendByte(DEBUG_USARTx,0xFD);
	Usart_SendByte(DEBUG_USARTx,0x00);
	Usart_SendByte(DEBUG_USARTx,0x06);
	Usart_SendByte(DEBUG_USARTx,0x01);
	Usart_SendByte(DEBUG_USARTx,0x01);
	Usart_SendByte(DEBUG_USARTx,0x5B);
	Usart_SendByte(DEBUG_USARTx,0x73);
	//控制音量
	Usart_SendByte(DEBUG_USARTx,num);
	
	Usart_SendByte(DEBUG_USARTx,0x5D);
	
}
/* 人控制 */
void speed_man(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SendByte(DEBUG_USARTx,0xFD);
	Usart_SendByte(DEBUG_USARTx,0x00);
	Usart_SendByte(DEBUG_USARTx,0x07);
	Usart_SendByte(DEBUG_USARTx,0x01);
	Usart_SendByte(DEBUG_USARTx,0x01);
	Usart_SendByte(DEBUG_USARTx,0x5B);
	Usart_SendByte(DEBUG_USARTx,0x6D);
	Usart_SendByte(DEBUG_USARTx,0x35);
	//控制音量
	Usart_SendByte(DEBUG_USARTx,num);
	
	Usart_SendByte(DEBUG_USARTx,0x5D);
	
}
/* End of File ------------------------------------------------------------- */



stm32f10x_it.h

?寫完配置函數(shù),當然不能忘記配置中斷服務,把這段代碼加入該文件的中,那么你的SYN8622還差一步就大功告成了

#include "SYN6288.h"

// 串口中斷服務函數(shù)
void DEBUG_USART_IRQHandler(void)
{
  uint8_t ucCh;
	if ( USART_GetITStatus ( DEBUG_USARTx, USART_IT_RXNE ) != RESET )
	{
		ucCh  = USART_ReceiveData( DEBUG_USARTx );
		
		if ( strUSART_Fram_Record .InfBit .FramLength < ( RX_BUF_MAX_LEN - 1 ) )                       //預留1個字節(jié)寫結束符
			   strUSART_Fram_Record .Data_RX_BUF [ strUSART_Fram_Record .InfBit .FramLength ++ ]  = ucCh;

	}
	 	 
	if ( USART_GetITStatus( DEBUG_USARTx, USART_IT_IDLE ) == SET )                                         //數(shù)據(jù)幀接收完畢
	{
    strUSART_Fram_Record .InfBit .FramFinishFlag = 1;		
		
		ucCh = USART_ReceiveData( DEBUG_USARTx );                                                              //由軟件序列清除中斷標志位(先讀USART_SR,然后讀USART_DR)	
  }	
}

?main.c

#include "bsp_usart1.h"  
#include "stm32f10x.h"
#include "bsp_SysTick.h"
#include "SYN6288.h"
void Rap_And_God(void);
/**
  * @brief  主函數(shù)
  * @param  無
  * @retval 無
  */
	
int main ( void )
{
	
	/* 初始化 */
	USARTx_Config (); 
  //USART_Config ();                                                              //初始化串口1
	SysTick_Init ();                                                               //配置 SysTick 為 1ms 中斷一次                                                         //初始化WiFi模塊使用的接口和外設    
                                                         //初始化RGB彩燈
	//語音播報系統(tǒng)
	SYN6288_GPIO_Config();
	SYN688_USART_Config();

	printf ( "rn 語音控制識別系統(tǒng)(Android+WiFi) rn" );

	while(1){
			Rap_And_God();
	
	};


	
	
}
/**
  * @brief  封裝語音函數(shù)
  * @param  無
  * @retval 無
  */
void Rap_And_God(void)
{
    SYN6288_Speech(DEBUG_USARTx,"粉紅的長裙");
		
		
    SYN6288_Speech(DEBUG_USARTx,"蓬松的頭發(fā)");
    SYN6288_Speech(DEBUG_USARTx,"牽著我的手看最新展出的油畫");
    SYN6288_Speech(DEBUG_USARTx,"無人的街道");
    SYN6288_Speech(DEBUG_USARTx,"在空蕩的家里");
    SYN6288_Speech(DEBUG_USARTx,"就只剩我一個人狂歡的趴體");
    SYN6288_Speech(DEBUG_USARTx,"就當是一場夢");
    SYN6288_Speech(DEBUG_USARTx,"醒了還是很感動");
    SYN6288_Speech(DEBUG_USARTx,"還是很想被你保護我心里的慘痛");
    SYN6288_Speech(DEBUG_USARTx,"喜歡我很辛苦");
    SYN6288_Speech(DEBUG_USARTx,"其實我都清楚");
    SYN6288_Speech(DEBUG_USARTx,"放心這世界很大我記得你的叮囑");
}

/*********************************************END OF FILE**********************/

參考

第二章 SYN6288語音合成模塊的使用icon-default.png?t=N7T8https://blog.csdn.net/qq_44645742/article/details/124871041?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170212810616800185858985%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170212810616800185858985&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_click~default-1-124871041-null-null.142^v96^pc_search_result_base7&utm_term=syn6288%E6%A8%A1%E5%9D%97%E4%BD%BF%E7%94%A8&spm=1018.2226.3001.4187基于STM32 + SYN6288語音播報icon-default.png?t=N7T8https://blog.csdn.net/zhouml_msn/article/details/125204251?ops_request_misc=&request_id=&biz_id=102&utm_term=syn6288%E6%A8%A1%E5%9D%97%E4%BD%BF%E7%94%A8&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-2-125204251.nonecase&spm=1018.2226.3001.4187

聯(lián)系方式 微信號:13648103287

  • 聯(lián)系方式.docx

推薦器件

更多器件
器件型號 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊 ECAD模型 風險等級 參考價格 更多信息
STM32F103RBT6 1 STMicroelectronics Mainstream Performance line, Arm Cortex-M3 MCU with 128 Kbytes of Flash memory, 72 MHz CPU, motor control, USB and CAN

ECAD模型

下載ECAD模型
$10.15 查看
CP2102N-A02-GQFN28R 1 Silicon Laboratories Inc USB Bus Controller, CMOS, QFN-28

ECAD模型

下載ECAD模型
$2.5 查看
PIC32MX575F512L-80I/PT 1 Microchip Technology Inc 32-BIT, FLASH, 80 MHz, RISC MICROCONTROLLER, PQFP100, 12 X 12 MM, 1 MM HEIGHT, LEAD FREE, PLASTIC, TQFP-100

ECAD模型

下載ECAD模型
$8.67 查看

相關推薦

電子產(chǎn)業(yè)圖譜

方案定制,程序設計方案、單片機程序設計與講解、APP定制開發(fā)。本公眾號致力于向讀者傳遞關于程序設計和開發(fā)的相關知識,并分享一些關于軟件開發(fā)的最佳實踐。如果您有什么問題或建議,請隨時聯(lián)系我們。我們將竭誠為您服務