![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
theweasel Guest
|
RS232 printf issue with receive enabled PIC16F690 |
Posted: Tue Dec 01, 2009 3:13 pm |
|
|
I'm having an issue getting printf statements to print when I have the receive pin enabled (B5) for the PIC16F690. The putc and getc commands work fine. Example code below:
Code: | #include <16F690.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOMCLR,NOBROWNOUT,NOIESO,NOFCMEN
#use delay(clock=4000000)
#use RS232(Baud=38400,XMIT=PIN_B7,RCV=PIN_B5)
char input;
void main(void){
printf("\n\rHello World!\n\r");
putc('A');
input = getc();
putc(input);
printf("\n\rI read a %c\n\r", input);
} |
If I type a "1" from TeraTerm for the getc command, I will see this output:
A11
(Local echo is on, hence the subsequent "1"). Note the "Hello World!" did not print. If I change the RCV pin to an unconnected pin, say C6 as in the following example:
Code: | #include <16F690.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOMCLR,NOBROWNOUT,NOIESO,NOFCMEN
#use delay(clock=4000000)
#use RS232(Baud=38400,XMIT=PIN_B7,RCV=PIN_C6)
char input;
void main(void){
printf("\n\rHello World!\n\r");
putc('A');
input = getc();
putc(input);
printf("\n\rI read a %c\n\r", input);
} |
I get the following output:
Hello World!
A
Success! But, when I modify the hardware to connect RX to C6, it does not recognize my inputs from TeraTerm so the code hangs on getc().
Any thoughts on this? I'd prefer to get the printf's working with RX as B5, but if I can get this working with another RX pin, I'm cool with that.
Thanks in advance for your help. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 01, 2009 3:21 pm |
|
|
1. Post your compiler version.
2. Also, are you using a board with a Max232-type chip on it ?
Did you buy the board or build it yourself ? If you bought it,
post the manufacturer and model number. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Dec 01, 2009 3:34 pm |
|
|
Hi,
Maybe some Rx errors makes the UART hang?
Try this:
#use RS232(Baud=38400,XMIT=PIN_B7,RCV=PIN_B5, ERRORS)
I'm doing 115.200 on the hardware UART in F690 + additional sending in 19.200 on software UART at 4MHz.
Good luck!
/BdeB |
|
![](templates/subSilver/images/spacer.gif) |
theweasel Guest
|
RS232 printf issue with receive enabled PIC16F690 |
Posted: Tue Dec 01, 2009 8:16 pm |
|
|
Hi. Thanks for your suggestions.
1. Compiler version is 4.037
2. I'm using a MAX232 logic translator and I'm confident in the hardware. I've used this board before for serial RX/ TX without issue. Moreover, the system works fine when I use putc/ getc... only printf doesn't work. If I remove the RCV pin in SW or change the pin in SW, I can printf all day.
3. I tried adding "errors" declaration in #use RS232, but, it does not affect the behavior... still no printf statements.
Any other ideas? |
|
![](templates/subSilver/images/spacer.gif) |
the_weasel Guest
|
|
Posted: Wed Dec 02, 2009 2:46 pm |
|
|
Looks like this is an issue with version 4.037. See topic 81053 on these forums. (I can't post the link because I'm a guest and I'm still waiting for my registration confirmation email).
Any work around for this bug? This is the first project I've required bidirectional RS232, so I've never encountered this. |
|
![](templates/subSilver/images/spacer.gif) |
the_weasel Guest
|
|
Posted: Wed Dec 02, 2009 2:58 pm |
|
|
Confirmed. Here is the version history update from version 4.038:
4.038 An RS232 problem for some configurations (since 4.037) is fixed
Can I make this work with 4.037? |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Dec 02, 2009 3:19 pm |
|
|
This is your first project with the CCS compiler, but you are using an 2.5 years old version (May-2007)?
It has been posted many times before on this forum, but the first releases of the new v4 compiler were terrible and contained so many bugs that CCS should have released them with a huge 'alfa release' message.
Starting around v4.070 the compiler became 'usable' and v4.099 is stable (I'm not sure about v4.100 and v4.101, these are reported to have introduced a few new bugs).
Maybe you can get your project working in v4.037 but with every problem you'll wonder if it is you or the compiler. Best to do an upgrade. |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Wed Dec 02, 2009 3:34 pm |
|
|
It's likely a bootleg copy of 4.037 from a guy posting under the name Red Alert. The same site also seems to have a few folks fussing about the license files being out of date. To get around this they also posted a bootleg copy of 3.249.
That's why there are so many questions about the older versions popping up.
I wonder if CCS knows about this site? _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
the_weasel Guest
|
|
Posted: Wed Dec 02, 2009 4:03 pm |
|
|
Thanks for the encouragement. I'd be happy to provide the invoice for my registered copy of the PCM compiler. I've used this version since May 2007, just never run into this issue because I've never made use of the rcv pin (with xmit only, there is no issue).
Now that we've determined I'm not a bootlegger, I'd be happy to get some constructive feedback. |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Wed Dec 02, 2009 4:16 pm |
|
|
My sincere apologies.
As you can imagine this is an ongoing problem for CCS (and the other compiler companies as well). We see a fair amount of it on this board.
I have 4.037 in my archives at home but unfortunately I don't have a 690 to test on. I bet someone here probably has.
When I get home from work I will look into it (if someone hasn't beaten me to it). Unless it's related to a hardware errata I feel sure some kind of workaround can be cooked up. _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 02, 2009 4:55 pm |
|
|
I've looked at the problem and the reason is because printf doesn't work
properly with the hardware UART in your version. It doesn't write to
the UART's transmit register.
The work-around is to add your own "my_putc()" routine (which calls
putc) and use the re-direction feature of printf to call that routine.
Then it works. I tested this in hardware with vs. 4.037. Add the code
shown in bold below.
Quote: |
#include <16F690.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,MCLR,BROWNOUT
#use delay(clock=4000000)
#use RS232(Baud=9600,XMIT=PIN_B7,RCV=PIN_B5)
char input;
void my_putc(char c)
{
putc(c);
}
void main(void)
{
printf(my_putc, "\n\rHello World!\n\r");
putc('A');
input = getc();
putc(input);
printf(my_putc, "\n\rI read a %c\n\r", input);
while(1);
} |
Also note that I've added a while(1) statement at the end of main().
This prevents the PIC from executing the hidden sleep instruction
that CCS places at the end of main(). If it executes this instruction,
the last two chars sent to the hardware UART will not be displayed,
because the PIC will go to sleep while they are still in progress of
being transmitted or in the queue to be transmitted. |
|
![](templates/subSilver/images/spacer.gif) |
the_weasel Guest
|
|
Posted: Wed Dec 02, 2009 6:08 pm |
|
|
PCMprogrammer,
You are a god amongst men. That did the trick. I'm golden. Thanks for your support. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|