当前位置:   article > 正文

stm32通过 一线串口通信控制JQ8900-16P语音模块_jq8900串口通信

jq8900串口通信

今天玩玩语音模块,用到了所谓的一线串口通信(就是用一个IO口发脉冲)不说了,上代码

JQ8900-16P语音模块资料自取:链接:https://pan.baidu.com/s/1O3P1Ro4Rc4cVMACuJVdqaA   提取码:1u4p 

接线:

      模块——————————单片机

ONE LINE—————————PB11

DC-5V———————————5V

GND———————————GND

  1. OneUart.c文件
  2. #include "OneUart.h"
  3. #include "delay.h"
  4. #include "stm32f10x.h"
  5. ///
  6. //函 OnUart_GPIO(void)
  7. //功 能:语音模块一线串口IO口
  8. //输入参数: void
  9. //输出参数: void
  10. //说 明:
  11. //
  12. void OnUart_GPIO(void)
  13. {
  14. GPIO_InitTypeDef GPIO_InitStructure;
  15. RCC->APB2ENR|=1<<3; //GPIOB
  16. //GPIOB.11
  17. GPIOB->CRH&=0xFFFF0FFF; //清零
  18. GPIOB->CRH|=0x00003000; //推挽输出 50MHZ
  19. GPIOB->ODR=~(1<<11); //B.11
  20. }
  21. ///
  22. //函 数:SendData(u8 addr)
  23. //功 能:语音模块一线串口
  24. //输入参数: addr要发送的0x数
  25. //输出参数: void
  26. //说 明:
  27. //
  28. void SendData ( u8 addr )//发送函数。
  29. {
  30. u8 i;
  31. /*发送时关掉中断,防止中断影响时序 */
  32. SDA = 1; /*开始拉高*/
  33. delay_us ( 1000 );
  34. SDA = 0; /*开始引导码*/
  35. delay_us ( 3200 );/*此处延时最少要大于2ms*/
  36. for ( i = 0; i < 8; i++ ) /*总共8位数据 */
  37. {
  38. SDA = 1;
  39. if ( addr & 0x01 ) /*3:1表示数据位1,每个位用两个脉冲表示 */
  40. {
  41. delay_us ( 600 );
  42. SDA = 0;
  43. delay_us ( 200 );
  44. }
  45. else /*13表示数据位0 ,每个位用两个脉冲表示 */
  46. {
  47. delay_us ( 200 );
  48. SDA = 0;
  49. delay_us ( 600 );
  50. }
  51. addr >>= 1;
  52. }
  53. SDA = 1;
  54. //恢复中断
  55. }

  1. .h文件
  2. #ifndef __ONEUART_H
  3. #define __ONEUART_H
  4. #include "sys.h"
  5. #define SDA PBout(11)
  6. void SendData ( u8 addr ); //发送函数。
  7. void OnUart_GPIO(void); //GPIO
  8. #endif

  1. main文件
  2. #include "stm32f10x.h"
  3. #include "delay.h"
  4. #include "OneUart.h"
  5. int main(void)
  6. {
  7. OnUart_GPIO();
  8. delay_init();
  9. while(1)
  10. {
  11. //发送0x013
  12. SendData(0x0a); //清空数字
  13. SendData(0x01); //曲目号
  14. SendData(0x03);
  15. SendData(0x0b); //选曲播放
  16. delay_ms(2000); //延时
  17. //发送0x01
  18. SendData(0x0a);
  19. SendData(0x01);
  20. SendData(0x0b);
  21. delay_ms(2000);
  22. //发送0x07
  23. SendData(0x0a);
  24. SendData(0x07);
  25. SendData(0x0b);
  26. delay_ms(2000);
  27. //发送0x03
  28. SendData(0x0a);
  29. SendData(0x03);
  30. SendData(0x0b);
  31. delay_ms(2000);
  32. }
  33. }

 在网上找了很多的延时函数,终于找到了一个达到要求的

  1. delay_us延时函数
  2. ///
  3. //函 数:delay_us(u6)
  4. //功 能:us延时函数
  5. //输入参数:u16 nTimer(延时时间)
  6. //输出参数:void
  7. //说 明:__NOP()【用__NOP()函数延时 72次】
  8. //
  9. void delay_us(u32 nTimer)
  10. {
  11. u32 i=0;
  12. for(i=0;i<nTimer;i++){
  13. __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
  14. __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
  15. __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
  16. __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
  17. __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
  18. }
  19. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/288281
推荐阅读
相关标签
  

闽ICP备14008679号