#include #if defined ( __CC_ARM )#pragma anon_._syn8266">
当前位置:   article > 正文

RT系统+STM32+SYN8266播报+红外定时器

syn8266

老规矩,先上产品图

 实验材料 :

stm32f103c8t6+syn8266+红外传感器

实验平台:

keil + RT系统

主要附上如何配置SYN8266

syn8266.h

  1. #ifndef _SYN6288_H_
  2. #define _SYN6288_H_
  3. #include "stm32f10x.h"
  4. #include <stdio.h>
  5. #include <stdbool.h>
  6. #if defined ( __CC_ARM )
  7. #pragma anon_unions
  8. #endif
  9. /******************************* ESP8266 外部全局变量声明 ***************************/
  10. #define RX_BUF_MAX_LEN 1024 //最大接收缓存字节数
  11. extern struct STRUCT_USARTx_Fram //串口数据帧的处理结构体
  12. {
  13. char Data_RX_BUF [ RX_BUF_MAX_LEN ];
  14. union {
  15. __IO u16 InfAll;
  16. struct {
  17. __IO u16 FramLength :15; // 14:0
  18. __IO u16 FramFinishFlag :1; // 15
  19. } InfBit;
  20. };
  21. } strUSART_Fram_Record;
  22. /* 开发板硬件相关头文件 */
  23. /**
  24. ******************************************************************************
  25. * @File SYN6288.h
  26. * @Author Velscode
  27. * @Email velscode@gmail.com
  28. * @Brief TTS 芯片 SYN6288驱动头文件(基于STM32F10x)
  29. * 使用了USART2(A2\A3)
  30. ******************************************************************************
  31. */
  32. //extern struct STRUCT_USARTx_Fram strUSART_Fram_Record;
  33. /****************************** SYN6288 引脚配置参数定义***************************************/
  34. #define SYN6288_GPIO_APBxClock_FUN RCC_APB2PeriphClockCmd
  35. #define SYN6288_GPIO_CLK RCC_APB2Periph_GPIOB
  36. #define SYN6288_GPIO_PORT GPIOB
  37. #define SYN6288_GPIO_PIN GPIO_Pin_2
  38. #define SYN6288_Read_GPIO_IN() GPIO_ReadInputDataBit ( SYN6288_GPIO_PORT, SYN6288_GPIO_PIN )
  39. // 串口2-USART2
  40. #define DEBUG_USART_SYN6288 USART3
  41. #define DEBUG_USART_CLK_SYN6288 RCC_APB1Periph_USART3
  42. #define DEBUG_USART_APBxClkCmd_SYN6288 RCC_APB1PeriphClockCmd
  43. #define DEBUG_USART_BAUDRATE 9600
  44. // USART GPIO 引脚宏定义
  45. #define DEBUG_USART_GPIO_CLK_SYN6288 (RCC_APB2Periph_GPIOB)
  46. #define DEBUG_USART_GPIO_APBxClkCmd RCC_APB2PeriphClockCmd
  47. #define DEBUG_USART_TX_GPIO_PORT_SYN6288 GPIOB
  48. #define DEBUG_USART_TX_GPIO_PIN_SYN6288 GPIO_Pin_10
  49. #define DEBUG_USART_RX_GPIO_PORT_SYN6288 GPIOB
  50. #define DEBUG_USART_RX_GPIO_PIN_SYN6288 GPIO_Pin_11
  51. #define DEBUG_USART_IRQ_SYN6288 USART3_IRQn
  52. #define DEBUG_USART_IRQHandler_SYN6288 USART3_IRQHandler
  53. void SYN6288_GPIO_Config ( void );
  54. void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch);
  55. void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str );
  56. void SYN688_USART_Config(void);
  57. void Usart_SYN6288_SendByte( USART_TypeDef * pUSARTx, uint8_t ch);
  58. void SYN_FrameInfo(char *HZdata);
  59. void Usart_SSYN6288_endString( USART_TypeDef * pUSARTx, char *str);
  60. /* 音量控制 */
  61. void Volinme(uint8_t Y_L);
  62. /* 语调控制 */
  63. void Intonation(uint8_t Y_L);
  64. /* 语速控制 */
  65. void Speed_pacing(uint8_t Y_L);
  66. /* 人控制 */
  67. void speed_man(uint8_t Y_L);
  68. #endif /*_SYN6288_H_*/
  69. /* End of File ------------------------------------------------------------- */

syn8266.c

  1. /**
  2. ******************************************************************************
  3. * @File SYN6288.c
  4. * @Author Velscode
  5. * @Email velscode@gmail.com
  6. * @Brief TTS 芯片 SYN6288驱动源代码文件(基于STM32F10x)
  7. * 使用了USART2(A2\A3
  8. ******************************************************************************
  9. */
  10. /* Internal Function Declaration ------------------------------------------- */
  11. void usart2_Init(unsigned int bound);
  12. /* Header Files ------------------------------------------------------------ */
  13. #include "SYN6288.h"
  14. #include "string.h"
  15. /* RT-Thread相关头文件 */
  16. #include <rthw.h>
  17. #include <rtthread.h>
  18. #include <string.h>
  19. struct STRUCT_USARTx_Fram strUSART_Fram_Record = { 0 };
  20. /**
  21. * @brief 配置嵌套向量中断控制器NVIC
  22. * @param 无
  23. * @retval 无
  24. */
  25. static void NVIC_Configuration(void)
  26. {
  27. NVIC_InitTypeDef NVIC_InitStructure;
  28. /* 嵌套向量中断控制器组选择 */
  29. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  30. /* 配置USART为中断源 */
  31. NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ_SYN6288;
  32. /* 抢断优先级*/
  33. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  34. /* 子优先级 */
  35. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  36. /* 使能中断 */
  37. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  38. /* 初始化配置NVIC */
  39. NVIC_Init(&NVIC_InitStructure);
  40. }
  41. //读忙
  42. void SYN6288_GPIO_Config ( void )
  43. {
  44. /*定义一个GPIO_InitTypeDef类型的结构体*/
  45. GPIO_InitTypeDef GPIO_InitStructure;
  46. /* 配置 LED1 引脚 */
  47. SYN6288_GPIO_APBxClock_FUN(SYN6288_GPIO_CLK, ENABLE);
  48. GPIO_InitStructure.GPIO_Pin = SYN6288_GPIO_PIN;
  49. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  50. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  51. GPIO_Init ( SYN6288_GPIO_PORT, & GPIO_InitStructure );
  52. }
  53. /**
  54. * @brief USART GPIO 配置,工作参数配置
  55. * @param 无
  56. * @retval 无
  57. */
  58. void SYN688_USART_Config(void)
  59. {
  60. GPIO_InitTypeDef GPIO_InitStructure;
  61. USART_InitTypeDef USART_InitStructure;
  62. // 打开串口GPIO的时钟
  63. DEBUG_USART_GPIO_APBxClkCmd(DEBUG_USART_GPIO_CLK_SYN6288, ENABLE);
  64. // 打开串口外设的时钟
  65. DEBUG_USART_APBxClkCmd_SYN6288(DEBUG_USART_CLK_SYN6288, ENABLE);
  66. // 将USART Tx的GPIO配置为推挽复用模式
  67. GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_GPIO_PIN_SYN6288;
  68. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  69. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  70. GPIO_Init(DEBUG_USART_TX_GPIO_PORT_SYN6288, &GPIO_InitStructure);
  71. // 将USART Rx的GPIO配置为浮空输入模式
  72. GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_GPIO_PIN_SYN6288;
  73. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  74. GPIO_Init(DEBUG_USART_RX_GPIO_PORT_SYN6288, &GPIO_InitStructure);
  75. // 配置串口的工作参数
  76. // 配置波特率
  77. USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
  78. // 配置 针数据字长
  79. USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  80. // 配置停止位
  81. USART_InitStructure.USART_StopBits = USART_StopBits_1;
  82. // 配置校验位
  83. USART_InitStructure.USART_Parity = USART_Parity_No ;
  84. // 配置硬件流控制
  85. USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  86. // 配置工作模式,收发一起
  87. USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  88. // 完成串口的初始化配置
  89. USART_Init(DEBUG_USART_SYN6288, &USART_InitStructure);
  90. // 串口中断优先级配置
  91. NVIC_Configuration();
  92. // 使能串口接收中断
  93. USART_ITConfig(DEBUG_USART_SYN6288, USART_IT_RXNE, ENABLE);
  94. // 使能串口
  95. USART_Cmd(DEBUG_USART_SYN6288, ENABLE);
  96. // 清除发送完成标志
  97. //USART_ClearFlag(USART1, USART_FLAG_TC);
  98. }
  99. //其实是USART2_Send_Byte
  100. /***************** 发送一个字符 **********************/
  101. void Usart_SYN6288_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
  102. {
  103. /* 发送一个字节数据到USART */
  104. USART_SendData(pUSARTx,ch);
  105. /* 等待发送数据寄存器为空 */
  106. while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
  107. }
  108. /***************** 发送字符串 **********************/
  109. void Usart_SSYN6288_endString( USART_TypeDef * pUSARTx, char *str)
  110. {
  111. unsigned int k=0;
  112. do
  113. {
  114. Usart_SYN6288_SendByte( pUSARTx, *(str + k) );
  115. k++;
  116. } while(*(str + k)!='\0');
  117. /* 等待发送完成 */
  118. while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
  119. {}
  120. }
  121. //语音合成
  122. void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str )
  123. {
  124. if(SYN6288_Read_GPIO_IN()==Bit_RESET)/* x us后仍为高电平表示数据“1*/
  125. {
  126. char * p = str;
  127. int len = 0,check=0xFD,i;
  128. while( *p++ != 0 )
  129. {
  130. len++;
  131. }
  132. len+=3;
  133. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
  134. Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,len / 256 );
  135. Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,len % 256 );
  136. check = check ^ ( len / 256 ) ^ ( len % 256 );
  137. Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,0x01 );
  138. Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,0x01 );
  139. check = check ^ 0x01 ^ 0x01;
  140. for( i = 0; i < len-3; i++ )
  141. {
  142. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,*str);
  143. check ^= ( *str );
  144. str++;
  145. }
  146. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,check);
  147. rt_thread_delay(150*len);
  148. }
  149. }
  150. /* 音量控制 */
  151. void Volinme(uint8_t Y_L)
  152. {
  153. uint8_t num ;
  154. num = Y_L+48;
  155. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
  156. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
  157. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
  158. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
  159. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
  160. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
  161. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x76);
  162. //控制音量
  163. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
  164. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
  165. // uint8_t num[9] ;
  166. //
  167. // num[0] = 0xFD;
  168. // num[1] = 0x00;
  169. // num[2] = 0x06;
  170. // num[3] = 0x01;
  171. // num[4] = 0x01;
  172. // num[5] = 0x5B;
  173. // num[6] = 0x76;
  174. // //控制音量
  175. // num[7] = Y_L+48;
  176. // num[8] = 0x5D;
  177. //
  178. // Usart_SendByte(DEBUG_USARTx,num[8]);
  179. }
  180. /* 语调控制 */
  181. void Intonation(uint8_t Y_L)
  182. {
  183. uint8_t num ;
  184. num = Y_L+48;
  185. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
  186. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
  187. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
  188. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
  189. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
  190. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
  191. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x74);
  192. //控制音量
  193. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
  194. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
  195. }
  196. /* 语速控制 */
  197. void Speed_pacing(uint8_t Y_L)
  198. {
  199. uint8_t num ;
  200. num = Y_L+48;
  201. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
  202. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
  203. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
  204. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
  205. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
  206. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
  207. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x73);
  208. //控制音量
  209. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
  210. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
  211. }
  212. /* 人控制 */
  213. void speed_man(uint8_t Y_L)
  214. {
  215. uint8_t num ;
  216. num = Y_L+48;
  217. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
  218. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
  219. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x07);
  220. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
  221. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
  222. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
  223. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x6D);
  224. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x35);
  225. //控制音量
  226. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
  227. Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
  228. }
  229. /* End of File ------------------------------------------------------------- */

stm32f10x_it.t添加中断函数

  1. /* 该文件统一用于存放中断服务函数 */
  2. #include "stm32f10x_it.h"
  3. #include "SYN6288.h"
  4. // 串口中断服务函数
  5. void DEBUG_USART_IRQHandler_SYN6288(void)
  6. {
  7. uint8_t ucCh;
  8. if ( USART_GetITStatus ( DEBUG_USART_SYN6288, USART_IT_RXNE ) != RESET )
  9. {
  10. ucCh = USART_ReceiveData( DEBUG_USART_SYN6288 );
  11. if ( strUSART_Fram_Record .InfBit .FramLength < ( RX_BUF_MAX_LEN - 1 ) ) //预留1个字节写结束符
  12. strUSART_Fram_Record .Data_RX_BUF [ strUSART_Fram_Record .InfBit .FramLength ++ ] = ucCh;
  13. }
  14. if ( USART_GetITStatus( DEBUG_USART_SYN6288, USART_IT_IDLE ) == SET ) //数据帧接收完毕
  15. {
  16. strUSART_Fram_Record .InfBit .FramFinishFlag = 1;
  17. ucCh = USART_ReceiveData( DEBUG_USART_SYN6288 ); //由软件序列清除中断标志位(先读USART_SR,然后读USART_DR)
  18. }
  19. }

初始化syn8266

  1. //语音播报系统
  2. SYN6288_GPIO_Config();
  3. SYN688_USART_Config();

在主函数中使用

  1. //APP2
  2. static void APP2_thread_entry(void* parameter)
  3. {
  4. rt_uint8_t key=0;
  5. rt_uint8_t dispBuff[100];
  6. rt_uint8_t t=0;
  7. rt_uint8_t *str=0;
  8. while(1)
  9. {
  10. key=Remote_Scan();
  11. if(key)
  12. {
  13. switch(key)
  14. {
  15. case 162:
  16. //1
  17. str= "· time 10min·";
  18. munite = 10;
  19. hour=0;
  20. second=0;
  21. SYN6288_Speech(DEBUG_USART_SYN6288,"定时十分钟");
  22. break;
  23. case 98:
  24. //2
  25. str= "· time 20min·";
  26. munite = 20;
  27. hour=0;
  28. second=0;
  29. SYN6288_Speech(DEBUG_USART_SYN6288,"定时二十分钟");
  30. break;
  31. case 226://3
  32. str= "· time 30min·";
  33. munite = 30;
  34. hour=0;
  35. second=0;
  36. SYN6288_Speech(DEBUG_USART_SYN6288,"定时三十分钟");
  37. break;
  38. case 34://4
  39. str= "· time 40min·";
  40. munite = 40;
  41. hour=0;
  42. second=0;
  43. SYN6288_Speech(DEBUG_USART_SYN6288,"定时四十分钟");
  44. break;
  45. case 2://5
  46. str= "· time 50min·";
  47. munite = 50;
  48. hour=0;
  49. second=0;
  50. SYN6288_Speech(DEBUG_USART_SYN6288,"定时五十分钟");
  51. break;
  52. case 194://6
  53. str= "· time 60min·";
  54. munite = 60;
  55. hour=0;
  56. second=0;
  57. SYN6288_Speech(DEBUG_USART_SYN6288,"定时六十分钟");
  58. break;
  59. case 224://7
  60. str= "· time 90min·";
  61. hour = 1;
  62. munite = 30;
  63. second=0;
  64. SYN6288_Speech(DEBUG_USART_SYN6288,"定时一个半小时");
  65. break;
  66. case 168://8
  67. str= "· time 2h ·";
  68. hour = 1;
  69. munite = 60;
  70. second=0;
  71. SYN6288_Speech(DEBUG_USART_SYN6288,"定时两个小时");
  72. break;
  73. case 144://9
  74. SYN6288_Speech(DEBUG_USART_SYN6288,"定时三个小时");
  75. str= "· time 3h ·";
  76. hour = 2;
  77. munite = 60;
  78. second=0;
  79. break;
  80. case 152:
  81. str= "detected code 0";
  82. name();
  83. break;
  84. case 104:
  85. str= "detected code *";
  86. break;
  87. case 176:
  88. str= "detected code #";
  89. break;
  90. case 24:
  91. str= "detected code ↑";
  92. break;
  93. case 16:
  94. str= "detected code ←";
  95. break;
  96. case 74:
  97. str= "detected code ↓";
  98. break;
  99. case 90:
  100. str= "detected code →";
  101. break;
  102. case 56:
  103. str= "detected code OK ";
  104. break;
  105. default:
  106. str= "EMOURE";
  107. break;
  108. }
  109. Draw_Font16B(4,100,BRRED,str); //显示SYMBOL
  110. key = 0;
  111. // uwRet = rt_thread_resume(APP3_thread);/* 恢复APP3线程! */
  112. // if(RT_EOK == uwRet)
  113. // {
  114. // rt_kprintf("恢复APP3线程成功!\n");
  115. // }
  116. // else
  117. // {
  118. // rt_kprintf("恢复APP3线程失败!失败代码:0x%lx\n",uwRet);
  119. // }
  120. }
  121. }
  122. }

附上代码连接 红外+语音播报 

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