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

printf with rs232
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kloppy_
Guest







printf with rs232
PostPosted: Wed Jul 28, 2004 5:19 pm     Reply with quote

can anybody tell me why this program only works when i omit the line
printf("received");?

i am using pcm with 3.110

Code:
#include <16F876.h>
#use delay (clock=20000000)
#use RS232 (baud=9600, xmit=pin_c6, rcv=pin_c7,bits=8,parity=n)
#use standard_io(c)
#fuses XT, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP


char input=0;

#int_rda
void serial_isr()
   {
input=getc();
   }


main()
   {
   enable_interrupts(int_rda);
   enable_interrupts(global);
   while (1==1)
      {
        delay_ms(1000);
        printf("%C",input);
        printf("received");
      }
   }
Mad

it also doesnt work if i use
Code:
printf("%c received",input);

instead of
Code:
printf("%C",input);
printf("received");


i am really confused..... Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 5:35 pm     Reply with quote

What do you mean by "doesn't work" ?
Please explain what you expect to see on the terminal window,
and what you actually see.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jul 28, 2004 7:00 pm     Reply with quote

You should use HS instead of XT with 20MHz.
kloppy



Joined: 28 Jul 2004
Posts: 32

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 4:49 am     Reply with quote

doesn't work means i don't get anything back from my PIC (i use hyperterminal on my pc).
i expect that my program echoes what i typed on the keyboard with a "received" after every letter evey second.
everything works fine if i omit the printf("received");.....

(this is just a test-program if the rs232 works)
prach
Guest







example code
PostPosted: Thu Jul 29, 2004 5:51 am     Reply with quote

Code:
       
#include    <16F628A.h>
#use delay (clock=4000000)
#use RS232 (baud=9600, xmit=pin_b2, rcv=pin_b1)
#fuses XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP
#include <input.c>

char input=0;

#int_rda
void serial_isr()
   {
      input=getc();
      printf("%C",input);
      printf("received");
   }


main()
   {
   enable_interrupts(int_rda);
   enable_interrupts(global);
   while(true);
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 11:22 am     Reply with quote

Quote:
Doesn't work means i don't get anything back from my PIC.


What do you mean by "anything" ? Does that mean no characters
at all ? Or, does it mean you're getting the "received" word, but
not the echoed characters ?

I compiled your program for the 16F877 and ran it. I got this:

receivedreceivedareceivedareceivedareceivedareceivedareceivedareceived

Now, your program is not a very good test program, for many reasons.
But the main reason is that you have no spaces inbetween the echoed
character and the word "received", and you have no carriage-return/
linefeed after each character. It's all piled in together.
So in the displayed data above, it just looks like a bunch of "received"
words. But I did, in fact, press the "a" character and it was echoed back.
If I take the string above and put the "a" characters in bold,
then you can see them:

receivedreceivedareceivedareceivedareceivedareceivedareceivedareceived

Do you think that this is actually what's happening ?
valemike
Guest







PostPosted: Thu Jul 29, 2004 1:30 pm     Reply with quote

I couldn't help but notice in your code:

Code:
   while (1==1)


It isn't necessary to write (1==1).

It is sufficient to just write in:

Code:
 while (1)


or

Code:
 for(;;)
Guest








PostPosted: Thu Jul 29, 2004 2:03 pm     Reply with quote

thanks - but these are only details.

i get nothing back from my pic. the terminal window is empty.


you are right it's no a good test program. originally this was a much bigger program which worked perfectly, excluded the rs232 communication. then i startet to delete more and more parts of my program til i found out that the only problem is this printf()!

it is really strange. i often used rs232 with 16f876 a few years ago and i never had a problem.

is it possible that the compiler doesn't work properly?
or maybe a hardware bug?

i also tried another pic with no success...
kloppy



Joined: 28 Jul 2004
Posts: 32

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 2:05 pm     Reply with quote

oops i forgot to log in....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 2:14 pm     Reply with quote

What's your compiler version ?
kloppy



Joined: 28 Jul 2004
Posts: 32

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 2:18 pm     Reply with quote

compiler version 3.110
kloppy



Joined: 28 Jul 2004
Posts: 32

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 2:28 pm     Reply with quote

i've got some news: if i make a hardware mclr, the program sends a naked "received" every second. but as soon as i hit a key, the pic stops to send anything.
that looks like this:
received
received
received
received
received
received
received
received
received



(i added a \r\n)

i thought that looks like the program hangs in the interrupt routine. but as soon as i change the program by omitting the printf("received");, the program works fine!!
the terminal looks like this:

ggggghzufdddddddddddll��hhgggggggtrsyaaa
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 30, 2004 1:02 pm     Reply with quote

I installed PCM vs. 3.110 and compiled your original program.
I got this output:

areceivedareceivedareceivedareceivedareceivedareceived

(It has "a" in front of "received" because I pressed the "a" key).

So there is nothing wrong with vs. 3.110.

I suggest that you do this:

1. Re-install the compiler.

2. Change the fuse setting from XT to HS, since you're using
a 20 MHz crystal.

3. Check your circuit for any floating pins, such as MCLR or Ground pins.

4. Check your settings for Hyperterminal. Do not set it for
"hardware handshaking", or XON/XOFF.

5. Check your settings in Control Panel / System / Device Manager /
Ports / Com1 (or whichever one you're using) / Port Settings /
Advanced. Set the Fifo buffers to the Default mode.

6. Try another PIC chip.
kloppy



Joined: 28 Jul 2004
Posts: 32

View user's profile Send private message

PostPosted: Sat Jul 31, 2004 10:05 am     Reply with quote

most of your suggestions i alreay tried. if the compiler isn't the problem, i think i will check my hardware again....
Ttelmah
Guest







PostPosted: Sat Jul 31, 2004 2:42 pm     Reply with quote

kloppy wrote:
most of your suggestions i alreay tried. if the compiler isn't the problem, i think i will check my hardware again....

Try adding the ERRORS directive to your RS232.
If your PC, is implementing 'echo', then when you type one character, this is sent to the PIC, which then sends back the long string 'received', which would then be echoed back by the PC. At this point, since you are inside the interrupt handler (general comment, don't send characters in the receive interrupt handler, do it outside...), the UART will overflow, the error bit will be set, and the system will hang.
Turning off echo would fix this (but having ERRORS would be worthwhile as well).

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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