Realize speech recognition system: teach you how to use STM32C8T6 and LD3320 (SPI communication version) to realize speech recognition

        This article is actually a personal understanding of LD3320 (SPI communication version). If you only talk about the code and development board information, in fact, when you buy LD3320, the seller has already provided a lot of information. I used the development board of LD3320 chip many times to design the system during my university, and I also added this system function in my graduation project to add fun to the whole system. The original intention of this article is also to summarize the learning content for your reference and study. If my understanding is wrong, I hope readers can point it out in the comments, it is very grateful.

Attach my engineering code: engineering code

Table of contents

Table of contents

Attach my engineering code: engineering code

Popular understanding about LD3320     

So what is the difference between the LD3320 serial port version and the SPI version?

The realization principle of LD3320

Function realization (demo)

1. Realize the function

2. Physical map

3. Wiring diagram

4. Detailed introduction and interpretation of SPI protocol 

1) The communication process of the SPI protocol is as follows:

2) The data transmission mode of the SPI protocol is divided into two modes: mode 0 and mode 3

3) The SPI protocol has four lines: SCLK, MOSI, MISO, SS

Code level analysis (requires modification)

1) main.c file

2) LD3320_main.c file and its header file (key)

(1) LD3320_main.c file

(2) LDchip.h file (do not explain too much, see notes for details)

3) About the IO port configuration of electrical appliances (led.c)


Popular understanding about LD3320     

        The advantage of using LD3320 is that it directly eliminates the process of training your model. In other words, it integrates a well-trained speech recognition system into the LD3320 chip. We only need to be able to "call" the LD3320 chip. Like building blocks, it is already a whole module, we don't even need to provide redundant operations, just pile it up, and it is ready to use. So how to "call" it is the biggest difficulty we need to solve.

       There are currently two types of LD3320 on the market: one is the SPI version , as shown in the figure below, this is our protagonist today, we can regard it as a module (a building block) of the peripheral circuit, and it needs to be connected with a single-chip microcomputer To "call" this module to realize intelligent speech recognition.

      

 The second is the serial port version, as shown in the figure.

So what is the difference between the LD3320 serial port version and the SPI version?

The difference between the SPI version and the serial port version of the LD3320 speech recognition chip lies in their different communication interfaces. The SPI version communicates through the SPI interface, while the serial version communicates through the serial interface.

Specifically, the SPI version can be directly connected with MCU or other devices that support SPI communication, and transmit data through the SPI interface. The serial port version needs to communicate with the MCU through the serial port, and usually needs to write a certain serial port communication protocol on the MCU to realize data exchange with the chip.

In addition, due to the different communication interfaces, the application scenarios of the SPI version and the serial port version are also slightly different. The SPI version of the chip is suitable for occasions that require high communication speed and high-speed data transmission, while the serial port version is suitable for applications that do not require high communication speed and need to adapt to different serial ports.

In layman's terms, the SPI version has a fast communication speed and can be regarded as a truly independent module; while the serial version can be regarded as a 51MCU with information processing capabilities.


The realization principle of LD3320

The realization principle of LD3320 speech recognition chip can be divided into the following steps:

1. Audio collection: LD3320 has a built-in microphone amplifier, which can collect the surrounding sound, and send the collected audio signal to the voice signal processor inside the chip.

2. Signal processing: LD3320 has a built-in speech signal processor, which can perform preprocessing, noise reduction, filtering and other processing on audio signals to improve the accuracy of recognition.

3. Feature extraction: After signal processing, LD3320 converts the audio signal into a digital signal and extracts the voice features. The LD3320 uses a feature extraction algorithm called Mel-frequency cepstral coefficients (MFCC).

4. Model matching: LD3320 has some built-in speech recognition models, such as Chinese numbers, English numbers, Chinese pinyin, etc. The LD3320 matches the extracted speech features with these models to recognize what the user said.

5. Output result: Once LD3320 recognizes the user, it will output the recognition result to the external MCU or DSP chip for subsequent application.

In general, the principle of LD3320 to achieve intelligent speech recognition is to collect audio through the built-in microphone amplifier. After signal processing and feature extraction, the extracted speech features are matched with the built-in model, so as to realize the recognition of user voice commands. recognition and understanding. The LD3320 speech recognition chip realizes speech recognition by recognizing specific frequency and time domain features in the speech signal. It uses endpoint detection technology, which detects the existence of the signal at the beginning and end of the voice signal, and passes it to the subsequent processing module for identification. The LD3320 chip can perform multi-language recognition, including Chinese, English, Japanese, Korean, etc. However, it should be noted that the accuracy of its speech recognition may be affected by environmental noise and other factors.


Function realization (demo)

1. Realize the function

Voice control switch bedroom, living room lights; switch fan and other functions

2. Physical map

3. Wiring diagram

 

4. Detailed introduction and interpretation of SPI protocol 

SPI (Serial Peripheral Interface) is a synchronous serial communication protocol used to transfer data between microcontrollers or other digital integrated circuits (ICs). It is a full-duplex, point-to-point communication protocol that uses four wires for communication: when the master sends data, the slave receives and returns response data.

The SPI communication protocol uses data transmission between a master and one or more slaves, where one device is the master and the other devices are slaves. The master is responsible for coordinating the entire communication process, and the slave will only respond when it is selected by the master. Normally, there will be only one master on the SPI bus, but multiple slaves can be connected at the same time, and each slave has an independent slave selection signal line.

1) The communication process of the SPI protocol is as follows:

1. The master pulls down the slave selection signal line to select the slave to communicate with.

2. The master sends a clock signal to the slave, and the clock signal divides the data transmission into several clock cycles.

3. The master sends data to the slave through one data line, and receives the data returned from the slave through another data line.

4. In the last cycle of the clock, the master pulls the slave select signal line high to indicate the end of the communication.

2) The data transmission mode of the SPI protocol is divided into two modes: mode 0 and mode 3

The clock polarity (CPOL) and phase (CPHA) of mode 0 are both 0, which means that the clock line is low in the idle state and data is sampled on the rising edge. The clock polarity (CPOL) and phase (CPHA) of mode 3 are both 1, which means that the clock line is high in the idle state, and the data is sampled on the falling edge.

3) The SPI protocol has four lines: SCLK, MOSI, MISO, SS

Among them, SCLK is the clock line, which is controlled by the master device for synchronous data transmission; MOSI is the data line output by the master device and input by the slave device; MISO is the data line output by the slave device and input by the master device; SS is the chip select signal line , which is used to select the slave device to communicate with the master device. During the communication process, the master device sends a clock signal to the slave device through the SCLK line, and at the same time sends data to the slave device through the MOSI line, and the slave device returns the response data through the MISO line. The SS line controls the selection and release of the slave device, and can support the communication of multiple slave devices.

The advantages of the SPI protocol are high speed, simplicity, low cost, and simple communication lines, but additional slave selection signal lines are required. The SPI protocol is widely used in communication between various digital integrated circuits, such as flash memory, EEPROM, digital signal processors, etc. All in all, the transmission rate of the SPI protocol is fast, which is suitable for applications with small data volume and high real-time performance.


Code level analysis (requires modification)

 From the above, we can easily see. We only need to learn to "call" LD3320, because it is a "building block", we only need to learn to use it. As for the problem of speech recognition, the chip has already solved it for you. The SPI protocol needs to be used when "calling" the chip, we use STM32C8T6 as the control chip

1) main.c file

We only need to pay attention to the LD3320_main() function here. As for the two functions in while, don't be fooled by it. It actually uses timers and interrupts to switch (living room and bedroom) lights. The difficulty is actually in LD3320_main()

int main()
{  	
	
	Systick_Init(72);
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	USART1_Init(115200);
	//TIM3_Int_Init(5000-1,72-1);
	TIM4_Int_Init(999,72-1);

	LED_Init();

	//TIM_Cmd(TIM3,ENABLE);
	TIM_Cmd(TIM4,ENABLE);
    printf("初始化完成\r\n");
    LD3320_main();		//LD3320 主函数函数
	while(1)
	{
		TimerTreat();
		ledshow();
       
	}
}

2) LD3320_main.c file and its header file (key)

(1) LD3320_main.c file

The main modification here is: static void Board_text(uint8 Code_Val) function, the specific operation can be combined with the analysis of the header file. Note that the header files also need to be modified. This is very simple, you only need to have basic C code reading ability to modify, no need to explain too much


#include "LDchip.h"
#include "Reg_RW.h"
#include "system.h"
#include "SysTick.h"
#include "usart.h"
#include <stdio.h>
#include "led.h"
/*************端口信息********************
 * 接线说明
 LD3320接口 	  STM32接口
 * RST              PB6
 * CS   	        PB8
 * WR/SPIS          PB9
 * P2/SDCK          PB13
 * P1/SDO           PB14
 * P0/SDI           PB15
 * IRQ              PA3
 * A0		        PB7
 * RD               PA0

*****************************************/



/************************************************************************************
//	nAsrStatus 用来在main主程序中表示程序运行的状态,不是LD3320芯片内部的状态寄存器
//	LD_ASR_NONE:		表示没有在作ASR识别
//	LD_ASR_RUNING:		表示LD3320正在作ASR识别中
//	LD_ASR_FOUNDOK:		表示一次识别流程结束后,有一个识别结果
//	LD_ASR_FOUNDZERO:	表示一次识别流程结束后,没有识别结果
//	LD_ASR_ERROR:		表示一次识别流程中LD3320芯片内部出现不正确的状态
*********************************************************************************/

uint8 nAsrStatus=0;	
void LD3320_Init(void);
uint8 RunASR(void);
void ProcessInt0(void);
void LD3320_EXTI_Cfg(void);
void LD3320_Spi_cfg(void);
void LD3320_GPIO_Cfg(void);
void LED_gpio_cfg(void);
static void Board_text(uint8 Code_Val);
extern void PrintComBit(USART_TypeDef* USARTx, uint8_t Data);
/***********************************************************
* 名    称: LD3320_main(void)
* 功    能: 主函数LD3320程序入口
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
void  LD3320_main(void)
{
	uint8 nAsrRes=0;
	LD3320_Init();	  

	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( );	//识别成功自动 获取识别码,识别码在LDChip.h文件中,自行定义的数据										 									
								 PrintComBit(USART1,nAsrRes ); //串口输出识别码								
								 //Board_text(nAsrRes );//开发板测试演示部分---对识别码的进行判断做出动作 (用户亦可以添加自己的功能,例如控制IO口输出,串口数据输出等)		
								 nAsrStatus = LD_ASR_NONE;
								break;
			
			case LD_ASR_FOUNDZERO:
			default: nAsrStatus = LD_ASR_NONE;
					 break;
			}//switch	
        //开发板测试
		Board_text(nAsrRes );
	}// while
}


static void Board_text(uint8 Code_Val)
{																					 
	switch(Code_Val)  //对结果执行相关操作
	{
		case CODE_DD:	//命令“打开客厅灯”
		LED_KT=1;
        printf("打开客厅灯\r\n");
		break;
		
        case CODE_GD:		//命令“关闭客厅灯”
	    LED_KT=0;
        printf("关闭客厅灯\r\n");
        break;
        
        case CODE_QDD:		//命令“打开卧室灯”
	    //打开卧室灯
        LED_WS = 1;
        printf("打开卧室灯\r\n");
        break;
        
        case CODE_DG:		//命令“关闭卧室灯”
	    //关闭卧室灯
        LED_WS = 0;
        printf("关闭卧室灯\r\n");
		break;
        
        case CODE_LSD:		//命令“全部打开”
	    //全部打开
        LED_KT=1;
        LED_WS = 1;
        printf("全部打开\r\n");
		break;
        
        case CODE_SSD:		//命令“全部关闭”
	    //全部关闭
        LED_KT=0;  
        LED_WS = 0;
        printf("全部关闭\r\n");
        break;
        
        case CODE_DDR:		//命令“打开风扇”
	    //打开风扇
        printf("打开风扇\r\n");
        JDY_FS = 0;
		break;
        
        case CODE_RDD:		//命令“关闭风扇”
	    //关闭风扇
        JDY_FS = 1;
        printf("关闭风扇\r\n");
		break;
		default:break;
	}	
}
/***********************************************************
* 名    称:LD3320_Init(void)
* 功    能:模块驱动端口初始配置
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
void LD3320_Init(void)
{
	LD3320_GPIO_Cfg();	
	LD3320_EXTI_Cfg();
	LD3320_Spi_cfg();	 
	LD_reset();
	
}
/***********************************************************
* 名    称:	RunASR(void)
* 功    能:	运行ASR
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
uint8 RunASR(void)
{
	uint8 i=0;
	uint8 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 Delay_( int i)
* 功    能: 短延时
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
void Delay_( int i)
 {     
    while( i--)
       {	

        }
 }	
/***********************************************************
* 名    称:	LD3320_delay(unsigned long uldata)
* 功    能:	长延时函数
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
 void  LD3320_delay(unsigned long uldata)
{
	unsigned int j  =  0;
	unsigned int g  =  0;
	for (j=0;j<5;j++)
	{
		for (g=0;g<uldata;g++)
		{
			Delay_(120);
		}
	}
}


/***********************************************************
* 名    称:LD3320_GPIO_Cfg(void)
* 功    能:初始化需要用到的IO口
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
void LD3320_GPIO_Cfg(void)
{	
	    GPIO_InitTypeDef GPIO_InitStructure;
		// 配置PA8 输出	 8M 波形	
		//定义RST/A0/CS/WR端口
	 {
	 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB ,ENABLE);
		//LD_CS	/RSET
		GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
		GPIO_Init(GPIOB,&GPIO_InitStructure);
		GPIO_SetBits(GPIOB,GPIO_Pin_7);	/*A0默认拉高*/
	 }
}
/***********************************************************
* 名    称:LD3320_Spi_cfg(void)
* 功    能:配置SPI功能和端口初始化
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
void LD3320_Spi_cfg(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
  	SPI_InitTypeDef  SPI_InitStructure;

	RCC_APB2PeriphClockCmd(	RCC_APB2Periph_GPIOB, ENABLE );//PORTB时钟使能 
	RCC_APB1PeriphClockCmd(	RCC_APB1Periph_SPI2,  ENABLE );//SPI2时钟使能 	
 
	
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  //PB13/14/15复用推挽输出 
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &GPIO_InitStructure);

	LD_CS_H();
	
 	GPIO_SetBits(GPIOB,GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);  //PB13/14/15上拉

	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;		//设置SPI工作模式:设置为主SPI
	SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;		//设置SPI的数据大小:SPI发送接收8位帧结构
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;		//选择了串行时钟的稳态:时钟悬空高
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;	//数据捕获于第二个时钟沿
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;		//NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:内部NSS信号有SSI位控制
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;		//定义波特率预分频的值:波特率预分频值为16
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;	//指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
	SPI_InitStructure.SPI_CRCPolynomial = 7;	//CRC值计算的多项式
	SPI_Init(SPI2, &SPI_InitStructure);  //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
 
	SPI_Cmd(SPI2, ENABLE); //使能SPI外设
}
/***********************************************************
* 名    称: LD3320_EXTI_Cfg(void) 
* 功    能: 外部中断功能配置和相关端口配置
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
void LD3320_EXTI_Cfg(void)
{
  EXTI_InitTypeDef EXTI_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;

  //定义IRQ中断引脚配置
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  GPIO_InitStructure.GPIO_Pin =GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	//外部中断线配置
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource3);
  EXTI_InitStructure.EXTI_Line = EXTI_Line3;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger =EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  EXTI_GenerateSWInterrupt(EXTI_Line3);
		
	GPIO_SetBits(GPIOA,GPIO_Pin_3);	 //默认拉高中断引脚

	EXTI_ClearFlag(EXTI_Line3);
	EXTI_ClearITPendingBit(EXTI_Line3);
	//中断嵌套配置
  NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}


/***********************************************************
* 名    称:  EXTI1_IRQHandler(void)
* 功    能: 外部中断函数
* 入口参数:  
* 出口参数:
* 说    明:
* 调用方法: 
**********************************************************/ 
void EXTI3_IRQHandler(void)
{
	if(EXTI_GetITStatus(EXTI_Line3)!= RESET ) 
	{
 		ProcessInt0();
		EXTI_ClearFlag(EXTI_Line3);
		EXTI_ClearITPendingBit(EXTI_Line3);
	}
}

(2) LDchip.h file (do not explain too much, see notes for details)

#ifndef LD_CHIP_H
#define LD_CHIP_H

#define uint8 unsigned char
#define uint16 unsigned int
#define uint32 unsigned long

//	以下三个状态定义用来记录程序是在运行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   	22	/* user need modify this value according to clock in */
#define LD_PLL_11			(uint8)((CLK_IN/2.0)-1)
#define LD_PLL_MP3_19		0x0f
#define LD_PLL_MP3_1B		0x18
#define LD_PLL_MP3_1D   	(uint8)(((90.0*((LD_PLL_11)+1))/(CLK_IN))-1)

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

// LD chip fixed values.
#define        RESUM_OF_MUSIC               0x01
#define        CAUSE_MP3_SONG_END           0x20

#define        MASK_INT_SYNC				0x10
#define        MASK_INT_FIFO				0x04
#define    	   MASK_AFIFO_INT				0x01
#define        MASK_FIFO_STATUS_AFULL		0x08



void LD_reset(void);
uint8 RunASR(void);

void LD_Init_Common(void);

void LD_Init_ASR(void);

void LD_ReloadMp3Data(void);
void LD_ReloadMp3Data_2(void);

uint8 LD_ProcessAsr(uint32 RecogAddr);
void LD_AsrStart(void);
uint8 LD_AsrRun(void);
uint8 LD_AsrAddFixed(void);
uint8 LD_GetResult(void);

void LD_ReadMemoryBlock(uint8 dev, uint8 * ptr, uint32 addr, uint8 count);
void LD_WriteMemoryBlock(uint8 dev, uint8 * ptr, uint32 addr, uint8 count);

extern uint8  nLD_Mode;


	//以下为识别码的宏定义无特别意义,0-ff可自行修改值,不分顺序不要重复。
#define CODE_DD       0X01	  /*打开客厅灯*/
#define CODE_GD	  	  0X02	  /*关闭客厅灯*/
#define CODE_QDD 	  0X03    /*打开卧室灯*/
#define CODE_DG		  0X04	  /*关闭卧室灯*/
#define CODE_LSD	  0X05	  /*全部打开*/
#define CODE_SSD	  0X06	  /*全部关闭*/
#define CODE_DDR	  0X07	  /*打开继电器*/
#define CODE_RDD	  0X08	  /*继电器点动*/

//#define CODE_PLAY	  0X09	  /*播放歌曲*/
//#define CODE_NAME	  0X0A    /*你叫什么名字*/
//#define CODE_DO		  0X0B    /*你会做什么*/


void  LD3320_delay(unsigned long uldata);

#define MIC_VOL 0x43    //麦克风灵敏度条件,值越大越灵敏也容易误识别

#endif

3) About the IO port configuration of electrical appliances (led.c)

The code here is a configuration of the electrical pin port

#include "led.h"
#include "timer.h"
 void LED_Init()
{
	GPIO_InitTypeDef  GPIO_InitStructure;
	 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);	    
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_0|GPIO_Pin_1;			   
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 	 //推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	 //IO口速度为50MHz
	GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    LED_KT = 0;
    LED_WS = 0;//灯光初始为关闭状态
    JDY_FS = 1;
}


void ledshow(void)
{
	if(g_stTimerTickFlag.bTimer500ms == 1)
	{
		LED_KT = !LED_KT;
        LED_WS = !LED_WS;
	}
}

        The code is also very simple, it is a process of building blocks. All in all, it is a very interesting small system, and it is also very good for some scenarios such as smart home. But at present, the LD3320 speech recognition board has very limited filtering of noises, and probably can only achieve effective recognition of 1m-1.5m, and the specifics have not been tested. Interested students can try hahahahahahaha

Oh, by the way, I need to explain that this code is only for learning , and the code itself is also changed by me through the merchant code. If you want to add a little function and some fun to your own design or system like me, you can get the code yourself!

Guess you like

Origin blog.csdn.net/Uncoverlove/article/details/130487761