STM32103 USART DMA发送完成判断方法分享

2019-12-14 13:33发布

<i class="pstatus"> 本帖最后由 shuen729 于 2018-4-28 11:57 编辑 </i><br> <br><p> 今天调代码的时候,遇到这个问题,USART在DMA模式下,进DMA发送完成中断后发现数据其实USART那边还没有真正的完成发送,论坛里面搜“DMA 发送完成”有一篇帖子,但是很遗憾不让看,要密码。</p><br><p> 然后不得已,看参考手册,找到下面的时序图</p><br> <p><img src="https://www.xiaopingtou.net/data/attach/1912/s7logd01cd1ixh2sli8xicabop2ykx9w.jpg" lazyloadthumb="1" border="0" alt=""></p><br><p> 然后在中断里面改了下,先把DMA禁止掉,然后等待TC置位,TC置位就可以确认所有数据已经送出。</p><br><p> void DMA1_Channel7_IRQHandler(void)</p><br><p> {</p><br><p> &nbsp; &nbsp; if(SET==DMA_GetITStatus(DMA1_IT_TC7))</p><br><p> &nbsp; &nbsp; {</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;DMA_ClearITPendingBit(DMA1_IT_TC7);</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;DMA_Cmd(DMA_USART2_TX, DISABLE);</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;DMA_USART2_TX-&gt;CNDTR = 0;</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;while(RESET == USART_GetFlagStatus(USART2,USART_FLAG_TC))</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;USART_ClearFlag(USART2,USART_FLAG_TC);</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Usart2_TR_Sw(RS485_RX);</p><br><p> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return ;</p><br><p> &nbsp; &nbsp; }</p><br><p> }</p> <br> <p><img src="https://image.xiaopingtou.net/data/attach/191214/zbahRxQ9.png" alt="135857g95xy0xgxfpkfxmm"><br></p><p><br></p>
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。