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

putc problems with rs232 and motor controller pololu

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








putc problems with rs232 and motor controller pololu
PostPosted: Sun Nov 25, 2007 4:35 pm     Reply with quote

hi
i need to send through rs232 7 bytes in order to configure the Pololu motor controller (motor name, speed, back n forth direction). I used putc function to do this and analizing the streamdata with hyperterminal i only saw 4 of 7 bytes i needed. I use a 18f452 pic rs232 set at 9200 baudrate. How can i solve this situation that is making me mad? Thanks in advance. Gabriele from italy.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 5:00 pm     Reply with quote

Quote:
I use a 18f452 pic rs232 set at 9200 baudrate

The Pololu controller doesn't support 9200 baud. It supports 9600 baud
or 19200 baud (and other rates). See this link:
http://www.pololu.com/products/pololu/0101/#dvcspecs
Try using the correct baud rate.

If it doesn't work, then post a very small test program. Show all of
#include, #fuses, and #use delay() statements.
trustno1



Joined: 25 Nov 2007
Posts: 4

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 2:44 am     Reply with quote

Thanks for your reply.

Quote:
The Pololu controller doesn't support 9200 baud. It supports 9600 baud
or 19200 baud (and other rates)


I mean 9600...and i've tried 19200 too, no result.

The code is:

Code:
#include <18F452.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8)


void main(){

output_high(PIN_B2); //reset
delay_ms(100);
putc(128); //init
putc(2); //fixed
putc(65);//configuration bits
delay_ms(100);
output_low(PIN_B2); //pin reset
delay_ms(500);
output_high(PIN_B2); //pin reset
delay_ms(100);
putc(128); //init
putc(0); //fixed
putc(3); //1 motor, back or forth direction
putc(127); //speed
}


In hyperterminal i see only the first 4 "putc".
i used this code too with same fuses:

Code:
putc('a');
putc('b');
putc('c');
putc('d');
putc('e');
putc('f');
putc('g');
putc('h');


in hyperterminal i see: "abcdef", but "g" and "h"?
Thanks,
Gabriele.
Ttelmah
Guest







PostPosted: Mon Nov 26, 2007 2:57 am     Reply with quote

You won't....
The key is to remember that there is nowhere for code to 'go', if you let the program 'drop off the end'. Tis is different from a program in a PC, where there is an underlying 'operating system', which has called the program. Hence programs on the PIC, need to remain alive. So you will see things like:
Code:

void main(void) {
   //Code here


  while(TRUE) ;
}

Where the 'while', is there to prevent the code dropping off the end.

What is happening to your code, is that the bytes are loaded into the output register of the PIC (which provides a total of two characters of buffering), and then the chip drops off the end of the code, and goes to sleep, preventing the last two characters from ever being sent...

Best Wishes
trustno1



Joined: 25 Nov 2007
Posts: 4

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 3:27 am     Reply with quote

Great, it works!!!

Thank you very much. I hope this can help others too!

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