dspic30f4013 UART ,Pls give me a hand!

Status
Not open for further replies.

kenny_zhou

Junior Member level 2
Joined
Jan 12, 2007
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
china
Activity points
1,401
fcy pll

hello everyone !please give me a hand!
this is a UART code,when PC sned character to dsPIC30F4013 it is ok,but when the dsPIC30F4013 couldn't send the character"0x41" to the PC,what should i do?Thanks a lot!

#include "p30f4013.h"
#define FCY 14745600
_FOSC(CSW_FSCM_OFF & XT_PLL8);//use a external crystal ,the instruction cycle =1/(FOSC*PLL/4)
_FWDT(WDT_OFF);
_FBORPOR(PBOR_OFF & MCLR_EN);//disable power off pretect,enable MCLR
_FGS(CODE_PROT_OFF);//disable code pretect
void ini232(void);
void __attribute__((__interrupt__)) _U1RXInterrupt(void); /*Declare 232 interrupt ISRs*/
unsigned char rxdata;
int main (void)
{
unsigned char i;
ini232(); /* Call function to initialize the 232 Interrupts */
for(i=32;i!=0;i--); //wait a moment,
while(1)
{
U1TXREG=0x41;
while(U1STAbits.UTXBF);
IFS0bits.U1TXIF=0;
}
}
void ini232(void)
{

TRISFbits.TRISF2 =1;
TRISFbits.TRISF3 =0;
U1BRG =95; //9600 baud rate
IPC2bits.U1RXIP=7;
IEC0bits.U1TXIE=0;
IEC0bits.U1RXIE=1;
U1MODE =0x8020;

U1STAbits.UTXEN =1;

}
void __attribute__((__interrupt__)) _U1RXInterrupt(void)
{
IFS0bits.U1RXIF = 0;
rxdata=(char)U1RXREG;

}
 

dspic30f4013 uart

 

    kenny_zhou

    Points: 2
    Helpful Answer Positive Rating
xtfreq

dear mehdi_an:
Thank you very much!
Now i have find the error , the code is right.the bug is in my PCB.
I confuse the line2 and line4 of the DB9.So MCU can receive data from PC use the lien 3,but could sent data.the data be transmite in the line4,so the PC cann't capture it .
hehe !what a dumpish mistake!
Now you can "cancel" the "help me" flag!
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…