Re: AN1017 速度計算
|
||||
---|---|---|---|---|
新會員
|
非常謝謝您!!!
發表於: 2021/11/23 12:34
|
|||
|
dsPIC30F3011 UART問題
|
||||
---|---|---|---|---|
新會員
|
各位先進好:
小弟目前使用dsPIC30F3011做UART傳輸,在寫入U2TXREG的時候不管怎樣都寫不進去,以下為我的程式碼 #include "uart.h" void InitUART2(void); void WriteUART2(unsigned int data); void WriteUART2dec2string(unsigned int data); void WriteStringUART2(const char * s); #define FCY (unsigned long)20000000 //add your operating frequency #define UART2_BAUD 9600 #define UBRG2_VALUE (FCY/UART2_BAUD)/16 - 1 void InitUART2(void) { U2BRG = UBRG2_VALUE; // baud rate 9600 U2STAbits.URXISEL = 0; // Interrupt flag bit is set for every character received. IPC6bits.U2RXIP = 5; // UART2 Receive Interrupt Priority = 4. U2STAbits.OERR = 0; // Clear the Receive Overflow Flag. IFS1bits.U2RXIF = 0; // Clear the UART2 Receive Interrupt flag. IEC1bits.U2TXIE = 0; IEC1bits.U2RXIE = 1; // Enable UART2 Receive Interrupt. U2MODEbits.UARTEN = 1; // Enable UART2. U2STAbits.UTXEN = 1; // Enable UART2 Transmit. /* U2STA &= 0xfffc; IEC1bits.U2RXIE = 1; // enable RX2 interrupt U2MODEbits.UARTEN = 1; // UARTEN: UART Enable bit U2STAbits.UTXEN = 1; // transmition ON */ } void WriteUART2 (unsigned int data) { U2TXREG = data; while(!U2STAbits.TRMT){} } 從watch去看的時候,data是有值的,但U2TXREG卻都是0,請問各位先進能幫我解答嗎? 謝謝!
發表於: 2021/7/6 17:17
|
|||
|
dsPIC30F3011 RS232共地問題
|
||||
---|---|---|---|---|
新會員
|
目前我用dsPIC30F3011進行馬達速度的PID運算,並以RS232連接Arduino做進一步的控制。
但現在有個問題就是,我dsPIC30F3011是單獨用一個48V去供電,而Arduino是單獨用9V去供電,中間的連接只有RS232。 不知道這樣是不是還需要再做額外的共地? 還是只需要將RS232接上即可? 還有就是因為這樣的電壓插有點大,有需要在Arduino前多裝一個突波電容嗎?
發表於: 2021/7/3 17:15
|
|||
|
Re: dsPIC uart接收問題
|
||||
---|---|---|---|---|
新會員
|
參照:
Ryang您好: 我有用示波器去量測Arduino的傳輸端是有波形的,代表應該Arduino是有傳出去的,可是在dsPIC端的U1RXREG還是沒有收到任何資料。 還有其他可能造成這種情況的原因嗎?
發表於: 2021/1/20 9:18
|
|||
|
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
|
|||
|