加入星计划,您可以享受以下权益:

  • 创作内容快速变现
  • 行业影响力扩散
  • 作品版权保护
  • 300W+ 专业用户
  • 1.5W+ 优质创作者
  • 5000+ 长期合作伙伴
立即加入

STM32传感器外设集-语音识别模块(LD3320)驱动代码编写

06/11 09:56
3052
服务支持:
技术交流群

完成交易后在“购买成功”页面扫码入群,即可与技术大咖们分享疑惑和经验、收获成长和认同、领取优惠和红包等。

虚拟商品不可退

当前内容为数字版权作品,购买后不支持退换且无法转移使用。

加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论
放大
实物图
相关方案
  • 方案介绍
    • 前言
    • 参考
  • 相关文件
  • 推荐器件
  • 相关推荐
  • 电子产业图谱
申请入驻 产业图谱

前言

LD3320是一款由icroute公司生产的语音识别芯片。它具有高性能的语音识别能力,可以广泛应用于各种智能控制、语音交互等场景。以下是关于LD3320语音识别模块的详细介绍:

1. 基本原理:LD3320语音识别模块通过识别预先内置的指令来实现对语音的控制。它的工作模式主要有三种:普通模式、按键模式和口令模式。在口令模式下,设备需要一级唤醒词(口令)来启动ASR进程,从而避免误动作。

2. 应用场景:LD3320语音识别模块可以广泛应用于家居智能控制、智能小车DIY设计、毕业设计创新功能、个人DIY设计以及语音控制嵌入式产品设计等领域。

3. 性能特点:LD3320具有较高的识别准确率和稳定性,能够在各种环境下实现精确的语音识别。此外,它还具有较低的功耗和较小的体积,便于集成到各种设备中。

4. 技术参数:LD3320语音识别模块具备50条预设指令的识别能力。在接收到语音指令后,模块会根据指令执行相应的操作。其工作电压范围为3.3V-5V,适合多种电源供应方案。

5. 接口方式:LD3320模块采用标准的TTL电平接口,易于与微控制器单片机等设备连接。同时,它还具备完善的开发文档和示例代码,便于开发者进行二次开发。

6. 市场前景:随着智能家居智能硬件等领域的快速发展,对语音识别技术的需求日益增长。LD3320作为一种具有较高性能和实用性的语音识别模块,具有广阔的市场前景。

本节主要贴上以前写的语音识别外设LD3320,希望对大家有用,本人已经测试过有用

如何使用,将下面这段函数添加到功能函数中

switch(nAsrStatus)
		{
			case LD_ASR_RUNING:
				
			case LD_ASR_ERROR:		
					break;
			case LD_ASR_NONE:
					nAsrStatus=LD_ASR_RUNING;
					if (RunASR()==0)//启动一次ASR识别流程:ASR初始化,ASR添加关键词语,启动ASR运算
					{		
						nAsrStatus = LD_ASR_ERROR;
					}
					break;
			case LD_ASR_FOUNDOK:
					 nAsrRes = LD_GetResult( );//一次ASR识别流程结束,去取ASR识别结果										 
					 printf("rn识别码:%d", nAsrRes);			 		
								
					 switch(nAsrRes)		   			//对结果执行相关操作,客户修改
						{
							case CODE_LSD:					//命令“流水灯”
							{
									printf(" 流水灯 指令识别成功rn"); 
							    //SYN6288_Speech(DEBUG_USARTx,"现在展示流水灯");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
															 break;
							}
							case CODE_SS:	 					//命令“闪烁”
							{
								printf(" 名字 指令识别成功rn"); 
								// SYN6288_Speech(DEBUG_USARTx,"现在展示闪烁");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
															 break;
							}
							case LDE_1:					
							{
								printf(" 红灯打开rn"); 
								 //SYN6288_Speech(DEBUG_USARTx,"按键触发");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
															break;
							}
							
							case LDE_2:						
							{
								printf(" 绿灯打开rn");
								 //SYN6288_Speech(DEBUG_USARTx,"全灭 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
															break;
							}
							case LDE_3:						
							{
								printf(" 蓝灯打开rn");
								// SYN6288_Speech(DEBUG_USARTx,"状态 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
															break;
							}	
							case LDE_1_1:					
							{
								printf(" 红灯关闭rn"); 
								 //SYN6288_Speech(DEBUG_USARTx,"按键触发");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
															break;
							}
							
							case LDE_2_1:						
							{
								printf(" 绿灯关闭rn");
								 //SYN6288_Speech(DEBUG_USARTx,"全灭 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
															break;
							}
							case LDE_3_1:						
							{
								printf(" 蓝灯关闭rn");
								// SYN6288_Speech(DEBUG_USARTx,"状态 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
								break;
							}
								
							case LDE_All_OFF:						//命令“状态”
							{
								printf(" 全灯关闭打开rn");
								// SYN6288_Speech(DEBUG_USARTx,"状态 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
								break;
							}	
							case chen:						
							{
								
								// SYN6288_Speech(DEBUG_USARTx,"状态 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
								break;
							}
							case chen_1:						
							{
								
								// SYN6288_Speech(DEBUG_USARTx,"状态 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
								break;
							}
							case voice_J_0:						
							{
			
								printf(" 音量提高rn");
								 //SYN6288_Speech(DEBUG_USARTx,"全灭 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									Delay_ms(200);
															break;
							}
							case voice_J_1:						
							{
								printf(" 音量降低rn");
						
								// SYN6288_Speech(DEBUG_USARTx,"状态 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
									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"

///以下三个状态定义用来记录程序是在运行ASR识别还是在运行MP3播放
#define LD_MODE_IDLE			0x00
#define LD_MODE_ASR_RUN		0x08
#define LD_MODE_MP3		 		0x40
///以下五个状态定义用来记录程序是在运行ASR识别过程中的哪个状态
#define LD_ASR_NONE					0x00	//表示没有在作ASR识别
#define LD_ASR_RUNING				0x01	//表示LD3320正在作ASR识别中
#define LD_ASR_FOUNDOK			0x10	//表示一次识别流程结束后,有一个识别结果
#define LD_ASR_FOUNDZERO 		0x11	//表示一次识别流程结束后,没有识别结果
#define LD_ASR_ERROR	 			0x31	//	表示一次识别流程中LD3320芯片内部出现不正确的状态

#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
///识别码(客户修改处)
#define CODE_LSD	1	 //唤醒
#define CODE_SS	  2	 //名字
#define LDE_1	  3	 //打开红
#define LDE_2	  4	 //打开绿
#define LDE_3		5  //打开蓝
#define LDE_All_OFF		6  //状态
#define voice_J_0  7	//提高音量

#define LDE_1_1	  51	 //打开红
#define LDE_2_1	  52	 //打开绿
#define LDE_3_1		53  //打开蓝
#define voice_J_1  57	//降低音量




#define chen		90  //娱乐
#define chen_1		91  //娱乐


///LD3320引脚相关定义
#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引脚相关定义
#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

///相关初始化
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 用来在main主程序中表示程序运行的状态,不是LD3320芯片内部的状态寄存器
//	LD_ASR_NONE:			表示没有在作ASR识别
//	LD_ASR_RUNING:		表示LD3320正在作ASR识别中
//	LD_ASR_FOUNDOK:		表示一次识别流程结束后,有一个识别结果
//	LD_ASR_FOUNDZERO:	表示一次识别流程结束后,没有识别结果
//	LD_ASR_ERROR:			表示一次识别流程中LD3320芯片内部出现不正确的状态
首先:
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;//用来记录当前是在进行ASR识别还是在播放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;						   							//时钟极性 空闲状态时,SCK保持低电平
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;						   						//时钟相位 数据采样从第一个时钟边沿开始
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;							   							//软件产生NSS
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;   //波特率控制 SYSCLK/128
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;				   					//数据高位在前
	SPI_InitStructure.SPI_CRCPolynomial = 7;							   							//CRC多项式寄存器初始值为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上的中断标志位  
	} 
}
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++)		//防止由于硬件原因导致LD3320芯片工作不正常,所以一共尝试5次启动ASR识别流程
	{
		LD_AsrStart();			//初始化ASR
		LD3320_delay(100);
		if (LD_AsrAddFixed()==0)	//添加关键词语到LD3320芯片中
		{
			LD_reset();				//LD3320芯片内部出现不正常,立即重启LD3320芯片
			LD3320_delay(50);	//并从初始化开始重新ASR识别流程
			continue;
		}
		LD3320_delay(10);
		if (LD_AsrRun() == 0)
		{
			LD_reset();			 //LD3320芯片内部出现不正常,立即重启LD3320芯片
			LD3320_delay(50);//并从初始化开始重新ASR识别流程
			continue;
		}
		asrflag=1;
		break;						//ASR流程启动成功,退出当前for循环。开始等待LD3320送出的中断信号
	}	
	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);

// 语音识别产生的中断
//(有声音输入,不论识别成功或失败都有中断)
	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;//执行没有识别
	}

	LD_WriteReg(0x2b,0);
	LD_WriteReg(0x1C,0);//写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后 再次写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 );
}

///相关初始化
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    //数组二维数值
	#define DATE_B 50		//数组一维数值
	//添加关键词,用户修改
	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		
															};	//添加识别码,用户修改
	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、按键触发rn"); 		
//	printf("4、全灭rn"); 			
//	printf("5、状态rn"); 		
//	nAsrStatus = LD_ASR_NONE;//初始状态:没有在作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)//启动一次ASR识别流程:ASR初始化,ASR添加关键词语,启动ASR运算
//					{		
//						nAsrStatus = LD_ASR_ERROR;
//					}
//					break;
//			case LD_ASR_FOUNDOK:
//					 nAsrRes = LD_GetResult( );//一次ASR识别流程结束,去取ASR识别结果										 
//					 printf("rn识别码:%d", nAsrRes);			 		
//								
//					 switch(nAsrRes)		   			//对结果执行相关操作,客户修改
//						{
//							case CODE_LSD:					//命令“流水灯”
//							{
//									printf(" 流水灯 指令识别成功rn"); 
//							    SYN6288_Speech(DEBUG_USARTx,"现在展示流水灯");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
//									Delay_ms(500);
//															 break;
//							}
//							case CODE_SS:	 					//命令“闪烁”
//							{
//								printf(" 闪烁 指令识别成功rn"); 
//								 SYN6288_Speech(DEBUG_USARTx,"现在展示闪烁");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
//									Delay_ms(500);
//															 break;
//							}
//							case CODE_AJCF:					//命令“按键触发”
//							{
//								printf(" 按键触发 指令识别成功rn"); 
//								 SYN6288_Speech(DEBUG_USARTx,"按键触发");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
//									Delay_ms(500);
//															break;
//							}
//							
//							case CODE_QM:						//命令“全灭”
//							{
//								printf(" 全灭 指令识别成功rn");
//								 SYN6288_Speech(DEBUG_USARTx,"全灭 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
//									Delay_ms(500);
//															break;
//							}
//							case CODE_ZT:						//命令“状态”
//							{
//								printf(" 状态 指令识别成功rn");
//								 SYN6288_Speech(DEBUG_USARTx,"状态 指令识别成功");  /*播放声音,播放声音时候LED会灭掉,就是BY接口用来检测是否繁忙的*/
//									Delay_ms(500);
//							}							
//							default:break;
//						}	
//					nAsrStatus = LD_ASR_NONE;
//					break;
//			case LD_ASR_FOUNDZERO:
//			default:
//					nAsrStatus = LD_ASR_NONE;
//					break;
//			}//switch
//		//开发板测试
//		Board_text(nAsrRes );
//	}// while
//}

参考

STM32F103C8T6+LD3320语音识别模块智能灯控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

联系方式 微信号:13648103287

  • 联系方式.docx

推荐器件

更多器件
器件型号 数量 器件厂商 器件描述 数据手册 ECAD模型 风险等级 参考价格 更多信息
AT89C51ED2-RDTUM 1 Microchip Technology Inc IC MCU 8BIT 64KB FLASH 64VQFP

ECAD模型

下载ECAD模型
$18.07 查看
ATSAMA5D35A-CN 1 Atmel Corporation RISC Microprocessor, 536MHz, CMOS, PBGA324, 15 X 15 MM, 1.40 MM HEIGHT, 0.80 MM PITCH, GREEN, MO-275KAAE-1, LFBGA-324
$13.79 查看
ATXMEGA64D3-AU 1 Microchip Technology Inc IC MCU 8BIT 64KB FLASH 64TQFP

ECAD模型

下载ECAD模型
$1.28 查看

相关推荐

电子产业图谱

方案定制,程序设计方案、单片机程序设计与讲解、APP定制开发。本公众号致力于向读者传递关于程序设计和开发的相关知识,并分享一些关于软件开发的最佳实践。如果您有什么问题或建议,请随时联系我们。我们将竭诚为您服务