stm32f103c8t6通过SPI2调用ld3320实现语音识别

  1. 硬件连接

采用SPI2连接。

VCC       3.3V

GND      地线

RST       PB11

CS          PB8

WR/SPIS   PB12

P2/SDCK   PB13

P1/SDO    PB14

P0/SDI    PB15

IRQ       PB9

  1. stm32F103C8T6设置

芯片时钟频率设置为12Mhz。

  1. 核心代码

(1)、ld3320模块io口配置

void LD3320_GPIO_Cfg(void)

{     

       GPIO_InitTypeDef GPIO_InitStructure;      

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB ,ENABLE);

       //LD_CS  /RSET

       GPIO_InitStructure.GPIO_Pin =GPIO_Pin_8|GPIO_Pin_11;//;

       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

       GPIO_Init(GPIOB,&GPIO_InitStructure);

}

(2)、ld3320模块io口配置

void LD3320_Spi_cfg(void)

{

       SPI_InitTypeDef  SPI_InitStructure;

       GPIO_InitTypeDef GPIO_InitStructure;

  //spi端口配置

       RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 | RCC_APB2Periph_GPIOB,ENABLE);       //使能SPI2外设时钟

  GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

 

       //P13/P14/P15

       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13;

       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

       GPIO_Init(GPIOB,&GPIO_InitStructure);

 

       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;                  //spis 片选    WR

       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

       GPIO_Init(GPIOB, &GPIO_InitStructure);

 

       LD_CS_H();

      

       //spi功能配置

       SPI_Cmd(SPI2, DISABLE);

       /* SPI2 配置 */

       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_128;  //波特率控制 SYSCLK/128

 

       SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;                     //数据高位在前

       SPI_InitStructure.SPI_CRCPolynomial = 7;            //CRC多项式寄存器初始值为7

       SPI_Init(SPI2, &SPI_InitStructure);

       /* 使能SPI2 */

       SPI_Cmd(SPI2, ENABLE);

 

}

(3)、ld3320时钟输入值配置

#define CLK_IN          22    /* user need modify this value according to clock in */

(4)、ld3320中断配置代码

void LD3320_EXTI_Cfg(void)

{

EXTI_InitTypeDef EXTI_InitStructure;

       NVIC_InitTypeDef NVIC_InitStructure;

    GPIO_InitTypeDef GPIO_InitStructure;

 

    //中断引脚配置

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &GPIO_InitStructure);

       //外部中断线配置

    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);

    EXTI_InitStructure.EXTI_Line = EXTI_Line9;

    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_Line9);

             

       GPIO_SetBits(GPIOB,GPIO_Pin_9);      //默认拉高中断引脚

 

       EXTI_ClearFlag(EXTI_Line9);

       EXTI_ClearITPendingBit(EXTI_Line9);

       //中断嵌套配置

    NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

}

因为PB9中断引脚在5-9范围内,因此中断通道名称是EXTI9_5_IRQn。注意不是EXTI5_9_IRQn。

(4)、ld3320中断函数代码

void EXTI9_5_IRQHandler(void)  

{

       if(EXTI_GetITStatus(EXTI_Line9)!= RESET )

       {

             ProcessInt0();

              PrintCom(USART1,"进入中断\r\n");    /*text........................*/

              EXTI_ClearFlag(EXTI_Line9);

              EXTI_ClearITPendingBit(EXTI_Line9);

       }

}

函数名为EXTI9_5_IRQHandler。

(4)、ld3320引脚宏代码

#define LD_RST_H() GPIO_SetBits(GPIOB, GPIO_Pin_11)

#define LD_RST_L() GPIO_ResetBits(GPIOB, GPIO_Pin_11)

 

#define LD_CS_H() GPIO_SetBits(GPIOB, GPIO_Pin_8)

#define LD_CS_L() GPIO_ResetBits(GPIOB, GPIO_Pin_8)

 

#define LD_SPIS_H()  GPIO_SetBits(GPIOB, GPIO_Pin_12)

#define LD_SPIS_L()  GPIO_ResetBits(GPIOB, GPIO_Pin_12)

因为在LD3320里多处要操作这些引脚的电平,因此统一用宏来处理。

(5)、ld3320主函数代码

void  LD3320_main(void)

{

       uint8 nAsrRes=0;

       LD3320_Init();  

 

PrintCom(USART1," 串口运行中....\r\n"); /*text.....*/

       PrintCom(USART1,"口令:1、流水灯右移\r\n"); /*text.....*/

       PrintCom(USART1,"2、闪烁\r\n"); /*text.....*/

       PrintCom(USART1,"3、流水灯左移\r\n"); /*text.....*/

       PrintCom(USART1,"4、全灭\r\n"); /*text.....*/

 

       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识别结果

                            PrintCom(USART1,"\r\n识别码:");                    /*text.....*/

                            USART_SendData(USART1,nAsrRes+0x30); /*text.....*/                         

                            switch(nAsrRes)               /*对结果执行相关操作,客户修改*/

                            {

                                   case CODE_LSDYY:                    /*命令“打开”*/                                                                     PrintCom(USART1,"“流水灯右移”命令识别成功\r\n"); /*text.....*/

                                       Glide_LED_Right();        //实现流水灯右移功能

                                   break;

                                   case CODE_SS:      /*命令“闪烁”*/                                                                                        PrintCom(USART1,"“闪烁”命令识别成功\r\n"); /*text.....*/

                                          Flicker_LED();        //实现灯闪烁功能                                                                          break;

                                   case CODE_LSDZY:             /*命令“流水灯左移”*/                                                                  PrintCom(USART1,"“流水灯左移”命令识别成功\r\n"); /*text.....*/

                                          Glide_LED_Left();     //实现流水灯左移功能                                                                    break;

                                   case CODE_QM:          /*命令“全灭”*/                                                                                   PrintCom(USART1,"“全灭”命令识别成功\r\n"); /*text.....*/

                                       Off_LED();             //关闭全部LED                                                                                  break;

                                   default:break;

                            }     

                            nAsrStatus = LD_ASR_NONE;

                            break;

                    

                     case LD_ASR_FOUNDZERO:

                     default:

                            nAsrStatus = LD_ASR_NONE;

                            break;

                     }//switch

           //开发板测试延时部分(用户可删除)           

              Board_text(nAsrRes );   /*text....................*/

       }// while

}

 

  1. 完整代码,请加QQ(395702361)索取。
实现语音识别打印,需要使用 STM32F103C8T6 微控制器作为主控芯片,HPD482L 作为打印模块,LD3320 作为语音识别模块。 首先,需要将 STM32F103C8T6 与 HPD482L 和 LD3320 进行连接。连接方式如下: - 将STM32F103C8T6的TX引脚连接到LD3320的RX引脚,将STM32F103C8T6的RX引脚连接到LD3320的TX引脚,以实现串口通信。 - 将HPD482L的DIN引脚连接到STM32F103C8T6的PB15引脚,将HPD482L的CS引脚连接到STM32F103C8T6的PB14引脚,将HPD482L的CLK引脚连接到STM32F103C8T6的PB13引脚,以实现SPI通信。 接下来,需要编写代码实现语音识别和打印功能。具体实现步骤如下: 1. 初始化串口和SPI接口 首先需要初始化串口和SPI接口,以便进行通信。在STM32F103C8T6上使用标准库函数进行初始化。 2. 初始化LD3320 设置LD3320的识别模式和参数,同时设置STM32F103C8T6的中断函数,以获取LD3320的响应。在STM32F103C8T6上使用标准库函数进行初始化。 3. 语音识别 使用LD3320进行语音识别,当LD3320检测到声音时,将语音信号通过串口发送给STM32F103C8T6。在STM32F103C8T6上接收到语音信号后,使用相应的算法进行语音识别,例如使用MFCC算法进行特征提取和匹配。 4. 打印 当语音被识别后,使用HPD482L进行打印。将打印数据通过SPI接口发送给HPD482L,HPD482L将数据打印出来。 以上是实现语音识别打印的大致步骤,具体实现需要根据硬件和软件的具体情况进行调整。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wave12_mp

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值