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

Incorrect Serial Communications

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



Joined: 19 Jan 2006
Posts: 11

View user's profile Send private message

Incorrect Serial Communications
PostPosted: Thu Jan 19, 2006 4:46 pm     Reply with quote

I've written a simple program for a 18F4550 chip. I have a MAX323 chip properly connected for serial communications. When I receive the bytes on the computer, they are incorrect. I've sent the following:
0xfc
0xfd
0xfe
0xff

then recieve
F8
FB
FC
FF

When I reverse the order, I get the same output but reversed. Using prinf("Hello World") also sends an incorrect string(this is why Im sending the hex values). I've tried 2 pics and replaced an old max232 with a brand new one. I've double checked all connections. I've also used the correct port settings on each side.

Here is my code


Code:
#include <18F4550.h>
#include <ctype.h>

//#fuses HS,WDT128,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
//#build(reset=0x1, interrupt=0x5) // Necessary for Bootloader
#org 0x082a,0x7fff // Necessary for Bootloader
//#opt 9

void main()   {
   set_tris_d(0);   // port c as output;
   set_tris_b(0xff);   // port b as uinput;
   //output_high(PIN_D0);
   //output_high(PIN_D1);   
   output_d(0xff);

   delay_ms(20);
   //printf("Hello World\n\r");

putc(0xfc);
putc(0xfd);
putc(0xfe);
putc(0xff);



//putc('A');
   while(true){
      if(input(PIN_B0)){
         output_high(PIN_D0);
      }else{
         output_low(PIN_D0);
         //printf("Test\n\r");
      }

   }
 
}


Thanks,

Matt
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jan 19, 2006 7:03 pm     Reply with quote

Interesting. You appear to be losing the most significant bit. Is the device the PIC is talking to a PC? If so are you sure you have configured it for 8 data bits, 1 stop bit and no parity?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
mat72



Joined: 19 Jan 2006
Posts: 11

View user's profile Send private message

PostPosted: Thu Jan 19, 2006 9:01 pm     Reply with quote

asmallri wrote:
Interesting. You appear to be losing the most significant bit. Is the device the PIC is talking to a PC? If so are you sure you have configured it for 8 data bits, 1 stop bit and no parity?


Yep... All of the above.

Matt
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 19, 2006 9:22 pm     Reply with quote

Your program is way too complicated to debug this problem. You should
use a much more simple program, such as the one shown below.
This program will send "UUUUUUUU" to the terminal program.

If you have an oscilloscope, measure the duration of one bit,
as sent out by the program below.
Code:
#include <18F452.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//==============================

void main()
{

while(1)
  {
   putc(0x55);
   delay_ms(1);
  }

}
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jan 19, 2006 9:33 pm     Reply with quote

If the serial format is correct then there is a mismatch between the bit clocks of the PC and the PIC. Because the data is close to being correct, if it had been a PIC18F452 type processor, I would have suggested checking you have a correctly loaded crystal.

The PIC you are using has a far more complex clocking system and this is where I think your problem lies. Because you are using a bootloader I suggest looking at the fuses configured for the bootloader and the loading of the crystal.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
mat72



Joined: 19 Jan 2006
Posts: 11

View user's profile Send private message

PostPosted: Fri Jan 20, 2006 3:08 pm     Reply with quote

asmallri wrote:
If the serial format is correct then there is a mismatch between the bit clocks of the PC and the PIC. Because the data is close to being correct, if it had been a PIC18F452 type processor, I would have suggested checking you have a correctly loaded crystal.

The PIC you are using has a far more complex clocking system and this is where I think your problem lies. Because you are using a bootloader I suggest looking at the fuses configured for the bootloader and the loading of the crystal.


I have a 20 Mhz Crystal. I'm not using the boot loader anymore. here are my Configuration bits

Clock src from 96Mhz PLL/2
[OSC1/OSC2 Src: /4] [96Mhz PLL Src: /6]
Divide by 5 (20Mhz input)
HS: HS+PLL, USB-HS

Thanks,

Matt
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Fri Jan 20, 2006 3:31 pm     Reply with quote

Is there a common ground for the PC and the PIC board? Try that.
mat72



Joined: 19 Jan 2006
Posts: 11

View user's profile Send private message

PostPosted: Fri Jan 20, 2006 3:59 pm     Reply with quote

yep
Eugeneo



Joined: 30 Aug 2005
Posts: 155
Location: Calgary, AB

View user's profile Send private message

PostPosted: Fri Jan 20, 2006 9:01 pm     Reply with quote

pulse a pin using the delay command and check it on the scope.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Jan 21, 2006 1:16 am     Reply with quote

mat72 wrote:
asmallri wrote:
If the serial format is correct then there is a mismatch between the bit clocks of the PC and the PIC. Because the data is close to being correct, if it had been a PIC18F452 type processor, I would have suggested checking you have a correctly loaded crystal.

The PIC you are using has a far more complex clocking system and this is where I think your problem lies. Because you are using a bootloader I suggest looking at the fuses configured for the bootloader and the loading of the crystal.


I have a 20 Mhz Crystal. I'm not using the boot loader anymore. here are my Configuration bits

Clock src from 96Mhz PLL/2
[OSC1/OSC2 Src: /4] [96Mhz PLL Src: /6]
Divide by 5 (20Mhz input)
HS: HS+PLL, USB-HS

Thanks,

Matt


Post the actual code for setting the fuses and the clock. I think the problem is the clock configuration.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah
Guest







PostPosted: Sat Jan 21, 2006 4:20 am     Reply with quote

Looking at this, it sounds like master clock=20MHz. /5, to give 4Mhz for USBPLL. PLL gives 96MHz then using /6, gives a processor clock of 16Mhz, not 20MHz. The fact that /6 is mentioned, suggests this may be what is happening.

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