STM32F103C8T6+LD3320 voice recognition module intelligent light control

https://download.csdn.net/download/weixin_53129688/87695080 https://download.csdn.net/download/weixin_53129688/87695080  Because the code demand is too large, it is not convenient to reply one by one, so the above ld3320+stm32 sources are released Code, for reference study.

1. Introduction of LD3320

 LD3320 is a speech recognition/voice control chip based on SI-ASR (Speaker-Independent Automatic SpeechRecognition) technology. Provides a true single-chip speech recognition solution. The LD3320 chip integrates high-precision A/D and D/A interface, no need for external auxiliary Flash and RAM, that is, voice recognition/voice control/man-machine dialogue functions can be realized. Moreover, the list of recognized keywords can be edited dynamically. Based on LD3320, voice recognition/voice control/human-machine dialogue functions can be easily realized in any electronic product, even the simplest system with 51 as the main control chip. Add VUI (Voice User Interface) voice user interface to all electronic products.
Main features:
1. Non-person-specific voice recognition technology: No need for users to perform recording training. Dynamically editable recognition key word list: Just transmit the recognized key words into the chip in the form of strings, and it can be used in the next recognition Effective immediately. For example, in the programming of 51 and other MCUs, the user simply sets the registers of the chip and dynamically transfers the content of the identification keywords such as "Hello" to the chip, and the chip can recognize the keywords set in this way. .
2. True single-chip solution: No need for any external auxiliary Flash and RAM, which really reduces system cost. Built-in high-precision A/D and D/A channels: No external AD chip is needed, just connect the microphone to the AD pin of the chip; it can play sound files and provide a 550mW built-in amplifier. High accuracy and practical voice recognition effect.
3. Support users to freely edit 50 keyword entries: At the same time, at most 50 keyword entries can be identified, and end users can edit and update the content of these 50 keyword entries at any time according to the needs of the scene.

The above is pure nonsense. You can see that the explanations here are all patient people. The dry goods are directly listed below, as long as you have hands, you can easily handle the LD3320 module. If you like it, like it and add attention.

2. Use of LD3320

There is nothing to say about the hardware. The LD3320 can be directly converted to a TTL module via USB, which is the so-called CH340 download. The wiring is also very simple. This is the LD3320 I use. It may be different from different vendors, but the principle is definitely the same. The microcontroller used must be STC11L..X, so don’t worry, when downloading, you only need to connect the 5V above to the 5V or VCC of CH340, GND to GND, TX to RX, RX to TX, and then you can download Yes, I used Acer's STC-ISP for downloading, and this is all about the hardware. 

Of course, some friends like to use the IO port on the LD3320 to control things. This is also possible, but I don’t like it very much, because the functions of the LD3320 are relatively limited after all. I still like to use 32 to control after communicating with the STM32, such as PWM this function.

Let's talk about the code part below.

I bought my LD3320 on a certain treasure, and the store will give the information, but I can’t post it here. Friends who want to link can private message me. I will reply when I see it. First, let me talk about my code framework.

3. Code framework

The LD3320 performs speech recognition, then performs serial communication, and sends the data to STM32. STM performs data reception judgment, and then performs corresponding operations, such as outputting PWM or high and low levels or OLED display.

4. LD3320 code

There are not many operable codes in LD3320, and many of them are unnecessary to read. Taking mine as an example, there are only a few operable places.

first place

Located in LDChip.c, the code used for recognition, LD3320 uses pinyin recognition, that is, you can input whatever you want it to recognize.

The first one is the quantity and width of the data. 13 on the top is the quantity, and 30 is the width. The width can exceed the length of the pinyin, but not too much, otherwise an error will be reported. The bottom is the corresponding command, remember except the last one Instructions, other instructions are followed by ,\ , and the CODE_... below are all named by myself, and there are as many instructions as there are . Except for the first CODE_CMD, which cannot be changed, others can be changed and added at will.

second place

The second place is this place. In LDChip.h corresponding to LDChip.c, this corresponds to the previous one. It is just a statement for CODE_.., but this is required, and the value can be arbitrary, as long as it is not repeated. Finally, CODE_CMD cannot be changed. Below is the sensitivity adjustment, which is mentioned in the picture.

 third place

The third place is in the main function main.c, which is the communication function processing. There is a user processing function, and the others do not need to be changed. You only need to add a few more judgment conditions in the switch——case, and then the communication sending function is also available. Yes, just change to send data.

These are all the parts of LD3320, simple and clear.

5. STM32 code

The 32 part is not difficult. Anyone who has learned 32 knows the serial port communication, that is, configure a serial port, receive the data transmitted by the LD3320, then make an if judgment, and then process it. I also have the serial port configuration. Of course, this is C8T6. Remember to check if the schematic diagram is compatible with other models. I remember that ZET6 and RTC6 should also be compatible.

void UART1_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_ITConfig(USART1, USART_IT_RXNE, ENABLE);
    
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_Init(&NVIC_InitStructure);
    
    USART_Cmd(USART1, ENABLE);
}

This is the serial port configuration, the serial port 1 I use ha

void USART1_IRQHandler(void)
{     if(USART_GetITStatus(USART1, USART_IT_RXNE) == SET)     {       uint8_t rx_data = USART_ReceiveData(USART1);         if(rx_data == 'a') //LED1 0         {            a=1;                            }         if(rx_data = = 'b') //LED1 1         {           a=2;         }         if(rx_data == 'c') //LED1 2         {           a=3;         }         USART_ClearITPendingBit(USART1, USART_IT_RXNE);     } } This is the interrupt service function, of course There are only some judgments here, and after making the judgments, you will find that the value of a is different when you receive different data, so you can use it to make judgments, just execute it in the main function, as shown in the figure
    
















        


That's all for sharing, remember to like, collect and follow.

Guess you like

Origin blog.csdn.net/weixin_53129688/article/details/127982201