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.

PIC to PIC Sync communication using USART

Status
Not open for further replies.

gidp

Newbie level 5
Joined
May 20, 2009
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
usart pic

Hello,

I need help in operating the USART, in SYNC mode when PIC 16F870 is used as MASTER and transmit data, to PIC 16F877A that set as SLAVE and received the data. I have set the baud rate to 62.5Mb/s.

When the master send the data via the TXREG, and I’m using delay of 200ms and then sends the next data it works (the slave gets the proper data):
MOVLW ADDRESS ; send the address as LOW byte TX
MOVWF TXREG ;
CALL DELAY_200MS ; call delay 200msec routine

But when I use the status register to test if the TX is completed its not working:
MOVLW ADDRESS ; send the address as LOW byte TX
MOVWF TXREG ;
BTFSS TXSTA,TRMT ; check if tx shift reg is empty
GOTO $-1 ; if not empty continue to check
GOTO NEXTB ; if empty go to send the next byte

My question is why the checking of the status register is not working?
and how can I sync between the master and slave so each time the master sends a byte the slave will received it properly?

Thanks in advanced.
Gideon.

The Master program starts as:

ORG 00H
NOP
GOTO MAIN
ORG 04H ; interrupt entrance address
RETFIE

MAIN
CLRF PORTC
BSF STATUS,RP0 ; select bank1 ;
CLRF TRISC ; set all PORTC as OUTPUT
MOVLW 0x27 ; for 10MHz XTAL set the Baud Rate to 62.5kb/s
MOVWF SPBRG
MOVLW 0xB0 ; Set USRAT TX Status Reg', CSRC bit7=1, TXEN bit5=1, SYNC bit4=1
MOVWF TXSTA ; bit1 TRMT (tx status) 1=empry
BCF STATUS,RP0 ; select bank0

MOVLW 0x80
MOVWF RCSTA ; Set USART RX Status Reg', Serial Port Enable SPEN bit7=1
BSF INTCON,GIE ; enable general interrupt
BSF INTCON,PEIE ; enable outside interrupt
 

pic to pic uart

Hi,

Looking at your code , you would think that it should detect the TRMT bit.
Short of running your code from scratch its hard to see the actual error.

Are you able to use Debugger and actually see the code and registers working ?

Am a little curious why you are running in Sync mode, when Async is much more common.

If you see this tutorial it covers Async, mainly by software but the last example does use the hardware USART - I have used this code and know it works, so it might be of help.
http://www.winpicprog.co.uk/pic_tutorial7.htm
 

usart

Thanks wp100,

I select Sync mode - since its faster and I thought it will be more robust, but I will try the Async mode as you have sugested, mybe its work better.

Thanks again.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top