Re: UART傳輸與接收問題
|
||||
---|---|---|---|---|
高級會員
|
感謝Dark大跟版大的回覆
真的是TX程式的問題,多加一行while(!TXSTAbits.TRMT);,問題就改善了。 又學到一課,太棒了
發表於: 2021/2/8 8:24
|
|||
|
Re: UART傳輸與接收問題
|
||||
---|---|---|---|---|
資深會員
|
EUSART_Write(uart_tb[k]);
這行下面需多一個檢查TXREG是否清空 while(!TXSTAbits.TRMT); 你沒檢查發送狀態就是會被後面的蓋過去。 而且你TX程式也很怪 應該是要
while(1)
發表於: 2021/2/3 22:41
|
|||
|
UART傳輸與接收問題
|
||||
---|---|---|---|---|
高級會員
|
各位好:
我使用兩個PIC16F1823要做UART傳輸,丟一筆三位數的資料, 並用七段顯示器顯示數值 我有把百位,十位,各位,拆開來用ASCll傳輸 我遇到的問題是, 當數值從299 要跳到300時 有時數值會偶爾出現 200 或399, 感覺只有其中一兩個位數先變化 尤其在有干擾源的情況下狀況更嚴重, 我已經在接收端增加許多限制避免漏收就讀出,但狀況依然沒有完全改善 9600 8bit TX:(放在主程式的While迴圈) while(1) { Speed_V = Speed_Command; uart_tb[0] = 0xA5; uart_tb[1] = (Speed_V/100) +'0'; uart_tb[2] = ((Speed_V/10)%10) +'0'; uart_tb[3] = (Speed_V%10)+'0'; uart_tb[4] = Er_F +'0'; uart_tb[5] = 0x0D; EUSART_Write(uart_tb[k]); if(k++ == 5) { //Speed; k = 0; } } RX:(用中斷接收) void User_UART_ISR(void) { while (EUSART_DataReady) { if(FlagReg1.Uart_FLAG == 0) { value = EUSART_Read(); if(value = 0xA5) { FlagReg1.Uart_FLAG = 1; k = 0; } } else { value = EUSART_Read(); uart_tb[k] = value; k++; if(k==5 && value == 0x0D) { if(uart_tb[0] >= 0x30 && uart_tb[1] >= 0x30 && uart_tb[2] >= 0x30) { Speed_S = (uart_tb[0]-'0') *100 + (uart_tb[1]-'0') *10 + (uart_tb[2]-'0'); Speed_Value = Speed_S * 1; } uart_tb[0] = 0; uart_tb[1] = 0; uart_tb[2] = 0; FlagReg1.Uart_FLAG = 0; } } } }
發表於: 2021/2/2 11:03
|
|||
|