无畏而为 发表于 2024-11-29 21:20

GD32F470,SPI DMA 读,DMA_INT_FLAG_FTF中断提前发生?

<p>外部中断EXTI_IRQHandler间隔启动读数据,中断后CS低电平使能读;<br />
读取指定数量数据后产生DMA1_Channel0_IRQHandler中断,CS高电平结束读。</p>

<p>异常:一般开始是正常读取,如正常波形,运行一段时间后,可能几分钟、几小时后DMA1_Channel0_IRQHandler提前产生中断,即实际并没有读取完毕,图波形图,CS已经高电平了,但是SPI_CLK仍然持续中。</p>

<p>黄色:CS电平<br />
蓝色:SPI CLK&nbsp;</p>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<div style="text-align: center;">
<div style="text-align: center;"></div>

<p>&nbsp;</p>

<p style="text-align: left;">相关代码:</p>
</div>

<p>void EXTI_IRQHandler(void)&nbsp;&nbsp; //定时产生SPI 读请求<br />
{<br />
&nbsp;&nbsp; &nbsp;if(RESET != exti_interrupt_flag_get(EXTI_Busy)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; exti_interrupt_flag_clear(EXTI_Busy);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;CS = CSReadEnable;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//启使能,如图低电平 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</p>

<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//启动的SPI DMA 中断 读&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dma_flag_clear(DMA,DMA_CH_RECV,DMA_FLAG_FTF);&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dma_flag_clear(DMA,DMA_CH_SEND,DMA_FLAG_FTF);&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;DMA_CHCNT(DMA, DMA_CH_RECV) = &nbsp;AD7606CHCount;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//void dma_transfer_number_config<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;DMA_CHCNT(DMA, DMA_CH_SEND) = &nbsp;AD7606CHCount;<br />
&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;DMA_CHCTL(DMA, DMA_CH_RECV) |= DMA_CHXCTL_CHEN;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//dma_channel_enable,启动DMA读。<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;DMA_CHCTL(DMA, DMA_CH_SEND) |= DMA_CHXCTL_CHEN;&nbsp;&nbsp; &nbsp;<br />
&nbsp; &nbsp; }<br />
}</p>

<p><br />
void DMA1_Channel0_IRQHandler(void)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//读取指定数量数据后产生中断。<br />
{<br />
&nbsp;&nbsp; &nbsp;if(RESET != dma_interrupt_flag_get(DMA,DMA_CH_RECV,DMA_INT_FLAG_FTF)){<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dma_interrupt_flag_clear(DMA,DMA_CH_RECV,DMA_INT_FLAG_FTF);&nbsp;&nbsp; &nbsp;</p>

<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;CS = CSHighZ;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//读取完成后,CS至高电平,<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;DMA_CHCTL(DMA, DMA_CH_RECV) &amp;= ~DMA_CHXCTL_CHEN;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//dma_channel_disable,下一次外部中断将再次开启。<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;DMA_CHCTL(DMA, DMA_CH_SEND) &amp;= ~DMA_CHXCTL_CHEN;&nbsp;&nbsp; &nbsp;&nbsp;</p>

<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//接收数据处理<br />
&nbsp;&nbsp; &nbsp;}<br />
}</p>

32446975 发表于 2024-11-30 11:01

<p></p>


<p>开启DMA的错误中断,在回调函数中输出调试信息。排查下,是否产生了DMA传输错误?</p>

wangerxian 发表于 2024-11-30 16:11

<p>想避免这个问题,我觉得还是别用DMA了,这个问题确实有点奇怪。</p>
页: [1]
查看完整版本: GD32F470,SPI DMA 读,DMA_INT_FLAG_FTF中断提前发生?