CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RS232 is not working with PCD

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

RS232 is not working with PCD
PostPosted: Thu May 03, 2012 5:30 pm     Reply with quote

With PCD version 4.132 and PIC24EP512GU810, RS232 is not working and IOs are OK. See code below:

Code:

#include "24EP512GU810.h"
#fuses PR_PLL, NOIESO, NOWDT
#fuses XT, OSCIO

#use delay(clock=60M)
#pin_select U1TX=PIN_F5
#pin_select U1RX=PIN_F4

#use rs232(baud=9600, xmit=PIN_F5, rcv=PIN_F4,bits=8,parity=N,stop=1,stream = UART1)

void main(void)
{
    int i=0;

    printf("hello!!\r\n");   
    for(;;)
    {
        output_toggle(PIN_A0);
        output_toggle(PIN_A1);
        output_toggle(PIN_A2);
        output_toggle(PIN_A3);
        output_toggle(PIN_A4);
        output_toggle(PIN_A5);
        output_toggle(PIN_A6);
        output_toggle(PIN_A7);
        delay_ms(100);
        fprintf(UART1,"total counter=%d\r\n",i);
    }
    while(1);
}


Please help.
Thanks,
Howard
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri May 04, 2012 1:48 am     Reply with quote

You need to use:
Code:

#include "24EP512GU810.h"
#fuses PR_PLL, NOIESO, NOWDT
#fuses XT, OSCIO

#use delay(clock=60M)
#pin_select U1TX=PIN_F5
#pin_select U1RX=PIN_F4

#use rs232(baud=9600, UART1,bits=8,parity=N,stop=1,stream = UART1)

Basically, you must _not_ put the pin numbers into the #USR RS232 declaration. Just 'UART1', which says 'talk to hardware UART1'. The select lines connect the pins to this UART.

Have you actually tested the system oscillates and is clocking at the right speed?. Two comments:
1) OSCIO - not legal with XT
2) Note2, Fig 9.1.


Best Wishes
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Fri May 04, 2012 10:26 am     Reply with quote

Ttelmah wrote:
You need to use:
Code:

#include "24EP512GU810.h"
#fuses PR_PLL, NOIESO, NOWDT
#fuses XT, OSCIO

#use delay(clock=60M)
#pin_select U1TX=PIN_F5
#pin_select U1RX=PIN_F4

#use rs232(baud=9600, UART1,bits=8,parity=N,stop=1,stream = UART1)

Basically, you must _not_ put the pin numbers into the #USR RS232 declaration. Just 'UART1', which says 'talk to hardware UART1'. The select lines connect the pins to this UART.

Have you actually tested the system oscillates and is clocking at the right speed?. Two comments:
1) OSCIO - not legal with XT
2) Note2, Fig 9.1.


Best Wishes


Ttelmah,

Thanks for the help. I made changes:
#use rs232(baud=9600, bits=8,parity=N,stop=1,stream = UART1)
and removed OSCIO. There is no difference on the result.

Also, I have found out the clock is about 1.76 second instead of 1 second. It is much slower then specified. Do not know why.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri May 04, 2012 2:36 pm     Reply with quote

Start by telling it your oscillator frequency.....

How do you expect the code to know how to generate 60M, when you aren't telling it the crystal frequency?. Key is that it has to know what the XT crystal is running at to calculate the PLL divider. So you need (clock=yyy,crystal=xxx) so the calculation can be done.

Best Wishes
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Fri May 04, 2012 6:41 pm     Reply with quote

Ttelmah wrote:
Start by telling it your oscillator frequency.....

How do you expect the code to know how to generate 60M, when you aren't telling it the crystal frequency?. Key is that it has to know what the XT crystal is running at to calculate the PLL divider. So you need (clock=yyy,crystal=xxx) so the calculation can be done.

Best Wishes


Internal RC was selected:
Code:

#fuses PR,FRC_PLL,NOWDT,ICSP1,NOJTAG
#device ADC=12
#use delay(clock=60M,internal)

It works OK now. Thanks.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group