usart.c 15 KB

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