• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: [求助]PIC18F662X -- UART傳送問題??? 急~~~
#6
高級會員
高級會員


查看用戶資訊
謝謝回覆~~

Debug中......

發表於: 2007/9/3 10:20
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: [求助]PIC18F662X -- UART傳送問題??? 急~~~
#5
版主
版主


查看用戶資訊
C_H_M 已經提醒過了,因為 check TXIF 只是知道 tx data 已經載入 TxTSR 暫存器中,實際資料還沒移出去,這時關掉 UART 最後一個 Byte (0x0A) 就送不出去了。將程式改成 Check TRMT 位元就可以了。 詳細請看 Data Sheet 有關 Asynchronous Transmission Timming

或參考 C18 W401 workshop 教材第5-3章之說明。

發表於: 2007/8/31 18:35
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: [求助]PIC18F662X -- UART傳送問題??? 急~~~
#4
高級會員
高級會員


查看用戶資訊
謝謝回覆!!
-----------------------------------------------------------------------------
// 以下的條件式改為 Pc_Output_Ptr < Pc_Output_Code_Cnt
// 以本程式為例, 發送6個字元時,
// 應為 [0], [1], [2], [3], [4], [5] 這6個字元
if (Pc_Output_Ptr < Pc_Output_Code_Cnt )
{
Write2USART(Pc_Output_Buffer[Pc_Output_Ptr]) ;
Pc_Output_Ptr += 1;
}

這是另一個問題----
我改為以上時, 利用監控程式, MCU送出為 XX,XX,XX,XX,0x0D,0xFF, 0x0A送不出來
若為原程式, MCU送出 XX,XX,XX,XX,0x0D,0x0A,0xFF

不知道位什麼會送出0xFF????程式並沒有送出0xFF的值.

發表於: 2007/8/31 17:43
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: [求助]PIC18F662X -- UART傳送問題??? 急~~~
#3
中級會員
中級會員


查看用戶資訊
看起來是沒有明顯的錯誤啦!
但還是提一些修改的建議給你...
void SendACKtoPC(void)
{   
    
Pc_Output_Buffer[0] = STX;
    
Pc_Output_Buffer[1] = ACK;
    
Pc_Output_Buffer[2] = MODE;
    
Pc_Output_Buffer[3] = CHECKSUM;
    
Pc_Output_Buffer[4]= 0xDPc_Output_Buffer[5]= 0xA;
    
Pc_Output_Code_Cnt=6;
    
Pc_Output_Ptr 0;
    
Rs_232_Rx_Tx_Flag.Rs_232_Tx_Fg=1;
    
TXSTA2bits.TXEN 
                
//這行搬往前,
                //必竟發送的順序應是致能發送後才開始發送
    
PIE3bits.TX2IE=1;    
    
Nop();
    
Nop();
}

#pragma        interrupt    Isr_High
void    Isr_High(void)
{
    if (
PIR3bits.TX2IF==&& PIE3bits.TX2IE==1)
    {
        
Nop();
        
PIR3bits.TX2IF=0;
        if(
Rs_232_Rx_Tx_Flag.Rs_232_Tx_Fg==1)        
            
Rs_232_Tx_Isr ();         // Data received from Modem to be sent to PC
    
}
}

void Rs_232_Tx_Isr (void)
{
    
int i 

                
// 以下的條件式改為 Pc_Output_Ptr < Pc_Output_Code_Cnt
                // 以本程式為例, 發送6個字元時,
                // 應為 [0], [1], [2], [3], [4], [5] 這6個字元
    
if (Pc_Output_Ptr Pc_Output_Code_Cnt 
    {
        
Write2USART(Pc_Output_Buffer[Pc_Output_Ptr]) ;
        
Pc_Output_Ptr += 1;     
    }
    else
    {
        
// TXSTA2bits.TXEN = 0 ; 
                                // 此行消去
                                // 連續發送字元時, 最後一次中斷時,
                                // 還有字元在發送中,
                                // 這時就將發送除能不太好...
                                // 僅將發送中斷除能就好
        
PIE3bits.TX2IE=0;    
        for ( 
0<Pc_Output_Code_Cnti++)        // Pc_Output_Code_Cnt
            
Pc_Output_Buffer[i] = 
                                
// 清除發送資料的部份可以不用做
                                // 稍為節省中斷所佔用的時間
                                // 因為發送個數已被清除了
        
Pc_Output_Ptr 
        
Pc_Output_Code_Cnt 
        
Rs_232_Rx_Tx_Flag.Rs_232_Tx_Fg=0;
    }
}

void SendACKtoPC(void)

發表於: 2007/8/31 16:23
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: [求助]PIC18F662X -- UART傳送問題??? 急~~~
#2
版主
版主


查看用戶資訊
看不出來程式有錯誤,還是要你自己慢慢的 Debug :
1. 利用剩下的 Output 腳,在接收完成與傳送開始的程式做設定I/O輸出 Hi or Low 用示波器看看脽出錯。

2. 善用 ICD2 的中斷設定來除錯。


發表於: 2007/8/31 14:21
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


[求助]PIC18F662X -- UART傳送問題??? 急~~~
#1
高級會員
高級會員


查看用戶資訊
程式部分如下:
當PC連續送資料給MCU, MCU要回ACK(SendACKtoPC)給PC, 當MCU回幾次ACK給PC後(次數不一定), MCU就送不出ACK, 是程式問題嗎??哪裡須修正??
有沒有MCU連續傳送資料的範例程式可參考.

謝謝回覆!!
void SendACKtoPC(void)
{   
    
Pc_Output_Buffer[0] = STX;
    
Pc_Output_Buffer[1] = ACK;
    
Pc_Output_Buffer[2] = MODE;
    
Pc_Output_Buffer[3] = CHECKSUM;
    
Pc_Output_Buffer[4]= 0xDPc_Output_Buffer[5]= 0xA;
    
Pc_Output_Code_Cnt=6;
    
Pc_Output_Ptr 0;
    
Rs_232_Rx_Tx_Flag.Rs_232_Tx_Fg=1;
    
PIE3bits.TX2IE=1;    
    
TXSTA2bits.TXEN 
    
Nop();
    
Nop();
}

#pragma        interrupt    Isr_High
void    Isr_High(void)
{
    if (
PIR3bits.TX2IF==&& PIE3bits.TX2IE==1)
    {
        
Nop();
        
PIR3bits.TX2IF=0;
        if(
Rs_232_Rx_Tx_Flag.Rs_232_Tx_Fg==1)        
            
Rs_232_Tx_Isr ();         // Data received from Modem to be sent to PC
    
}
}

void Rs_232_Tx_Isr (void)
{
    
int i 
    
    if (
Pc_Output_Ptr <= Pc_Output_Code_Cnt 
    {
        
Write2USART(Pc_Output_Buffer[Pc_Output_Ptr]) ;
        
Pc_Output_Ptr += 1;     
    }
    else
    {
        
TXSTA2bits.TXEN 
        
PIE3bits.TX2IE=0;    
        for ( 
0<Pc_Output_Code_Cnti++)        // Pc_Output_Code_Cnt
            
Pc_Output_Buffer[i] = 
        
Pc_Output_Ptr 
        
Pc_Output_Code_Cnt 
        
Rs_232_Rx_Tx_Flag.Rs_232_Tx_Fg=0;
    }
}

發表於: 2007/8/31 11:57
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------