加入星計(jì)劃,您可以享受以下權(quán)益:

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

STM32傳感器外設(shè)集-語(yǔ)音識(shí)別模塊(LD3320)驅(qū)動(dòng)代碼編寫(xiě)

06/11 09:56
3187
服務(wù)支持:
技術(shù)交流群

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

虛擬商品不可退

當(dāng)前內(nèi)容為數(shù)字版權(quán)作品,購(gòu)買后不支持退換且無(wú)法轉(zhuǎn)移使用。

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

前言

LD3320是一款由icroute公司生產(chǎn)的語(yǔ)音識(shí)別芯片。它具有高性能的語(yǔ)音識(shí)別能力,可以廣泛應(yīng)用于各種智能控制、語(yǔ)音交互等場(chǎng)景。以下是關(guān)于LD3320語(yǔ)音識(shí)別模塊的詳細(xì)介紹:

1. 基本原理:LD3320語(yǔ)音識(shí)別模塊通過(guò)識(shí)別預(yù)先內(nèi)置的指令來(lái)實(shí)現(xiàn)對(duì)語(yǔ)音的控制。它的工作模式主要有三種:普通模式、按鍵模式和口令模式。在口令模式下,設(shè)備需要一級(jí)喚醒詞(口令)來(lái)啟動(dòng)ASR進(jìn)程,從而避免誤動(dòng)作。

2. 應(yīng)用場(chǎng)景:LD3320語(yǔ)音識(shí)別模塊可以廣泛應(yīng)用于家居智能控制、智能小車DIY設(shè)計(jì)、畢業(yè)設(shè)計(jì)創(chuàng)新功能、個(gè)人DIY設(shè)計(jì)以及語(yǔ)音控制嵌入式產(chǎn)品設(shè)計(jì)等領(lǐng)域。

3. 性能特點(diǎn):LD3320具有較高的識(shí)別準(zhǔn)確率和穩(wěn)定性,能夠在各種環(huán)境下實(shí)現(xiàn)精確的語(yǔ)音識(shí)別。此外,它還具有較低的功耗和較小的體積,便于集成到各種設(shè)備中。

4. 技術(shù)參數(shù):LD3320語(yǔ)音識(shí)別模塊具備50條預(yù)設(shè)指令的識(shí)別能力。在接收到語(yǔ)音指令后,模塊會(huì)根據(jù)指令執(zhí)行相應(yīng)的操作。其工作電壓范圍為3.3V-5V,適合多種電源供應(yīng)方案。

5. 接口方式:LD3320模塊采用標(biāo)準(zhǔn)的TTL電平接口,易于與微控制器、單片機(jī)等設(shè)備連接。同時(shí),它還具備完善的開(kāi)發(fā)文檔和示例代碼,便于開(kāi)發(fā)者進(jìn)行二次開(kāi)發(fā)。

6. 市場(chǎng)前景:隨著智能家居智能硬件等領(lǐng)域的快速發(fā)展,對(duì)語(yǔ)音識(shí)別技術(shù)的需求日益增長(zhǎng)。LD3320作為一種具有較高性能和實(shí)用性的語(yǔ)音識(shí)別模塊,具有廣闊的市場(chǎng)前景。

本節(jié)主要貼上以前寫(xiě)的語(yǔ)音識(shí)別外設(shè)LD3320,希望對(duì)大家有用,本人已經(jīng)測(cè)試過(guò)有用

如何使用,將下面這段函數(shù)添加到功能函數(shù)中

switch(nAsrStatus)
		{
			case LD_ASR_RUNING:
				
			case LD_ASR_ERROR:		
					break;
			case LD_ASR_NONE:
					nAsrStatus=LD_ASR_RUNING;
					if (RunASR()==0)//啟動(dòng)一次ASR識(shí)別流程:ASR初始化,ASR添加關(guān)鍵詞語(yǔ),啟動(dòng)ASR運(yùn)算
					{		
						nAsrStatus = LD_ASR_ERROR;
					}
					break;
			case LD_ASR_FOUNDOK:
					 nAsrRes = LD_GetResult( );//一次ASR識(shí)別流程結(jié)束,去取ASR識(shí)別結(jié)果										 
					 printf("rn識(shí)別碼:%d", nAsrRes);			 		
								
					 switch(nAsrRes)		   			//對(duì)結(jié)果執(zhí)行相關(guān)操作,客戶修改
						{
							case CODE_LSD:					//命令“流水燈”
							{
									printf(" 流水燈 指令識(shí)別成功rn"); 
							    //SYN6288_Speech(DEBUG_USARTx,"現(xiàn)在展示流水燈");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
															 break;
							}
							case CODE_SS:	 					//命令“閃爍”
							{
								printf(" 名字 指令識(shí)別成功rn"); 
								// SYN6288_Speech(DEBUG_USARTx,"現(xiàn)在展示閃爍");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
															 break;
							}
							case LDE_1:					
							{
								printf(" 紅燈打開(kāi)rn"); 
								 //SYN6288_Speech(DEBUG_USARTx,"按鍵觸發(fā)");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
															break;
							}
							
							case LDE_2:						
							{
								printf(" 綠燈打開(kāi)rn");
								 //SYN6288_Speech(DEBUG_USARTx,"全滅 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
															break;
							}
							case LDE_3:						
							{
								printf(" 藍(lán)燈打開(kāi)rn");
								// SYN6288_Speech(DEBUG_USARTx,"狀態(tài) 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
															break;
							}	
							case LDE_1_1:					
							{
								printf(" 紅燈關(guān)閉rn"); 
								 //SYN6288_Speech(DEBUG_USARTx,"按鍵觸發(fā)");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
															break;
							}
							
							case LDE_2_1:						
							{
								printf(" 綠燈關(guān)閉rn");
								 //SYN6288_Speech(DEBUG_USARTx,"全滅 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
															break;
							}
							case LDE_3_1:						
							{
								printf(" 藍(lán)燈關(guān)閉rn");
								// SYN6288_Speech(DEBUG_USARTx,"狀態(tài) 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
								break;
							}
								
							case LDE_All_OFF:						//命令“狀態(tài)”
							{
								printf(" 全燈關(guān)閉打開(kāi)rn");
								// SYN6288_Speech(DEBUG_USARTx,"狀態(tài) 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
								break;
							}	
							case chen:						
							{
								
								// SYN6288_Speech(DEBUG_USARTx,"狀態(tài) 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
								break;
							}
							case chen_1:						
							{
								
								// SYN6288_Speech(DEBUG_USARTx,"狀態(tài) 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
								break;
							}
							case voice_J_0:						
							{
			
								printf(" 音量提高rn");
								 //SYN6288_Speech(DEBUG_USARTx,"全滅 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
															break;
							}
							case voice_J_1:						
							{
								printf(" 音量降低rn");
						
								// SYN6288_Speech(DEBUG_USARTx,"狀態(tài) 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
									Delay_ms(200);
								break;
							}								
							default:break;
						}	
					nAsrStatus = LD_ASR_NONE;
					break;
			case LD_ASR_FOUNDZERO:
			default:
					nAsrStatus = LD_ASR_NONE;
					break;
			}//switch

LD3320.h

#ifndef _LD3320_H__
#define _LD3320_H__
#include "stm32f10x_exti.h"
#include "stm32f10x_spi.h"

///以下三個(gè)狀態(tài)定義用來(lái)記錄程序是在運(yùn)行ASR識(shí)別還是在運(yùn)行MP3播放
#define LD_MODE_IDLE			0x00
#define LD_MODE_ASR_RUN		0x08
#define LD_MODE_MP3		 		0x40
///以下五個(gè)狀態(tài)定義用來(lái)記錄程序是在運(yùn)行ASR識(shí)別過(guò)程中的哪個(gè)狀態(tài)
#define LD_ASR_NONE					0x00	//表示沒(méi)有在作ASR識(shí)別
#define LD_ASR_RUNING				0x01	//表示LD3320正在作ASR識(shí)別中
#define LD_ASR_FOUNDOK			0x10	//表示一次識(shí)別流程結(jié)束后,有一個(gè)識(shí)別結(jié)果
#define LD_ASR_FOUNDZERO 		0x11	//表示一次識(shí)別流程結(jié)束后,沒(méi)有識(shí)別結(jié)果
#define LD_ASR_ERROR	 			0x31	//	表示一次識(shí)別流程中LD3320芯片內(nèi)部出現(xiàn)不正確的狀態(tài)

#define CLK_IN   					24/* user need modify this value according to clock in */
#define LD_PLL_11					(uint8_t)((CLK_IN/2.0)-1)
#define LD_PLL_MP3_19			0x0f
#define LD_PLL_MP3_1B			0x18
#define LD_PLL_MP3_1D   	(uint8_t)(((90.0*((LD_PLL_11)+1))/(CLK_IN))-1)

#define LD_PLL_ASR_19 		(uint8_t)(CLK_IN*32.0/(LD_PLL_11+1) - 0.51)
#define LD_PLL_ASR_1B 		0x48
#define LD_PLL_ASR_1D 		0x1f

#define MIC_VOL 0x43
///識(shí)別碼(客戶修改處)
#define CODE_LSD	1	 //喚醒
#define CODE_SS	  2	 //名字
#define LDE_1	  3	 //打開(kāi)紅
#define LDE_2	  4	 //打開(kāi)綠
#define LDE_3		5  //打開(kāi)藍(lán)
#define LDE_All_OFF		6  //狀態(tài)
#define voice_J_0  7	//提高音量

#define LDE_1_1	  51	 //打開(kāi)紅
#define LDE_2_1	  52	 //打開(kāi)綠
#define LDE_3_1		53  //打開(kāi)藍(lán)
#define voice_J_1  57	//降低音量




#define chen		90  //娛樂(lè)
#define chen_1		91  //娛樂(lè)


///LD3320引腳相關(guān)定義
#define LD3320RST_PIN					GPIO_Pin_15		
#define LD3320RST_GPIO_PORT		GPIOB
#define LD3320RST_GPIO_CLK		RCC_APB2Periph_GPIOB
#define LD_RST_H() 						GPIO_SetBits(GPIOB, GPIO_Pin_15)
#define LD_RST_L() 						GPIO_ResetBits(GPIOB, GPIO_Pin_15)

///LD3320引腳相關(guān)定義
#define LD3320CS_PIN					GPIO_Pin_4		
#define LD3320CS_GPIO_PORT		GPIOA
#define LD3320CS_GPIO_CLK			RCC_APB2Periph_GPIOA
#define LD_CS_H()							GPIO_SetBits(GPIOA, GPIO_Pin_4)
#define LD_CS_L()							GPIO_ResetBits(GPIOA, GPIO_Pin_4)

#define LD3320IRQ_GPIO_CLK		RCC_APB2Periph_GPIOB
#define LD3320IRQ_PIN					GPIO_Pin_12
#define LD3320IRQ_GPIO_PORT		GPIOB
#define LD3320IRQEXIT_PORTSOURCE		GPIO_PortSourceGPIOB
#define LD3320IRQPINSOURCE		GPIO_PinSource12
#define LD3320IRQEXITLINE			EXTI_Line12
#define LD3320IRQN						EXTI15_10_IRQn

#define LD3320WR_PIN					GPIO_Pin_13
#define LD3320WR_GPIO_PORT		GPIOB
#define LD3320WR_GPIO_CLK			RCC_APB2Periph_GPIOB
#define LD_SPIS_H()  					GPIO_SetBits(GPIOB, GPIO_Pin_13)
#define LD_SPIS_L()  					GPIO_ResetBits(GPIOB, GPIO_Pin_13)

#define	LD3320SPI							SPI1
#define LD3320SPI_CLK					RCC_APB2Periph_SPI1						

#define LD3320SPIMISO_PIN					GPIO_Pin_6
#define LD3320SPIMISO_GPIO_PORT		GPIOA
#define LD3320SPIMISO_GPIO_CLK		RCC_APB2Periph_GPIOA

#define LD3320SPIMOSI_PIN					GPIO_Pin_7
#define LD3320SPIMOSI_GPIO_PORT		GPIOA
#define LD3320SPIMOSI_GPIO_CLK		RCC_APB2Periph_GPIOA

#define LD3320SPISCK_PIN					GPIO_Pin_5
#define LD3320SPISCK_GPIO_PORT		GPIOA
#define LD3320SPISCK_GPIO_CLK			RCC_APB2Periph_GPIOA

///相關(guān)初始化
void LD3320_main(void);
void LD3320_init(void);
static void LD3320_GPIO_Cfg(void);
static void LD3320_EXTI_Cfg(void);
static void LD3320_SPI_cfg(void);
///中間層
static void LD3320_delay(unsigned long uldata);
uint8_t RunASR(void);
void LD_reset(void);
void LD_AsrStart(void);
uint8_t LD_Check_ASRBusyFlag_b2(void);
///寄存器操作
uint8_t spi_send_byte(uint8_t byte);
void LD_WriteReg(uint8_t data1,uint8_t data2);
uint8_t LD_ReadReg(uint8_t reg_add);
uint8_t LD_AsrAddFixed(void);
uint8_t LD_GetResult(void);
uint8_t LD_AsrRun(void);
void ProcessInt(void);
void LD_Init_Common(void);
void LD_Init_ASR(void);

#endif

LD3320.c

#include "LD3320.h"
#include "string.h"
#include "bsp_SysTick.h"
#include <string.h>
#include "bsp_usart1.h"
#include "SYN6288.h"
#include "bsp_led.h"

/************************************************************************************
//	nAsrStatus 用來(lái)在main主程序中表示程序運(yùn)行的狀態(tài),不是LD3320芯片內(nèi)部的狀態(tài)寄存器
//	LD_ASR_NONE:			表示沒(méi)有在作ASR識(shí)別
//	LD_ASR_RUNING:		表示LD3320正在作ASR識(shí)別中
//	LD_ASR_FOUNDOK:		表示一次識(shí)別流程結(jié)束后,有一個(gè)識(shí)別結(jié)果
//	LD_ASR_FOUNDZERO:	表示一次識(shí)別流程結(jié)束后,沒(méi)有識(shí)別結(jié)果
//	LD_ASR_ERROR:			表示一次識(shí)別流程中LD3320芯片內(nèi)部出現(xiàn)不正確的狀態(tài)
首先:
LD3320
SPI總線

RST—PB15,
CS--PA4,
IRQ—PB12,
WR—PB13,
MISO—PA6,
MOSI—PA7,
SCK—PA5
*********************************************************************************/
extern uint8_t nAsrStatus;	
uint8_t nLD_Mode = LD_MODE_IDLE;//用來(lái)記錄當(dāng)前是在進(jìn)行ASR識(shí)別還是在播放MP3
uint8_t ucRegVal;


static void LD3320_GPIO_Cfg(void)
{	
		GPIO_InitTypeDef GPIO_InitStructure;
		RCC_APB2PeriphClockCmd(LD3320RST_GPIO_CLK | LD3320CS_GPIO_CLK,ENABLE);
		//LD_CS	/RSET
		GPIO_InitStructure.GPIO_Pin =LD3320CS_PIN;
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
		GPIO_Init(LD3320CS_GPIO_PORT,&GPIO_InitStructure);
		GPIO_InitStructure.GPIO_Pin =LD3320RST_PIN;
		GPIO_Init(LD3320RST_GPIO_PORT,&GPIO_InitStructure);
}
static void LD3320_EXTI_Cfg(void)
{
  EXTI_InitTypeDef EXTI_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);	

	RCC_APB2PeriphClockCmd(LD3320IRQ_GPIO_CLK, ENABLE);
  GPIO_InitStructure.GPIO_Pin =LD3320IRQ_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LD3320IRQ_GPIO_PORT, &GPIO_InitStructure);
	//外部中斷線配置
  GPIO_EXTILineConfig(LD3320IRQEXIT_PORTSOURCE, LD3320IRQPINSOURCE);
  EXTI_InitStructure.EXTI_Line = LD3320IRQEXITLINE;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger =EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
	//中斷嵌套配置
  NVIC_InitStructure.NVIC_IRQChannel = LD3320IRQN;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}
static void LD3320_SPI_cfg(void)
{
	SPI_InitTypeDef  SPI_InitStructure;
	GPIO_InitTypeDef GPIO_InitStructure;
  //spi端口配置
	RCC_APB2PeriphClockCmd(LD3320SPI_CLK,ENABLE);		
  RCC_APB2PeriphClockCmd(LD3320WR_GPIO_CLK | LD3320SPIMISO_GPIO_CLK | LD3320SPIMOSI_GPIO_CLK | LD3320SPISCK_GPIO_CLK,ENABLE);
	
	GPIO_InitStructure.GPIO_Pin = LD3320SPIMISO_PIN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_Init(LD3320SPIMISO_GPIO_PORT,&GPIO_InitStructure);
	
	GPIO_InitStructure.GPIO_Pin = LD3320SPIMOSI_PIN;
	GPIO_Init(LD3320SPIMOSI_GPIO_PORT,&GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = LD3320SPISCK_PIN;
	GPIO_Init(LD3320SPISCK_GPIO_PORT,&GPIO_InitStructure);
	
	GPIO_InitStructure.GPIO_Pin = LD3320WR_PIN;				
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(LD3320WR_GPIO_PORT, &GPIO_InitStructure);
	
	LD_CS_H();
	
	SPI_Cmd(LD3320SPI, DISABLE);

	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;   	//全雙工
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;						   						//主模式
	SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;					   					//8位
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;						   							//時(shí)鐘極性 空閑狀態(tài)時(shí),SCK保持低電平
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;						   						//時(shí)鐘相位 數(shù)據(jù)采樣從第一個(gè)時(shí)鐘邊沿開(kāi)始
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;							   							//軟件產(chǎn)生NSS
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;   //波特率控制 SYSCLK/128
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;				   					//數(shù)據(jù)高位在前
	SPI_InitStructure.SPI_CRCPolynomial = 7;							   							//CRC多項(xiàng)式寄存器初始值為7
	SPI_Init(LD3320SPI, &SPI_InitStructure);

	SPI_Cmd(LD3320SPI, ENABLE);
}

///中間層
void EXTI15_10_IRQHandler(void)
{
	if(EXTI_GetITStatus(LD3320IRQEXITLINE)!= RESET ) 
	{
		ProcessInt(); 
	
		EXTI_ClearFlag(LD3320IRQEXITLINE);
		EXTI_ClearITPendingBit(LD3320IRQEXITLINE);//清除LINE上的中斷標(biāo)志位  
	} 
}
static void LD3320_delay(unsigned long uldata)
{
	unsigned int i  =  0;
	unsigned int j  =  0;
	unsigned int k  =  0;
	for (i=0;i<5;i++)
	{
		for (j=0;j<uldata;j++)
		{
			k = 200;
			while(k--);
		}
	}
}
uint8_t RunASR(void)
{
	uint8_t i=0;
	uint8_t asrflag=0;
	for (i=0; i<5; i++)		//防止由于硬件原因?qū)е翷D3320芯片工作不正常,所以一共嘗試5次啟動(dòng)ASR識(shí)別流程
	{
		LD_AsrStart();			//初始化ASR
		LD3320_delay(100);
		if (LD_AsrAddFixed()==0)	//添加關(guān)鍵詞語(yǔ)到LD3320芯片中
		{
			LD_reset();				//LD3320芯片內(nèi)部出現(xiàn)不正常,立即重啟LD3320芯片
			LD3320_delay(50);	//并從初始化開(kāi)始重新ASR識(shí)別流程
			continue;
		}
		LD3320_delay(10);
		if (LD_AsrRun() == 0)
		{
			LD_reset();			 //LD3320芯片內(nèi)部出現(xiàn)不正常,立即重啟LD3320芯片
			LD3320_delay(50);//并從初始化開(kāi)始重新ASR識(shí)別流程
			continue;
		}
		asrflag=1;
		break;						//ASR流程啟動(dòng)成功,退出當(dāng)前for循環(huán)。開(kāi)始等待LD3320送出的中斷信號(hào)
	}	
	return asrflag;
}

void LD_reset(void)
{
	uint8_t i;
	LD_RST_H();
	LD3320_delay(100);
	LD_RST_L();
	LD3320_delay(100);
	LD_RST_H();
	LD3320_delay(100);
	LD_CS_L();
	LD3320_delay(100);
	LD_CS_H();		
	LD3320_delay(100);
	
	i=LD_ReadReg(0x6);
	LD_WriteReg(0x35, 0x33);
	LD_WriteReg(0x1b, 0x55);
	LD_WriteReg(0xb3, 0xaa);
	i=LD_ReadReg(0x35);
	i=LD_ReadReg(0x1b);
	i=LD_ReadReg(0xb3);
	i=i;
	LD_RST_H();
	LD3320_delay(100);
	LD_RST_L();
	LD3320_delay(100);
	LD_RST_H();
	LD3320_delay(100);
	LD_CS_L();
	LD3320_delay(100);
	LD_CS_H();		
	i=LD_ReadReg(0x6);
	LD3320_delay(100);
	i=LD_ReadReg(0x35);
	i=LD_ReadReg(0x1b);
	i=LD_ReadReg(0xb3);
	i=i;
}
void LD_AsrStart(void)
{
	LD_Init_ASR();
}

uint8_t LD_Check_ASRBusyFlag_b2(void)
{
	uint8_t j;
	uint8_t flag = 0;
	for (j=0; j<10; j++)
	{
		if (LD_ReadReg(0xb2) == 0x21)
		{
			flag = 1;
			break;
		}
		LD3320_delay(10);		
	}
	return flag;
}


///寄存器操作
uint8_t spi_send_byte(uint8_t byte)
{
	while (SPI_I2S_GetFlagStatus(LD3320SPI, SPI_I2S_FLAG_TXE) == RESET);
	SPI_I2S_SendData(LD3320SPI,byte);
	while (SPI_I2S_GetFlagStatus(LD3320SPI,SPI_I2S_FLAG_RXNE) == RESET);
	return SPI_I2S_ReceiveData(LD3320SPI);
}

void LD_WriteReg(uint8_t data1,uint8_t data2)
{
	LD_CS_L();
	LD_SPIS_L();
	spi_send_byte(0x04);
	spi_send_byte(data1);
	spi_send_byte(data2);
	LD_CS_H();
}

uint8_t LD_ReadReg(uint8_t reg_add)
{
	uint8_t i;
	LD_CS_L();
	LD_SPIS_L();
	spi_send_byte(0x05);
	spi_send_byte(reg_add);
	i=spi_send_byte(0x00);
	LD_CS_H();
	return(i);
}

uint8_t LD_GetResult(void)
{
	return LD_ReadReg(0xc5);
}

uint8_t LD_AsrRun(void)
{
	LD_WriteReg(0x35, MIC_VOL);
	LD_WriteReg(0x1C, 0x09);
	LD_WriteReg(0xBD, 0x20);
	LD_WriteReg(0x08, 0x01);
	LD3320_delay( 5 );
	LD_WriteReg(0x08, 0x00);
	LD3320_delay( 5);

	if(LD_Check_ASRBusyFlag_b2() == 0)
	{
		return 0;
	}

	LD_WriteReg(0xB2, 0xff);	
	LD_WriteReg(0x37, 0x06);
	LD_WriteReg(0x37, 0x06);
	LD3320_delay(5);
	LD_WriteReg(0x1C, 0x0b);
	LD_WriteReg(0x29, 0x10);
	LD_WriteReg(0xBD, 0x00);   
	return 1;
}
void ProcessInt(void)
{
	uint8_t nAsrResCount=0;

	ucRegVal = LD_ReadReg(0x2B);

// 語(yǔ)音識(shí)別產(chǎn)生的中斷
//(有聲音輸入,不論識(shí)別成功或失敗都有中斷)
	LD_WriteReg(0x29,0) ;
	LD_WriteReg(0x02,0) ;

	if((ucRegVal & 0x10) && LD_ReadReg(0xb2)==0x21 && LD_ReadReg(0xbf)==0x35)		
	{	 
			nAsrResCount = LD_ReadReg(0xba);

			if(nAsrResCount>0 && nAsrResCount<=4) 
			{
				nAsrStatus=LD_ASR_FOUNDOK; 				
			}
			else
			{
				nAsrStatus=LD_ASR_FOUNDZERO;
			}	
	}
	else
	{
		nAsrStatus=LD_ASR_FOUNDZERO;//執(zhí)行沒(méi)有識(shí)別
	}

	LD_WriteReg(0x2b,0);
	LD_WriteReg(0x1C,0);//寫(xiě)0:ADC不可用
	LD_WriteReg(0x29,0);
	LD_WriteReg(0x02,0);
	LD_WriteReg(0x2B,0);
	LD_WriteReg(0xBA,0);	
	LD_WriteReg(0xBC,0);	
	LD_WriteReg(0x08,1);//清除FIFO_DATA
	LD_WriteReg(0x08,0);//清除FIFO_DATA后 再次寫(xiě)0
}

void LD_Init_Common(void)
{
	LD_ReadReg(0x06);  
	LD_WriteReg(0x17, 0x35); 
	LD3320_delay(5);
	LD_ReadReg(0x06);  

	LD_WriteReg(0x89, 0x03);  
	LD3320_delay(5);
	LD_WriteReg(0xCF, 0x43);   
	LD3320_delay(5);
	LD_WriteReg(0xCB, 0x02);
	
	/*PLL setting*/
	LD_WriteReg(0x11, LD_PLL_11);       
	if (nLD_Mode == LD_MODE_MP3)
	{
		LD_WriteReg(0x1E, 0x00); 
		LD_WriteReg(0x19, LD_PLL_MP3_19);   
		LD_WriteReg(0x1B, LD_PLL_MP3_1B);   
		LD_WriteReg(0x1D, LD_PLL_MP3_1D);
	}
	else
	{
		LD_WriteReg(0x1E,0x00);
		LD_WriteReg(0x19, LD_PLL_ASR_19); 
		LD_WriteReg(0x1B, LD_PLL_ASR_1B);		
	  LD_WriteReg(0x1D, LD_PLL_ASR_1D);
	}
	LD3320_delay(5);
	
	LD_WriteReg(0xCD, 0x04);
	LD_WriteReg(0x17, 0x4c); 
	LD3320_delay(1);
	LD_WriteReg(0xB9, 0x00);
	LD_WriteReg(0xCF, 0x4F); 
	LD_WriteReg(0x6F, 0xFF); 
}

void LD_Init_ASR(void)
{
	nLD_Mode=LD_MODE_ASR_RUN;
	LD_Init_Common();

	LD_WriteReg(0xBD, 0x00);
	LD_WriteReg(0x17, 0x48);	
	LD3320_delay(5);
	LD_WriteReg(0x3C, 0x80);    
	LD_WriteReg(0x3E, 0x07);
	LD_WriteReg(0x38, 0xff);    
	LD_WriteReg(0x3A, 0x07);
	LD_WriteReg(0x40, 0);          
	LD_WriteReg(0x42, 8);
	LD_WriteReg(0x44, 0);    
	LD_WriteReg(0x46, 8); 
	LD3320_delay( 1 );
}

///相關(guān)初始化
void LD3320_init(void)
{
	LD3320_GPIO_Cfg();	
	LD3320_EXTI_Cfg();
	LD3320_SPI_cfg();
	LD_reset();
}
static uint8_t LD_AsrAddFixed(void)
{
	uint8_t k, flag;
	uint8_t nAsrAddLength;
	#define DATE_A 20    //數(shù)組二維數(shù)值
	#define DATE_B 50		//數(shù)組一維數(shù)值
	//添加關(guān)鍵詞,用戶修改
	uint8_t  sRecog[DATE_A][DATE_B] = {
	 			"xiao die xiao die",
				"ni jiao shen me",
				"ni shi shei",
				"da kai hong deng",
				"da kai lv deng",
				"da kai lan deng",
				"guan bi hong deng",
				"guan bi lv deng",
				"guan bi lan deng",
				"chen meng die shi shei",
				"chen xiang xin shi shei",
				"yin liang ti gao",
				"yin liang jiang da",
				"guan bi suo you deng" 
		
		
																	};	
	uint8_t  pCode[DATE_A] = {
	 															CODE_LSD,	
																CODE_SS,	
																CODE_SS,	
																LDE_1,   
																LDE_2,	
																LDE_3,		
																LDE_1_1,   
																LDE_2_1,	
																LDE_3_1,		
																chen,		
																chen_1,		
																voice_J_0,		
																voice_J_1,		
																LDE_All_OFF		
															};	//添加識(shí)別碼,用戶修改
	flag = 1;
	for (k=0; k<DATE_A; k++)
	{			
		if(LD_Check_ASRBusyFlag_b2() == 0)
		{
			flag = 0;
			break;
		}

		LD_WriteReg(0xc1, pCode[k] );
		LD_WriteReg(0xc3, 0);
		LD_WriteReg(0x08, 0x04);
		LD3320_delay(1);
		LD_WriteReg(0x08, 0x00);
		LD3320_delay(1);

		for (nAsrAddLength=0; nAsrAddLength<DATE_B; nAsrAddLength++)
		{
			if (sRecog[k][nAsrAddLength] == 0)
				break;
			LD_WriteReg(0x5, sRecog[k][nAsrAddLength]);
		}
		LD_WriteReg(0xb9, nAsrAddLength);
		LD_WriteReg(0xb2, 0xff);
		LD_WriteReg(0x37, 0x04);
	}	 
	return flag;
}


用戶修改
//void LD3320_main(void)
//{
//	uint8_t nAsrRes=0;
//	  
// 	printf("1、流水燈rn"); 
//	printf("2、閃爍rn"); 				
//	printf("3、按鍵觸發(fā)rn"); 		
//	printf("4、全滅rn"); 			
//	printf("5、狀態(tài)rn"); 		
//	nAsrStatus = LD_ASR_NONE;//初始狀態(tài):沒(méi)有在作ASR

//	while(1)
//	{
//		switch(nAsrStatus)
//		{
//			case LD_ASR_RUNING:
//				
//			case LD_ASR_ERROR:		
//					break;
//			case LD_ASR_NONE:
//					nAsrStatus=LD_ASR_RUNING;
//					if (RunASR()==0)//啟動(dòng)一次ASR識(shí)別流程:ASR初始化,ASR添加關(guān)鍵詞語(yǔ),啟動(dòng)ASR運(yùn)算
//					{		
//						nAsrStatus = LD_ASR_ERROR;
//					}
//					break;
//			case LD_ASR_FOUNDOK:
//					 nAsrRes = LD_GetResult( );//一次ASR識(shí)別流程結(jié)束,去取ASR識(shí)別結(jié)果										 
//					 printf("rn識(shí)別碼:%d", nAsrRes);			 		
//								
//					 switch(nAsrRes)		   			//對(duì)結(jié)果執(zhí)行相關(guān)操作,客戶修改
//						{
//							case CODE_LSD:					//命令“流水燈”
//							{
//									printf(" 流水燈 指令識(shí)別成功rn"); 
//							    SYN6288_Speech(DEBUG_USARTx,"現(xiàn)在展示流水燈");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
//									Delay_ms(500);
//															 break;
//							}
//							case CODE_SS:	 					//命令“閃爍”
//							{
//								printf(" 閃爍 指令識(shí)別成功rn"); 
//								 SYN6288_Speech(DEBUG_USARTx,"現(xiàn)在展示閃爍");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
//									Delay_ms(500);
//															 break;
//							}
//							case CODE_AJCF:					//命令“按鍵觸發(fā)”
//							{
//								printf(" 按鍵觸發(fā) 指令識(shí)別成功rn"); 
//								 SYN6288_Speech(DEBUG_USARTx,"按鍵觸發(fā)");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
//									Delay_ms(500);
//															break;
//							}
//							
//							case CODE_QM:						//命令“全滅”
//							{
//								printf(" 全滅 指令識(shí)別成功rn");
//								 SYN6288_Speech(DEBUG_USARTx,"全滅 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
//									Delay_ms(500);
//															break;
//							}
//							case CODE_ZT:						//命令“狀態(tài)”
//							{
//								printf(" 狀態(tài) 指令識(shí)別成功rn");
//								 SYN6288_Speech(DEBUG_USARTx,"狀態(tài) 指令識(shí)別成功");  /*播放聲音,播放聲音時(shí)候LED會(huì)滅掉,就是BY接口用來(lái)檢測(cè)是否繁忙的*/
//									Delay_ms(500);
//							}							
//							default:break;
//						}	
//					nAsrStatus = LD_ASR_NONE;
//					break;
//			case LD_ASR_FOUNDZERO:
//			default:
//					nAsrStatus = LD_ASR_NONE;
//					break;
//			}//switch
//		//開(kāi)發(fā)板測(cè)試
//		Board_text(nAsrRes );
//	}// while
//}

參考

STM32F103C8T6+LD3320語(yǔ)音識(shí)別模塊智能燈控icon-default.png?t=N7T8https://blog.csdn.net/weixin_53129688/article/details/127982201?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170212843516800222862352%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170212843516800222862352&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~top_click~default-2-127982201-null-null.nonecase&utm_term=ld3320&spm=1018.2226.3001.4450

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

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

推薦器件

更多器件
器件型號(hào) 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊(cè) ECAD模型 風(fēng)險(xiǎn)等級(jí) 參考價(jià)格 更多信息
STM32F407VGT6 1 STMicroelectronics High-performance foundation line, Arm Cortex-M4 core with DSP and FPU, 1 Mbyte of Flash memory, 168 MHz CPU, ART Accelerator, Ethernet, FSMC

ECAD模型

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

ECAD模型

下載ECAD模型
$2.5 查看
STM8S003F3P6 1 STMicroelectronics Mainstream Value line 8-bit MCU with 8 Kbytes Flash, 16 MHz CPU, integrated EEPROM

ECAD模型

下載ECAD模型
$1.53 查看

相關(guān)推薦

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

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