123asdasd 发表于 2024-3-24 11:41

大佬们帮忙看一看

<p>本人想基于MSPM0L1306实现利用串口输入控制单片机功能的程序,例如如果检测到串口输入的值为3,那么就输出当前的温度值,但是无论怎么做都成功不了,还请各位大佬帮忙看一下怎么改正,以下为部分源代码,其中rxData为记录串口输入的变量,uint_8和uint_16都试过了,没用</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>void UART_0_INST_IRQHandler(void)<br />
{<br />
&nbsp; &nbsp; switch (DL_UART_Main_getPendingInterrupt(UART_0_INST))<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; case DL_UART_MAIN_IIDX_RX:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rxData = DL_UART_Main_receiveData(UART_0_INST);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; default:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp;if(rxData == &#39;3&#39;)<br />
&nbsp; &nbsp; &nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; UARTprintf(&quot;The current temperature is \n&quot;);&nbsp; //UARTprintf为前面定义的字符串输出函数,没有问题<br />
&nbsp; &nbsp; &nbsp; &nbsp; Usart_Send_16bit_Data(result);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Usart_Send_16bit_Data为前面定义的整型输出函数,没有问题<br />
&nbsp; &nbsp; &nbsp; &nbsp; UARTprintf(&quot;*C\n&quot;);<br />
&nbsp; &nbsp; &nbsp;}<br />
&nbsp;else if(rxData == 10 )<br />
&nbsp; &nbsp; &nbsp; &nbsp; UARTprintf(&quot;please input the right number \n&quot;);<br />
&nbsp; &nbsp; &nbsp;}<br />
}</p>

极限零 发表于 2024-3-25 09:05

<p>switch 中遇到break会跳出switch,因此,你这代码永远不会执行到&nbsp;if(rxData == &#39;3&#39;)这一步</p>

wangerxian 发表于 2024-3-25 15:14

<p>建议不要在中断里做判断,直接在main的while函数中去判断rxData数据,如果不等于0进入你的switch,处理完后rxData清零。</p>
页: [1]
查看完整版本: 大佬们帮忙看一看