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

baud rate issue

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

baud rate issue
PostPosted: Mon Feb 21, 2011 5:21 pm     Reply with quote

Hi There,

I have two mcus communicating via rs-232 with each other, one is a 18f8722 and the other one a 16f883. In addition, I have hooked the 2nd USART from the 18f controller to my pc and the terminal at 9600 baud.
I get the communication there going nicely but there seems to be a problem with the 16f guy. I have hooked both Rx and Tx up to an oscilloscope and I see that one byte from the 18f takes about 1ms which is right at 9600 baud, the 16f seems to be totally out of sync and way slower. It is hooked up to a 20MHz crystal oscillator and I'm using #FUSES HS> I have also tried XT but there was no change. My #use delay(clock=20000000) is set fine too and I really don't know what the problem is here, any suggestion and hints are appreciated!

Thank you!

Ron
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Feb 21, 2011 8:00 pm     Reply with quote

Are you using a 20MHz crystal (2 pins) or a 20MHz oscillator (3 pins, power, GND & output)? If you are truly using an oscillator you should be able to use your oscilloscope to make sure the frequency is really 20MHz.

How about writing a simple loop that blinks a LED every 10 seconds. Time it with a watch to see if it is close. Use 100 or 1000 seconds to check with more precision.
_________________
The search for better is endless. Instead simply find very good and get the job done.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Mon Feb 21, 2011 10:40 pm     Reply with quote

If you have a scope, program the suspect processor to send out a stream of bytes each containing 0x55. That gives you alternating 1's and 0's, and you can use it to see what the baud rate actually is. If it's inconsistent, you've got an oscillator problem. If it's constant but wrong, you haven't set the baud rate properly.
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 12:35 pm     Reply with quote

Okay, I'm sending 0x55 with a 10ms delay in between and timing seems to be fine. 1 Byte takes 1ms and then it is waiting 9 before it starts with the next one, Zoomed-in, it 1Bit is 100uS wide which should be good as well. Now, I got no rs232 converters in my circuit but the controllers don't understand each other - why would that be? If I'm not using a MAX on either side, it should still work, no? Sad

Thanks for hints!

My test code:
Code:
#include <16F883.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=20000000)

#USE RS232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=MCU2)

void main()
{
  while (true){ 
    fprintf(MCU2,"U");
    delay_ms(10);     
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 1:16 pm     Reply with quote

Post a list of connections between the two PICs.

Is this a Proteus project or is it real hardware ?
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 1:29 pm     Reply with quote

PCM programmer wrote:
Post a list of connections between the two PICs.

Is this a Proteus project or is it real hardware ?


Code:
MCU1: Tx RC6
      Rx RC7

MCU2: Tx RG1
      Rx RG2

Connected via RS232 but not using any line converters


Real hardware.

On one side I'm using the PICDEM PIC18 dev kit from microchip. (MCU2) and on the other side an own little board that's featuring the 16f PIC (MCU1). When MCU2 sends a byte to MCU1, MCU1 would respond with a byte and MCU2 would display the response on the terminal connected to it.
Now what I get, MCU2 is sending a byte, MCU1 is properly responding but MCU2 can't really see anything (other than kbhit() returning true but there's only 0 in the buffer but 0x55 was sent back...). Now I looked at it with the scope and I see that there's a lot of echo(~1V) on MCU2's Rx line when it initially sends stuff out. this is on pins RG 1(Tx)&2(Rx). May this be the reason why kbhit kicks in too early but is not able to actually read anything smart?

And this is what I'm getting:
blue is MCU2 and red MCU1.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 2:03 pm     Reply with quote

Do you have a ground connection between these two boards ? Do you
have C6 connected to G2, and C7 connected to G1 ? That's what you need.

Post the test program for the 18F8722.

Also post your compiler version.
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 2:09 pm     Reply with quote

PCM programmer wrote:
Do you have a ground connection between these two boards ? Do you
have C6 connected to G2, and C7 connected to G1 ? That's what you need.

Post the test program for the 18F8722.

Also post your compiler version.


Yes, Rx and Tx are correct and GND is connected too.
It might be a problem that MCU1 is sending signals at around 3.8V while MCU2 is sending them at 2.8V only... that could lead to a misunderstanding between the two i imagine...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 2:35 pm     Reply with quote

So one PIC has a 5v Vdd and the other PIC is 3.3v ? Yes, that will cause
problems with the logic levels.
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 4:25 pm     Reply with quote

PCM programmer wrote:
So one PIC has a 5v Vdd and the other PIC is 3.3v ? Yes, that will cause
problems with the logic levels.


Yes I think I've figured it out, thanks for the help! Razz
Fighting with different, non electrical issues now... Rolling Eyes
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