Reply by Paul Carpenter December 11, 20082008-12-11
In article <S_qdnZi_vNpGDN3UnZ2dnUVZ_umdnZ2d@giganews.com>,=20
zhengjun_10@hotmail.com says...
> Hi all,=20 >=20 > I am using dspic30f6010a interfacing pc with rs232.=20 > when I use hyperterminal, I can only receive something like > <<x<<||||||=C3?=C3?=C3?=C3?. why is that? And how can I send signal from > hyperterminal.=20
For a whole host of reasons ranging from you have set the wrong baud rate in Hyperterminal to the code is not doing what you think it should be doing. If you cannot work out how to send a signal from Hyperterminal try hitting the keyboard with your head.
> when I use matlab, the program automatically terminates when I write: > s=3Dserial('com1','BaudRate',9600); fopen(s)=20 > why is that?=20
No idea try looking in the Matlab manuals/help.
> The pic program is as follow, anyone can help?=20 >=20 > #define PLLODE 1=20 > #define FCY XTFREQ*PLLODE=20 > #define BAUDRATE 9600=20 > #define BRGVAL ((FCY/BAUDRATE)/16)-1=20
As you have not said what your actual crystal frequency and the define XTFREQ are, who knows?
> char Buf[80];=20 > char * Receiveddata =3D Buf;=20 > void initU1(void)=20 > {=20 > U1BRG =3D BRGVAL; // initialize the baud rate generator=20 > U1MODE =3D 0x8400; // ENable, 8data, no parity, 1 stop=20 > U1STA =3D 0x0440; // enable the Transmitter=20
Does the receiver need enabling or are your comments wrong.
> } //initU2=20
Bad comment style starts as 'initU1' end comment says 'initU2'
>=20 > //This is UART1 transmit ISR=20
This function may never be called as your appear never to set interupt enables. Not that it does anything useful.
> void __attribute__((__interrupt__)) _U1TXInterrupt(void)=20 > {=20 > IFS0bits.U1TXIF =3D 0;=20 > }=20 > //This is UART1 receive ISR=20
This function may never be called as your appear never to set interupt enables. Not that it does anything useful.
> void __attribute__((__interrupt__)) _U1RXInterrupt(void) /*Declare 232 > interrupt ISRs*/=20 > {=20 > IFS0bits.U1RXIF =3D 0;=20 > //read the receive buffer till atleast one or more character can be read=
=20
> while (U1STAbits.URXDA)=20 > {=20 > ( *(Receiveddata)++) =3D U1RXREG;=20
Why read the data in TWO places??
> }=20 > }=20 > int main (void)=20 > {=20 > // Datta to be transmitted=20 > char Txdata[] =3D {'M','i','c','r','o','c','h','i','p'};=20 > initU1();/* Call function to initialize */=20 > while(1)=20 > {=20 > while( U1STAbits.UTXBF); // wait while Tx buffer full=20 > U1TXREG =3D (unsigned int *)Txdata;=20
So from reset you dump ALL of memory or nothing depending on a register=20 bit, if interupts are enabled this could do either stop after first=20 character, or after NO charcters depending on how you have enabled=20 interupts.
> while(U1STAbits.TRMT)=20 > ( *(Receiveddata)++) =3D U1RXREG;=20
Once we have stopped transmitting receive character depending on the setting of a bit, but receive data into ALL of memory writing over=20 ALL memory or stopping forever from receiving everything. All depends on your interupt enabling scheme not shown or commented.
> }=20 > }=20
This looks like poorly thought out homework answer. Have you even got a program on your dsPIC to flash an LED yet? --=20 Paul Carpenter | paul@pcserviceselectronics.co.uk <http://www.pcserviceselectronics.co.uk/> PC Services <http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font <http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny <http://www.badweb.org.uk/> For those web sites you hate
Reply by zheng December 11, 20082008-12-11
Hi all, 

I am using dspic30f6010a interfacing pc with rs232. 
when I use hyperterminal, I can only receive something like
<<x<<||||||&uuml;&uuml;&uuml;&uuml;. why is that? And how can I send signal from
hyperterminal. 
when I use matlab, the program automatically terminates when I write:
s=serial('com1','BaudRate',9600); fopen(s) 
why is that? 
The pic program is as follow, anyone can help? 

#define PLLODE 1 
#define FCY XTFREQ*PLLODE 
#define BAUDRATE 9600 
#define BRGVAL ((FCY/BAUDRATE)/16)-1 
char Buf[80]; 
char * Receiveddata = Buf; 
void initU1(void) 
{ 
    U1BRG  = BRGVAL;        // initialize the baud rate generator 
    U1MODE = 0x8400;      // ENable, 8data, no parity, 1 stop 
    U1STA  = 0x0440;     // enable the Transmitter 
} //initU2 

//This is UART1 transmit ISR 
void __attribute__((__interrupt__)) _U1TXInterrupt(void) 
{ 
IFS0bits.U1TXIF = 0; 
} 
//This is UART1 receive ISR 
void __attribute__((__interrupt__)) _U1RXInterrupt(void) /*Declare 232
interrupt ISRs*/ 
{ 
   IFS0bits.U1RXIF = 0; 
//read the receive buffer till atleast one or more character can be read 
while (U1STAbits.URXDA) 
{ 
 ( *(Receiveddata)++) = U1RXREG; 
} 
} 
int main (void) 
{ 
// Datta to be transmitted 
char Txdata[] = {'M','i','c','r','o','c','h','i','p'}; 
initU1();/* Call function to initialize */ 
while(1) 
{ 
     while( U1STAbits.UTXBF);  // wait while Tx buffer full 
        U1TXREG = (unsigned int *)Txdata; 
  while(U1STAbits.TRMT) 
        ( *(Receiveddata)++) = U1RXREG; 
   } 
}