Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

microcontroller serial communication

Status
Not open for further replies.

malik ahsan

Newbie level 5
Joined
Jan 4, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,360
is there any relationship between crystal and baud rate.....i am using 16 MHZ crystal with PIC16F877A and baud rate is 9600.....is it alright or will i have to check the compatibility between these two......i am building communication between PIC16F877A and pc through wireless media(RF transceiver) and baud rate of transceiver is also set to 9600...please guide me where is the problem because i am getting some different characters in matlab....
 

Hi,

Look at the pics datasheet Usart Section and it shows the relationship between baud rate and crystal frequency and the settings you must select.

If you are using the lo cost ASK type of RF boards that do not use any encoding then you will have to use the Manchester coding method otherwise your data will be drowned out by all the other noise/signals the receiver picks up.
 
i think i am helpless.... i have tried to read the data sheet but that is gone over my head.....can you elaborate me some more please....
 

Hi, malik ahsan
is there any relationship between crystal and baud rate

Yes the baud rate is dependent on the crystal frequency. baud rate is set by SPBRG register. On the datasheet it says for 16MHz crystal SPBRG = 25. try to write and read any register value from the corresponding transceiver as a debugging measure just to check if the communication is correct.
One other problem could be the distance between transmitter and receiver. If the distance between transmitter and receiver is very short the RF power from the transmitter antenna may interfere with the electronics of the receiver, corrupting data on the buses.
 

Hi,

To add to YEARs answer,

He is correct but there is another parameter to be considered BRGH which is set in the TXSTA register.

He has used Table 10.3 BRGH = 0

I have always used Table 10.4 BRGH = 1 which means your SPBRG value would be decimal 103 at 16mhz 9600b

Here is a sample of the code I use for 9600b at 4mhz, its in assembler but you should be able to adapt it to the code you are using.

Code:
ser_init	movlw   d'25'               ; 9600 baud @ 4 Mhz Fosc  8 bit Async		
     		movwf   SPBRG				; BRGH=1	
     		movlw   b'00100100'           
     		movwf   TXSTA               ;enable Async Transmission, set brgh=1

     		movlw   b'10010000'
     		movwf   RCSTA               ;enable Async Reception
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top