usart.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. #include "usart.h"
  2. uint8_t UART6_RX_BUF[BUFF_SIZE];
  3. uint8_t UART6_RX_STAT=0;
  4. uint32_t UART6_RX_NUM = 0;
  5. /**
  6. * @brief DEBUG_USART GPIO 配置,工作模式配置。115200 8-N-1 ,中断接收模式
  7. * @param 无
  8. * @retval 无
  9. */
  10. void DEBUG_USART_Config(void)
  11. {
  12. USART_InitTypeDef USART_InitStruct;
  13. GPIO_InitTypeDef GPIO_InitStruct;
  14. // Enable USART6 clock
  15. RCC_APB2PeriphClockCmd(DEBUG_USART_CLK, ENABLE);
  16. // Enable GPIOC clock
  17. RCC_AHB1PeriphClockCmd(DEBUG_USART_RX_GPIO_CLK, ENABLE);
  18. // Configure USART6 pins
  19. GPIO_InitStruct.GPIO_Pin = DEBUG_USART_RX_PIN | DEBUG_USART_TX_PIN; // USART6_TX (PC6) and USART6_RX (PC7)
  20. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  21. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  22. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
  23. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  24. GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStruct);
  25. // Connect USART6 pins to AF8
  26. GPIO_PinAFConfig(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_SOURCE, DEBUG_USART_RX_AF);
  27. GPIO_PinAFConfig(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_SOURCE, DEBUG_USART_TX_AF);
  28. // Configure USART6
  29. USART_InitStruct.USART_BaudRate = DEBUG_USART_BAUDRATE;
  30. USART_InitStruct.USART_WordLength = USART_WordLength_8b;
  31. USART_InitStruct.USART_StopBits = USART_StopBits_1;
  32. USART_InitStruct.USART_Parity = USART_Parity_No;
  33. USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  34. USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  35. USART_Init(DEBUG_USART, &USART_InitStruct);
  36. NVIC_InitTypeDef NVIC_InitStructure;
  37. NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ; //IRQ通道
  38. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //主优先级
  39. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //从优先级
  40. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道
  41. NVIC_Init(&NVIC_InitStructure);
  42. // Enable USART6
  43. USART_ITConfig(DEBUG_USART, USART_IT_IDLE, ENABLE); //开启空闲中断
  44. DMA_Cmd(DEBUG_USART_DMA_STREAM, ENABLE); //使能DMA接收
  45. USART_Cmd(DEBUG_USART, ENABLE);
  46. USART_ClearFlag(DEBUG_USART, USART_FLAG_TC);
  47. }
  48. void DEBUG_USART_IRQHandler(void)
  49. {
  50. uint16_t clear;
  51. if(USART_GetITStatus(DEBUG_USART,USART_IT_IDLE)!=RESET)
  52. {
  53. //清除空闲中断
  54. clear=USART6->SR;
  55. clear=USART6->DR;
  56. //关闭DMA
  57. DMA_Cmd(DEBUG_USART_DMA_STREAM,DISABLE);
  58. UART6_RX_NUM=BUFF_SIZE-DMA_GetCurrDataCounter(DEBUG_USART_DMA_STREAM);
  59. //清除DMA中断
  60. DMA_ClearFlag(DEBUG_USART_DMA_STREAM,DMA_IT_TCIF1);
  61. DMA_Cmd(DEBUG_USART_DMA_STREAM, ENABLE);
  62. //接收状态置位
  63. UART6_RX_STAT=1;
  64. }
  65. }
  66. /**
  67. * @brief USART1 TX DMA 配置,内存到外设(USART1->DR)
  68. * @param 无
  69. * @retval 无
  70. */
  71. void USART_DMA_Config(void)
  72. {
  73. // 使能串口和DMA时钟
  74. RCC_APB2PeriphClockCmd(DEBUG_USART_CLK, ENABLE);
  75. RCC_AHB1PeriphClockCmd(DEBUG_USART_DMA_CLK, ENABLE);
  76. DMA_InitTypeDef DMA_InitStructure;
  77. DMA_InitStructure.DMA_Channel = DEBUG_USART_DMA_CHANNEL;
  78. /*设置DMA源:串口数据寄存器地址*/
  79. DMA_InitStructure.DMA_PeripheralBaseAddr = DEBUG_USART_DR_BASE;
  80. /*内存地址(要传输的变量的指针)*/
  81. DMA_InitStructure.DMA_Memory0BaseAddr = (u32)UART6_RX_BUF;
  82. /*方向:从外设到内存*/
  83. DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
  84. /*传输大小DMA_BufferSize=SENDBUFF_SIZE*/
  85. DMA_InitStructure.DMA_BufferSize = BUFF_SIZE;
  86. /*外设地址不增*/
  87. DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  88. /*内存地址自增*/
  89. DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  90. /*外设数据单位*/
  91. DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  92. /*内存数据单位 8bit*/
  93. DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  94. /*DMA模式:不断循环*/
  95. DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
  96. /*优先级:中*/
  97. DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
  98. /*禁用FIFO*/
  99. DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
  100. DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  101. /*存储器突发传输 16个节拍*/
  102. DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  103. /*外设突发传输 1个节拍*/
  104. DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
  105. /*配置DMA2的数据流*/
  106. DMA_Init(DEBUG_USART_DMA_STREAM, &DMA_InitStructure);
  107. USART_DMACmd(DEBUG_USART,USART_DMAReq_Rx,ENABLE);
  108. DMA_ITConfig(DEBUG_USART_DMA_STREAM,DMA_IT_TC,ENABLE);
  109. NVIC_InitTypeDef NVIC_InitStructure;
  110. NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream5_IRQn ;//串口1发送中断通道
  111. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //抢占优先级
  112. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级
  113. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
  114. NVIC_Init(&NVIC_InitStructure);
  115. }
  116. void DMA2_Stream5_IRQHandler() {
  117. if (DMA_GetITStatus(DMA2_Stream1, DMA_IT_TCIF1))
  118. {
  119. DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1);
  120. }
  121. }
  122. /*
  123. 485串口de控制端口
  124. */
  125. void USART_485_DE_init()
  126. {
  127. GPIO_InitTypeDef GPIO_InitStruct;
  128. RCC_AHB1PeriphClockCmd(USART_485_DE_GPIO_CLK, ENABLE);
  129. GPIO_InitStruct.GPIO_Pin = USART_485_DE_PIN;
  130. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
  131. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  132. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  133. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  134. GPIO_Init(USART_485_DE_GPIO_PORT, &GPIO_InitStruct);
  135. }
  136. void USART_485_DE_TX()
  137. {
  138. GPIO_WriteBit(USART_485_DE_GPIO_PORT,USART_485_DE_PIN,1);
  139. }
  140. void USART_485_DE_RX()
  141. {
  142. GPIO_WriteBit(USART_485_DE_GPIO_PORT,USART_485_DE_PIN,0);
  143. }
  144. void USART_485_Send(uint8_t *message,uint16_t size)
  145. {
  146. uint16_t i=0;
  147. USART_485_DE_TX();
  148. for(i=0;i<size;i++)
  149. {
  150. USART_SendData(USART_232,*(message+i));
  151. while (USART_GetFlagStatus(USART_232, USART_FLAG_TC) == RESET);
  152. }
  153. USART_485_DE_RX();
  154. }
  155. //void _485_Config(void)
  156. //{
  157. // GPIO_InitTypeDef GPIO_InitStructure;
  158. // USART_InitTypeDef USART_InitStructure;
  159. // /* config USART clock */
  160. // RCC_AHB1PeriphClockCmd(_485_USART_RX_GPIO_CLK|_485_USART_TX_GPIO_CLK|_485_RE_GPIO_CLK, ENABLE);
  161. // RCC_APB1PeriphClockCmd(_485_USART_CLK, ENABLE);
  162. //
  163. // /* Connect PXx to USARTx_Tx*/
  164. // GPIO_PinAFConfig(_485_USART_RX_GPIO_PORT,_485_USART_RX_SOURCE, _485_USART_RX_AF);
  165. // /* Connect PXx to USARTx_Rx*/
  166. // GPIO_PinAFConfig(_485_USART_TX_GPIO_PORT,_485_USART_TX_SOURCE,_485_USART_TX_AF);
  167. //
  168. // /* USART GPIO config */
  169. // /* Configure USART Tx as alternate function push-pull */
  170. // GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  171. // GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  172. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  173. // GPIO_InitStructure.GPIO_Pin = _485_USART_TX_PIN ;
  174. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  175. // GPIO_Init(_485_USART_TX_GPIO_PORT, &GPIO_InitStructure);
  176. // /* Configure USART Rx as alternate function */
  177. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  178. // GPIO_InitStructure.GPIO_Pin = _485_USART_RX_PIN;
  179. // GPIO_Init(_485_USART_RX_GPIO_PORT, &GPIO_InitStructure);
  180. //
  181. // /* 485收发控制管脚 */
  182. // GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  183. // GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  184. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  185. // GPIO_InitStructure.GPIO_Pin = _485_RE_PIN ;
  186. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  187. // GPIO_Init(_485_RE_GPIO_PORT, &GPIO_InitStructure);
  188. //
  189. // /* USART mode config */
  190. // USART_InitStructure.USART_BaudRate = _485_USART_BAUDRATE;
  191. // USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  192. // USART_InitStructure.USART_StopBits = USART_StopBits_1;
  193. // USART_InitStructure.USART_Parity = USART_Parity_No ;
  194. // USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  195. // USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  196. // USART_Init(_485_USART, &USART_InitStructure);
  197. // USART_Cmd(_485_USART, ENABLE);
  198. //
  199. // NVIC_Configuration();
  200. // /* 使能串口接收中断 */
  201. // USART_ITConfig(_485_USART, USART_IT_RXNE, ENABLE);
  202. //
  203. // GPIO_ResetBits(_485_RE_GPIO_PORT,_485_RE_PIN); //默认进入接收模式
  204. //}
  205. /*
  206. 485串口在未配置情况下,初始化的参数
  207. */
  208. void USART_485_config()
  209. {
  210. USART_485_DE_init();
  211. USART_InitTypeDef USART_InitStruct;
  212. GPIO_InitTypeDef GPIO_InitStruct;
  213. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  214. RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
  215. GPIO_PinAFConfig(USART_485_RX_GPIO_PORT, USART_485_RX_SOURCE, USART_485_RX_AF);
  216. GPIO_PinAFConfig(USART_485_TX_GPIO_PORT, USART_485_TX_SOURCE, USART_485_TX_AF);
  217. GPIO_InitStruct.GPIO_Pin = USART_485_TX_PIN ;
  218. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  219. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  220. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  221. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  222. GPIO_Init(GPIOC, &GPIO_InitStruct);
  223. GPIO_InitStruct.GPIO_Pin = USART_485_RX_PIN;
  224. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  225. GPIO_Init(GPIOC, &GPIO_InitStruct);
  226. USART_InitStruct.USART_BaudRate = USART_485_BAUDRATE;
  227. USART_InitStruct.USART_WordLength = USART_WordLength_8b;
  228. USART_InitStruct.USART_StopBits = USART_StopBits_1;
  229. USART_InitStruct.USART_Parity = USART_Parity_No;
  230. USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  231. USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  232. USART_Init(USART_485, &USART_InitStruct);
  233. USART_Cmd(USART_485, ENABLE);
  234. USART_ClearFlag(USART_485, USART_FLAG_TC);
  235. USART_ITConfig(USART_485,USART_IT_RXNE,ENABLE);
  236. USART_ITConfig(USART_485,USART_IT_IDLE,ENABLE);
  237. NVIC_InitTypeDef NVIC_InitStruct;
  238. NVIC_InitStruct.NVIC_IRQChannel = USART_485_IRQ;
  239. NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
  240. NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
  241. NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
  242. NVIC_Init(&NVIC_InitStruct);
  243. }
  244. /*
  245. * 函数名:void Config_485_Port(uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity, uint8_t flowcontrol)
  246. * 输入参数:baudrate,databits,stopbits,parity,flowcontol 串口的配置参数
  247. * 输出参数:无
  248. * 返回值:无
  249. * 函数作用:根据输入参数进行配置485串口参数
  250. */
  251. void Config_485_Port(uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity, uint8_t flowcontrol)
  252. {
  253. uint8_t wordLength;
  254. if(parity!=0)
  255. {
  256. wordLength=databits+1;
  257. }else wordLength=databits;
  258. USART_InitTypeDef USART_InitStruct;
  259. GPIO_InitTypeDef GPIO_InitStruct;
  260. RCC_AHB1PeriphClockCmd(USART_485_CLK, ENABLE);
  261. RCC_APB2PeriphClockCmd(USART_485_RX_GPIO_CLK, ENABLE);
  262. GPIO_InitStruct.GPIO_Pin = USART_485_RX_PIN | USART_485_TX_PIN;
  263. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  264. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  265. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
  266. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  267. GPIO_Init(GPIOC, &GPIO_InitStruct);
  268. GPIO_PinAFConfig(USART_485_RX_GPIO_PORT, USART_485_RX_SOURCE, USART_485_RX_AF);
  269. GPIO_PinAFConfig(USART_485_TX_GPIO_PORT, USART_485_TX_SOURCE, USART_485_TX_AF);
  270. USART_InitStruct.USART_BaudRate = baudrate;
  271. USART_InitStruct.USART_WordLength = (wordLength== 9) ? USART_WordLength_9b : USART_WordLength_8b;
  272. USART_InitStruct.USART_StopBits = USART_StopBits_1;
  273. USART_InitStruct.USART_Parity = USART_Parity_No;
  274. USART_InitStruct.USART_Parity =(parity == 1) ? (USART_Parity_Odd) : (parity == 2 ? USART_Parity_Even : USART_Parity_No);
  275. USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  276. USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  277. USART_Init(USART_485, &USART_InitStruct);
  278. USART_Cmd(USART_485, ENABLE);
  279. USART_ClearFlag(USART1, USART_FLAG_TC);
  280. USART_ITConfig(USART_485,USART_IT_RXNE,ENABLE);
  281. USART_ITConfig(USART_485,USART_IT_IDLE,ENABLE);
  282. // 配置485接收中断优先级
  283. NVIC_InitTypeDef NVIC_InitStruct;
  284. NVIC_InitStruct.NVIC_IRQChannel = USART_485_IRQ;
  285. NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
  286. NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
  287. NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
  288. NVIC_Init(&NVIC_InitStruct);
  289. }
  290. /*
  291. 232串口配置
  292. */
  293. void USART_232_config()
  294. {
  295. USART_InitTypeDef USART_InitStruct;
  296. GPIO_InitTypeDef GPIO_InitStruct;
  297. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  298. RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  299. GPIO_PinAFConfig(USART_232_RX_GPIO_PORT, USART_232_RX_SOURCE, USART_232_RX_AF);
  300. GPIO_PinAFConfig(USART_232_TX_GPIO_PORT, USART_232_TX_SOURCE, USART_232_TX_AF);
  301. GPIO_InitStruct.GPIO_Pin = USART_232_RX_PIN | USART_232_TX_PIN;
  302. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  303. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  304. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
  305. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  306. GPIO_Init(GPIOA, &GPIO_InitStruct);
  307. USART_InitStruct.USART_BaudRate = USART_232_BAUDRATE;
  308. USART_InitStruct.USART_WordLength = USART_WordLength_8b;
  309. USART_InitStruct.USART_StopBits = USART_StopBits_1;
  310. USART_InitStruct.USART_Parity = USART_Parity_No;
  311. USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  312. USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  313. USART_Init(USART_232, &USART_InitStruct);
  314. USART_Cmd(USART_232, ENABLE);
  315. USART_ClearFlag(USART1, USART_FLAG_TC);
  316. USART_ITConfig(USART_232,USART_IT_RXNE,ENABLE);
  317. USART_ITConfig(USART_232,USART_IT_IDLE,ENABLE);
  318. // 配置USART1接收中断优先级
  319. NVIC_InitTypeDef NVIC_InitStruct;
  320. NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;
  321. NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
  322. NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
  323. NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
  324. NVIC_Init(&NVIC_InitStruct);
  325. }
  326. /***************** 发送一个字符 **********************/
  327. void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
  328. {
  329. /* 发送一个字节数据到USART */
  330. USART_SendData(pUSARTx,ch);
  331. /* 等待发送数据寄存器为空 */
  332. while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
  333. }
  334. /***************** 发送字符串 **********************/
  335. void Usart_SendString( USART_TypeDef * pUSARTx, char *str)
  336. {
  337. unsigned int k=0;
  338. do
  339. {
  340. Usart_SendByte( pUSARTx, *(str + k) );
  341. k++;
  342. } while(*(str + k)!='\0');
  343. /* 等待发送完成 */
  344. while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
  345. {}
  346. }
  347. /***************** 输出Hex字符串可能包含0x00**********************/
  348. void Usart_SendHex( USART_TypeDef * pUSARTx, uint8_t *str,uint16_t hexLength)
  349. {
  350. unsigned int k=0;
  351. do
  352. {
  353. Usart_SendByte( pUSARTx, *(str + k) );
  354. k++;
  355. } while(k==hexLength);
  356. /* 等待发送完成 */
  357. while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
  358. {}
  359. }
  360. /***************** 发送一个16位数 **********************/
  361. void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch)
  362. {
  363. uint8_t temp_h, temp_l;
  364. /* 取出高八位 */
  365. temp_h = (ch&0XFF00)>>8;
  366. /* 取出低八位 */
  367. temp_l = ch&0XFF;
  368. /* 发送高八位 */
  369. USART_SendData(pUSARTx,temp_h);
  370. while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
  371. /* 发送低八位 */
  372. USART_SendData(pUSARTx,temp_l);
  373. while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
  374. }
  375. /*********************************************END OF FILE**********************/