UART pic to pic in assembly

Thread Starter

ozirock

Joined Jan 13, 2011
47
Hi,

I'm having trouble communicating between two pics, I'm trying to use UART like in the example here.

On PIC 1 I am trying to send data to PIC2 and I use the following routine:

Rich (BB code):
send    	movwf 	TXREG            ; send data in W

TransWt 	bsf 	STATUS,RP0       ; RAM PAGE 1 
WtHere  	btfss 	TXSTA,TRMT       ; (1) transmission is complete if hi 
        	goto 	WtHere

        	bcf 	STATUS,RP0       ; RAM PAGE 0 
        	return
I call this using:

Rich (BB code):
Signal_1	movlw  	'1' 
        	call 	send
		GOTO	Pulse_Check
Then on PIC 2 I try to receive it using the following code:

Rich (BB code):
receive 	btfss 	PIR1,RCIF        ; (5) check for received data 
        	goto 	receive

        	movf 	RCREG,W          ; save received data in W 
        	return
which is called using:

Rich (BB code):
Pulse_Check    	call 	receive
		MOVWF   IN1_S
This is all pretty much from the page with the example so I presume there is no issue there, I think my problem might be when I'm setting the options for the PIC, this is done as follows:

Rich (BB code):
RESET		MOVLW	B'00000111'	;Disable Comparator module's
		MOVWF	CMCON
		;
		
		movlw   b'00000000'     ; set up portA 
		movwf   PORTA
	
		movlw   b'00000100'     ; RB2(TX)=1 others are 0 
        	movwf   PORTB
		
		BSF	STATUS,RP0	;Switch to register bank 1
					;Disable pull-ups
					;INT on rising edge
					;TMR0 to CLKOUT
					;TMR0 Incr low2high trans.
					;Prescaler assign to Timer0
					;Prescaler rate is 1:256												
		MOVLW	B'11010111'	;Set PIC options (See datasheet).
		MOVWF	OPTION_REG	;Write the OPTION register.
					;
		;---Configure peripheral interrupts
		MOVLW 	B'00100000' 	;Disable all peripheral interrupts except receiver
		MOVWF 	PIE1 		;Peripheral interrupt enable/disable
		
		;---Configure general interrupts
		MOVLW 	B'01000000' 	;Disable all interrupts except peripheral
		MOVWF	INTCON 		;Interrupt control register
		
		movlw 	0xFF 
    		movwf 	PR2             ;PWM setting
		
		MOVLW	B'00000010'
		MOVWF	TRISB		;all RB ports are outputs
					
		MOVLW	B'00011100'	;RA2:RA4 ports are inputs, all others are outputs
		MOVWF	TRISA
		
		; ------------------------------------ 
		; SET BAUD RATE TO COMMUNICATE WITH PC 
		; ------------------------------------ 
		; Boot Baud Rate = 9600, No Parity, 1 Stop Bit 
		; 
		movlw 	0x19            ; 0x19=9600 bps (0x0C=19200 bps) 
		movwf 	SPBRG 
		movlw 	b'00100100'     ; brgh = high (2) 
        	movwf	TXSTA           ; enable Async Transmission, set brgh
		
		BCF	STATUS,RP0	;Switch Back to reg. Bank 0
		
		movlw 	b'10010000'     ; enable Async Reception 
        	movwf 	RCSTA 
		
		movlw 	B'00000100'         
		movwf 	T2CON           ;timer 2 on, no prescaler or postscaler 
		movlw 	B'00001111' 
		movwf 	CCP1CON 
		
		MOVF     CCP1CON,W	;set CCP1 as PWM
		ANDLW    0xF0
		IORLW    0x0C
    		MOVWF    CCP1CON
		
		MOVLW    0x7E		;126		;set highest PWM value
		BANKSEL  PR2		;over this (127) is permanently on
		MOVWF    PR2
		BANKSEL  TMR2
		
		MOVF     T2CON,W	;set prescaler to 16
		ANDLW    0xF8		;PWM at 2500HZ
		IORLW    0x02
		MOVWF    T2CON
	
		MOVF     T2CON,W	;set postscaler to 1
		ANDLW    0x07
		IORLW    0x00
    		MOVWF    T2CON
		
		CLRF 	CCPR1L
    		CLRF	PORTB
    		BSF     T2CON, TMR2ON

; 
; ------------------------------------ 
; PROVIDE A SETTLING TIME FOR START UP 
; ------------------------------------ 
; 
        	clrf 	dataL 
settle  	decfsz	dataL,F 
        	goto 	settle

        	movf 	RCREG,W 
        	movf 	RCREG,W 
        	movf	RCREG,W            ; flush receive buffer
I've seen the interrupts discussed on different pages as being a problem and so I tried to set them up myself but I'm not sure if it's done right. Any guidance would be much appreciated.
 

Thread Starter

ozirock

Joined Jan 13, 2011
47
I'll definitely look into getting a few st232 or max232 chips as I keep seeing them popping up all over the place for different applications so it would be good to learn how to interface with them.

I'll disable the interrupts again so and work from there
 

mjhilger

Joined Feb 28, 2011
118
I notice in your send routine, you have no timeout. Is your send routine always returning ? If so you know that your output should be sent. Toggle some unused pin high when you enter the send routine and low on exit. You should be able to view this pin and the serial output pin with a scope to see if it is sending out. Quick check this way (I have read many serial messages using this method in the past). Of course connection to PC or some output device is easier long term diag.
 
Top