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 support@ccsinfo.com

RS232 gibberish

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







RS232 gibberish
PostPosted: Tue Dec 09, 2008 6:25 pm     Reply with quote

I've got another problem related to the PIC communicating with the outside world... except this time I've taken a slightly more antiquated approach and started using RS232.

Really, this is just to help me debug issues with the USB communications, seeing as I'd need an alternate method of getting information from my PIC when I'm busy debugging USB issues. The big problem this time is....

You guessed it, I've never done RS232 before and, once again, despite the sample code and big CCS reference guide... I'm at a loss. My code is as follows:
Code:
#include <18F4550.h>
#use delay(clock=20000000)

//Set up RS232
#use rs232(UART1, baud=9600, xmit=PIN_C6, rcv=PIN_C7)

//Bootloader Stuff
#build(reset = 0x800, interrupt = 0x808)
#org 0x0000, 0x07ff {}

//Main
void main()
{
   while(1){
     printf("\r\nhello world\n");
   }
}

Now, everything I've found seems to tell me that this is an alright program... and when I run it I do, in fact, receive data on the serial port and it does display in the serial monitor... the only problem is...

While my code indicates that it should display "hello world" trailing off into infinity... I get something more along the lines of this:
Quote:
¹2íS2­2­2R­@¹2R­@¹2R­@¹2­@¹2­r­r­r­2­2­2íS2íS2ïS2­2R­2R­@¹2R­@¹2R­@¹2­
2­r­r­r­2­2­S2íS2íS2ïS2­2R­2R­@¹2R­@¹2­@¹2­2­r­r­r­2­2íS2íS2íS2ï2­2R­2
R­@¹2R­@¹2­@¹2­r­r­r­r­2­2íS2íS2ïS2­2­2R­@¹2R­@¹2R­@¹2­2­r­r­r­2­2­2íS
2íS2ïS2­2R­2R­@¹2R­@¹2R­@¹2­2­r­r­r­2­2­S2íS2íS2ï2­2R­2R­@¹2R­@¹2­@¹2­
trailing off into infinity.

Now... is there something obvious I'm missing in my code (as seems to be usual) or is there a setting I'm missing in my serial monitor?

By the way, I'm using the serial monitor integrated into the CCS C compiler, if that makes a difference.

Thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 6:36 pm     Reply with quote

Did you setup Hyperterminal to have the same baudrate, etc., as the PIC ?
Did you connect a MAX232-type chip between the PIC and the PC ?

Your code is missing the #fuses statement. Post it.

Here is a post that describes how to setup Hyperterminal:
http://www.ccsinfo.com/forum/viewtopic.php?t=9253&start=1

Here is the CCS FAQ article on RS-232 problems:
http://www.ccsinfo.com/faq.php?4

Here is a schematic of a MAX232 circuit:
http://web.ukonline.co.uk/j.winpenny/pic/rs232x.gif
Note that if you're using a MAX232A, then you should use 0.1 uF
capacitors, instead of the 1 uF caps.

----
Edit: Fixed link to Hyperterminal thread.
2nd Edit: Fixed link to schematic.


Last edited by PCM programmer on Wed Apr 14, 2010 6:42 pm; edited 2 times in total
Guest








PostPosted: Tue Dec 09, 2008 10:03 pm     Reply with quote

Ummm... Well, first off: I'm using the Microchip PICDEM FS USB Demo Board which has an integrated RS232 port and does indeed have a MAX232 and capacitors already mounted on the board. Also, the Bootloader app that comes along with the demo board automatically inserts its own fuses if what I have might render it inoperable, so I usually just stick with the default board settings. If it would help, I can post what the manual tells me is "default"

Second of all, is it just me or do those two Hyperterminal posts not exist anymore?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 10:28 pm     Reply with quote

You're right. I fixed the link.


Yes, post the fuses used by the bootloader.
MatrixPhreak
Guest







PostPosted: Tue Dec 09, 2008 10:52 pm     Reply with quote

Taken straight from the Users Guide provided on the CD
Quote:
The PIC18F4550 microcontroller for the PICDEM FS USB board has a specific configuration setting that is necessary for the bootload program to function. The USB Voltage Regulator and device oscillator settings are both critical, and cannot be changed. Other settings, such as code protection, WDT and LVP, are less critical but may cause irreversible side effects. The default configuration values are shown in Table3-1.
The configuration data contained in a hex file may violate the restrictions on the critical configuration settings described above. Should this happen, the Demo Tool will display a warning dialog box (Figure3-6). This will also be accompanied by a brief text description of the configuration conflict. Users have the option to accept the new configuration settings, use the board’s factory configuration settings, or maintain the current configuration setting.

Table 3-1 is below:
Code:
0x300000    CONFIG1L    0x24    Clock configuration
0x300001    CONFIG1H    0x0E    Clock configuration
0x300002    CONFIG2L    0x3     FBOR, PWRT, USB voltage regulator
0x300003    CONFIG2H    0x1E    WDT configuration
0x300005    CONFIG3H    0x81    MCLR, CCP2, A/D configuration
0x300006    CONFIG4L    0x81    Core microcontroller configuration
0x300008    CONFIG5L    0x0F    Code protect (program memory)
0x300009    CONFIG5H    0xC0    Code protect (boot block/EEPROM)
0x30000A    CONFIG6L    0x0F    Write protect (program memory)
0x30000B    CONFIG6H    0xA0    Write protect (boot block/EEPROM)
0x30000C    CONFIG7L    0x0F    Table Read protect (program memory)
0x30000D    CONFIG7H    0x40    Table Read protect (boot block/EEPROM)


If any of the fuses I set in the code conflict with those default working fuses, it displays an error box that lets me select to use the default board fuses (above).

I've configured Hyperterminal as per your instructions, as well (thanks, by the way, for correcting the link.) However, when I run the code, siow.exe shows the garbage text but Hyperterminal doesn't.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 10:56 pm     Reply with quote

Are you saying that the output is displayed correctly on Hyperterminal ?
MatrixPhreak
Guest







PostPosted: Tue Dec 09, 2008 11:10 pm     Reply with quote

No... So far, even when siow is showing garbage, Hyperterminal remains blank. Maybe I'm missing a step somewhere, but I'm fairly sure I set it up properly.

I even checked the COM ports. I ran siow through it's available ports, and only COM1 was showing any input, so I set COM1 in Hyperterminal.

I used the sample code you provided on another page (rs232 on 18F4520), but changed the include and clock settings to match my own. I left the fuses the same, but let the bootloader replace the settings with the default. My code now looks like this:
Code:
#include <18F4550.H>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

/*
Bootloader vectors
*/

#build(reset= 0x800, interrupt = 0x808)
#org 0x0000, 0x07ff {}

//========================
void main()
{
int8 c;

printf("Start: \n\r");
 
while(1)
  {
   c = getc();
   putc(c);
  }   

}

The interesting part is, it will correctly echo SOME keypresses. For instance, this is the output (in siow, I still can't get hyperterminal to display). I start the program, and then run through the keyboard row-by-row (starting with q and ending with .) You'll note that most of the output is correct (I've turned off localecho, the display is purely from the PIC now)
Code:
Zr þ
yweztyuùox[]\y{dfghjkl;§zx{vznm,./
(The output doesn't include that line break before the "ywezt" string, I put that in to differentiate between what SHOULD say "Start:" and where it began echoing my input.)
MatrixPhreak
Guest







PostPosted: Tue Dec 09, 2008 11:13 pm     Reply with quote

Scratch that, sorry. Hyperterminal DOES display, now...

But it's the same garbage text as siow. Once again: running that test program and doing the same (q to /, row by row. line break inserted to distinguish)
Code:
Z2 þ
yweztyuiox[]\y{dfghúkl;§zx{vznm,./
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 11:44 pm     Reply with quote

The oscillator Config Bits that you posted are equivalent to:
Code:
#fuses HSPLL, PLL5, CPUDIV1

This means the actual internal clock speed is 48 MHz. Change the
#use delay() statement to reflect this and it should work.


Also, the FS USB board manual says it runs at 48 MHz.
http://ww1.microchip.com/downloads/en/DeviceDoc/51526b.pdf
See this section:
Quote:
1.4.1 Oscillator and Operating Frequency
MatrixPhreak
Guest







PostPosted: Tue Dec 09, 2008 11:52 pm     Reply with quote

Excellent! Thank you so very much! Works like a dream, and I probably never would've figured that out on my own!

Thank you for all your help.
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