Re: dsPIC uart接收問題
|
||||
---|---|---|---|---|
版主
|
眼睛除錯很累人,請參考一下教育訓練光碟下 16-bit 教材裡有一份 "dsPIC30F Module Training" 裡面有一份 dsPIC30F4011 UART 的講解及範例可以參考看看。
http://www.microchip.com.tw/RTC/RTC_DVD/
發表於: 2021/1/20 10:50
|
|||
|
Re: dsPIC uart接收問題
|
||||
---|---|---|---|---|
版主
|
單看程式容易誤判,最簡單的方式就是先用示波器測量一下 UART 的波形及分析所傳述的資料為何?
示波器最重要,資料在上面一目了然。
發表於: 2021/1/19 13:00
|
|||
|
dsPIC uart接收問題
|
||||
---|---|---|---|---|
新會員
|
最近使用dsPIC30f3011這個晶片在做與arduino端傳資料的動作
但不知道是arduino端的問題還是dsPIC這端的問題 PIC這邊都收不到資料,可是URXDA都是為1(datasheet上說為1代表有值) 但U1RXREG都沒有值跑出來 有沒有大神可以幫忙解惑 感激萬分 code如下: uart.c: #include #include #include "uart.h" void InitUART1(void); void InitUART2(void); #define FCY (unsigned long)20000000 //add your operating frequency #define UART1_BAUD 9600 #define UBRG1_VALUE (FCY/UART1_BAUD)/16 - 1 void WriteUART1(unsigned int data) { while (U1STAbits.TRMT==0); if(U1MODEbits.PDSEL == 3) U1TXREG = data; else U1TXREG = data & 0xFF; } void WriteUART1dec2string(unsigned int data) { unsigned char temp; temp=data/1000; WriteUART1(temp+'0'); data=data-temp*1000; temp=data/100; WriteUART1(temp+'0'); data=data-temp*100; temp=data/10; WriteUART1(temp+'0'); data=data-temp*10; WriteUART1(data+'0'); } void WriteStringUART1(const char * s) { while(*s) WriteUART1(*s++); } void InitUART1(void) { U1BRG = UBRG1_VALUE; // baud rate 9600 U1MODEbits.ALTIO=0; //備用的I/O U1MODEbits.STSEL=0; //1-stop bit U1MODEbits.PDSEL=0; //No Parity,8-data bits U1MODEbits.ABAUD=0; //Autobaud Disabled U1MODEbits.USIDL=0; U1STAbits.URXISEL = 3; // Interrupt flag bit is set for every character received. IPC2bits.U1RXIP = 5; // UART1 Receive Interrupt Priority = 4. U1STAbits.OERR = 0; // Clear the Receive Overflow Flag. IFS0bits.U1RXIF = 0; // Clear the UART1 Receive Interrupt flag. //IEC0bits.U1TXIE = 0; IEC0bits.U1RXIE = 1; // enable UART1 Receive Interrupt. U1MODEbits.UARTEN = 1; U1STAbits.UTXEN=1; } main: #include #include #include #include "uart.h" //--------------------------Device Configuration------------------------ _FOSC(CSW_FSCM_OFF & XT_PLL16); _FWDT(WDT_OFF); _FBORPOR(PBOR_ON & BORV_20 & PWRT_64 & MCLR_EN); //---------------------------------------------------------------------- #define FCY 20000000 void DelayNmSec(unsigned int N); char Rxdata; void __attribute__((__interrupt__)) _U1RXInterrupt(void) { IFS0bits.U1RXIF = 0; Rxdata = U1RXREG; } int main(void) { InitUART1(); return; } arduino端: unsigned int Txdata; int x; int y; int z; int w=0; void setup() { Serial3.begin(9600); } void loop() { x=random(100); y=random(100); z=x+y; Txdata=(z&(256-1)); Serial3.write(Txdata); Serial3.println(Txdata); }
發表於: 2021/1/18 15:34
|
|||
|