JQ6500语音模块详解(STM32)

打印 上一主题 下一主题

主题 1918|帖子 1918|积分 5754

目次
一、介绍
二、传感器原理
1.原理图
2.引脚形貌
三、步伐计划
main文件
usart.h文件
usart.c文件
四、实验结果 
五、资料获取
项目分享


一、介绍

        JQ6500是一种支持串口驱动的语音模块,提供串口的MP3芯片,集成了MP3、WMV的硬解码。同时软件支持TF卡驱动,支持电脑直接更新SPI Flash的内容,支持FAT16、FAT32文件体系。通过简单的串口指令即可完成播放指定的音乐,以及怎样播放音乐等功能,利用方便,稳固可靠。

以下是JQ6500语音模块的参数:
型号

JQ6500

工作电压

3.3~5V

额定电流

20mA

UART接口

尺度串口,TTL电平,波特率可设

工作温度

-40~80℃

湿度

5%~95%

哔哩哔哩视频链接:
     JQ6500语音模块(STM32)
  (资料分享见文末) 
二、传感器原理

1.原理图



2.引脚形貌



三、步伐计划

1.利用STM32F103C8T6利用JQ6500语音模块连接扬声器,通过按键控制播放几段音频。
KEY

PA0

JQ6500_TX

PA10

JQ6500_RX

PA9

OLED_SCL

PB11

OLED_SDA

PB10

main文件

  1. #include "stm32f10x.h"
  2. #include "led.h"
  3. #include "usart.h"
  4. #include "delay.h"
  5. #include "oled.h"
  6. #include "key.h"
  7. /*****************辰哥单片机设计******************
  8.                                                                                         STM32
  9. * 项目                        :        JQ6500语音模块实验                     
  10. * 版本                        : V1.0
  11. * 日期                        : 2025.2.7
  12. * MCU                        :        STM32F103C8T6
  13. * 接口                        :        参看usart.h                                               
  14. * BILIBILI        :        辰哥单片机设计
  15. * CSDN                        :        辰哥单片机设计
  16. * 作者                        :        辰哥
  17. **********************BEGIN***********************/
  18. int key = 0;
  19. int key_state = 0;
  20. int key_num = 0;
  21. int main(void)
  22. {
  23.        
  24.   SystemInit();//配置系统时钟为72M       
  25.         delay_init(72);
  26.         LED_Init();
  27.         LED_On();
  28.         USART1_Config();//串口初始化
  29.         Key_Init();
  30.         OLED_Init();
  31.         printf("Start \n");
  32.         delay_ms(1000);
  33.        
  34.         OLED_Clear();
  35.         //显示“语音序号:”
  36.         OLED_ShowChinese(0,0,0,16,1);
  37.         OLED_ShowChinese(16,0,1,16,1);
  38.         OLED_ShowChinese(32,0,2,16,1);
  39.         OLED_ShowChinese(48,0,3,16,1);
  40.         OLED_ShowChar(64,0,':',16,1);
  41.   while (1)
  42.   {
  43.                 key = Key_GetData();
  44.                 if(key)
  45.                 {
  46.                         key_state = 1;
  47.                         key_num++;
  48.                         if(key_num>3)key_num=1;
  49.                 }
  50.                 else
  51.                         key_state = 0;
  52.                
  53.                 if(key_state)
  54.                 {
  55.                         switch(key_num)
  56.                         {
  57.                                 case 1:
  58.                                         music_play(1);
  59.                                         LED_Toggle();
  60.                                         OLED_ShowNum(56,30,1,1,16,1);                //1
  61.                                 break;
  62.                                        
  63.                                 case 2:
  64.                                         music_play(2);
  65.                                         LED_Toggle();
  66.                                         OLED_ShowNum(56,30,2,1,16,1);                //2
  67.                                 break;
  68.                                
  69.                                 case 3:
  70.                                         music_play(3);
  71.                                         LED_Toggle();
  72.                                         OLED_ShowNum(56,30,3,1,16,1);                //3
  73.                                 break;
  74.                                
  75.                                 default:
  76.                                         break;
  77.                         }       
  78.                 }
  79.   }
  80. }
复制代码
usart.h文件

  1. #ifndef __USART1_H
  2. #define        __USART1_H
  3. #include "stm32f10x.h"
  4. #include <stdio.h>
  5. /*****************辰哥单片机设计******************
  6.                                                                                         STM32
  7. * 项目                        :        JQ6500语音模块实验                     
  8. * 版本                        : V1.0
  9. * 日期                        : 2025.2.7
  10. * MCU                        :        STM32F103C8T6
  11. * 接口                        :        参串口1                                               
  12. * BILIBILI        :        辰哥单片机设计
  13. * CSDN                        :        辰哥单片机设计
  14. * 作者                        :        辰哥
  15. **********************BEGIN***********************/
  16. void USART1_Config(void);
  17. int fputc(int ch, FILE *f);
  18. void USART1_printf(USART_TypeDef* USARTx, uint8_t *Data,...);
  19. void UART1SendByte(unsigned char SendData);
  20. void music_play(unsigned char dat);
  21. #endif /* __USART1_H */
复制代码
usart.c文件

  1. #include "usart.h"
  2. #include <stdarg.h>
  3. /*****************辰哥单片机设计******************
  4.                                                                                         STM32
  5. * 项目                        :        JQ6500语音模块实验                     
  6. * 版本                        : V1.0
  7. * 日期                        : 2025.2.7
  8. * MCU                        :        STM32F103C8T6
  9. * 接口                        :        参串口1                                               
  10. * BILIBILI        :        辰哥单片机设计
  11. * CSDN                        :        辰哥单片机设计
  12. * 作者                        :        辰哥
  13. **********************BEGIN***********************/
  14. void USART1_Config(void)
  15. {
  16.         GPIO_InitTypeDef GPIO_InitStructure;
  17.         USART_InitTypeDef USART_InitStructure;
  18.         /* 使能 USART1 时钟*/
  19.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
  20.         /* USART1 使用IO端口配置 */   
  21.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  22.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
  23.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  24.   GPIO_Init(GPIOA, &GPIO_InitStructure);   
  25.   
  26.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  27.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;        //浮空输入
  28.   GPIO_Init(GPIOA, &GPIO_InitStructure);   //初始化GPIOA
  29.           
  30.         /* USART1 工作模式配置 */
  31.         USART_InitStructure.USART_BaudRate = 9600;        //波特率设置:9600
  32.         USART_InitStructure.USART_WordLength = USART_WordLength_8b;        //数据位数设置:8位
  33.         USART_InitStructure.USART_StopBits = USART_StopBits_1;         //停止位设置:1位
  34.         USART_InitStructure.USART_Parity = USART_Parity_No ;  //是否奇偶校验:无
  35.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;        //硬件流控制模式设置:没有使能
  36.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//接收与发送都使能
  37.         USART_Init(USART1, &USART_InitStructure);  //初始化USART1
  38.         USART_Cmd(USART1, ENABLE);// USART1使能
  39. }
  40. /* 描述  :重定向c库函数printf到USART1*/
  41. int fputc(int ch, FILE *f)
  42. {
  43. /* 将Printf内容发往串口 */
  44.   USART_SendData(USART1, (unsigned char) ch);
  45.   while (!(USART1->SR & USART_FLAG_TXE));
  46.   return (ch);
  47. }
  48. /*发送一个字节数据*/
  49. void UART1SendByte(unsigned char SendData)
  50. {          
  51.                 USART_SendData(USART1,SendData);
  52.                 while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);            
  53. }
  54. void music_play(unsigned char dat)
  55. {
  56.         unsigned char  music_code[6] = {0X7E,0X04,0X03,0X00,0X01,0XEF};       
  57.         int i;
  58.         music_code[4] = dat;
  59.         for(i=0;i<6;i++)
  60.         {
  61.                 UART1SendByte(music_code[i]);
  62.         }
  63. }
复制代码
四、实验结果 


五、资料获取

项目分享


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

惊雷无声

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表