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

Problem with Serial(RS232) in PIC24HJ128GP204!

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



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

View user's profile Send private message Visit poster's website

Problem with Serial(RS232) in PIC24HJ128GP204!
PostPosted: Mon Aug 15, 2011 4:25 pm     Reply with quote

Good evening everyone.

I'm having problems with the RS232 in PIC24HJ128GP204.

I can not get anything, much less so to send the serial of the PIC.

Below is a piece of source code.
I appreciate if you could give a help in some way.
Code:

#fuses hs, ec, nooscio, wrtb, nobss, norbs, nowdt, wposts1,  wpres128, windis, noput, icsp1, alti2c, nojtag, nodebug, wrtss, nosss, norss, protect, nocksfsm, noiol1way, noieso 

#use delay(clock=32000000, RESTART_WDT)

#pin_select U1TX = PIN_B10 
#pin_select U1RX = PIN_C9   

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


void main()
   {
   setup_adc_ports (sAN0 | sAN1 | VSS_VDD);
                                                                           
   setup_adc (ADC_CLOCK_DIV_64);         
   set_tris_a(0x7ff);                                                         
   set_tris_b(0x9203);                                                         
   set_tris_c(0x2c0);
    enable_interrupts(INTR_GLOBAL);                                           

loop:
   while(TRUE)
   {
       if (!input(S1))                                                       
       {
              printf("Start\r\n"); 
              or
              fprintf(rs,"Start\r\n");
             
             PIC does not transmit anything!         
        }

.
.
.
.
.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Aug 15, 2011 4:50 pm     Reply with quote

While I don't use that PIC some quick comments...

Always add 'errors' to the use rs232(options...)...

Never use set_tris()..... functions,let the compiler do it automatically for you.There's no need to manually code them and if you get 1 bit wrong...your program will fail...

you may have a wrong fuse selected,check each one,maybe compare to known working code ?

you have interrupts enabled but NO ISRs ! major mistake !! Either disable ALL ISRs or create ISR routines.

hopefully this may help you
hugo_br



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

View user's profile Send private message Visit poster's website

PostPosted: Tue Aug 16, 2011 8:52 am     Reply with quote

I managed to run the serial communication with speeds up to 4800 but if I put values ​​above this speed RS232 sends wrong characters.
I changed the line of fuses and TRIS to work at these speeds and disable interrupts as suggested by temtronic.
I do not know if there's something there, but I will be replacing the 32MHz oscillator with a 40MHz, does that help anything?
I keep waiting for the help everyone.

Good day anda thanks!
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 16, 2011 11:26 am     Reply with quote

Ok..first I'd add a delay in 'main' to space out the printing. right now it's a continous stream of data to, I assume, a PC with some kind of RS232 monitoring program.
Do you have a MAX232 type chip (I'll assume yes, as you say it works < 4800 baud).

Is the PC side a real rs232 comport or a USB dongle ?

Confirm the PC program will run at >4800 baud using a 'loopback' connector.

Proper wiring ( good ground) betwwen the two computers ?

Running out of straws to pull !!
hugo_br



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

View user's profile Send private message Visit poster's website

PostPosted: Wed Aug 17, 2011 8:50 am     Reply with quote

I would like to thank everyone's help.
Problem solved!

Gotta run to 115200 with no problems.
I got it hitting the fuses and routines in the program.
On another board I will work a maximum in 2400, is a hardware limitation.
I isolate the line of communication with photo coupler so that the speed was affected. to maintain good communication went down to 1200, so the line is stable.

Now I need to do a routine to receive complete sentences with the PIC and not just a character. Does anyone have any suggestions for how to start?

Once again I thank everyone's attention.

Hugo.
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