I am trying to transmit and receive data over serial communication 'wireless-ly' using 2 Xbee modules (Zigbee series 2 , Znet-2.5 ver. 2mW).
First i tried to do the loop back test which was successful.
>End A: I connected one Xbee on its usb explorer board with PC, picking it up on X-CTU software.
>End B: I step up the other on bread board, by applying power and ground to it and shorted the Dout and Din using a wire.
-Loop back successful
Now when i tried to involve a microcontroller (Pic18F4550) at End B which takes in data received from Dout and simple instructions put it back to transmit it to Din.
So that its still Loop back (for a single byte) From End A to End B - ucontroller - End B - End A
I sent byte at a time.. but i get junk to what i transmit from End A. Even though i transmit only a single byte from End A but i sometimes get 2 or 3 bytes in return.
And all junk (for example sending ASCII 'A' get back hex FF,FB,F4)
So changed End A to another mircontroller setup (basic connections as in picture) and connected 2 LED bars on End A to see what was sent and what i received.
On End B i added a LCD to see what it received.
I first connect both serial connections with wire to check if both programs were working .. and they are .. no problem when both end connected with wires directly to each other.
but when i connect Xbee on both controllers (on their serial port as in picture), nothing happened. no transmission at all.
End-A
End-B
Can some one tell me what am i doing wrong. I have also attach the config pics of boht Xbee modules.
First i tried to do the loop back test which was successful.
>End A: I connected one Xbee on its usb explorer board with PC, picking it up on X-CTU software.
>End B: I step up the other on bread board, by applying power and ground to it and shorted the Dout and Din using a wire.
-Loop back successful
Now when i tried to involve a microcontroller (Pic18F4550) at End B which takes in data received from Dout and simple instructions put it back to transmit it to Din.
So that its still Loop back (for a single byte) From End A to End B - ucontroller - End B - End A
I sent byte at a time.. but i get junk to what i transmit from End A. Even though i transmit only a single byte from End A but i sometimes get 2 or 3 bytes in return.
And all junk (for example sending ASCII 'A' get back hex FF,FB,F4)
So changed End A to another mircontroller setup (basic connections as in picture) and connected 2 LED bars on End A to see what was sent and what i received.
On End B i added a LCD to see what it received.
I first connect both serial connections with wire to check if both programs were working .. and they are .. no problem when both end connected with wires directly to each other.
but when i connect Xbee on both controllers (on their serial port as in picture), nothing happened. no transmission at all.
End-A
Code:
list p=18f4550
#include p18f4550.inc
config FOSC=HS
; config FOSCS=off
config wdt=off
config pwrt=on
;=====================================================
; constant definitions
;=====================================================
;=====================================================
; PIC register equates(in boot start from 0x7D0)
R1 EQU 0x7D1
R2 EQU 0x7D2
R3 EQU 0x7D3
R4 EQU 0x7D4
CNT EQU 0x7D5
TEMP1 EQU 0x7D6
TEMP2 EQU 0x7D7
D_CNT EQU 0x7D8
;=====================================================
;=====================================================
; variables in PIC RAM
;=====================================================
;cblock 0x0c
;endc
;============================================================
; program
;============================================================
;============================================================
; program
;============================================================
org 0x800 ; start at address
goto MAIN
; Space for interrupt handler, change interupt address for other processor
org 0x0808
MAIN
CALL SETUP_DELAY
MOVLW 0x0F
MOVWF ADCON1
CLRF TRISB
CLRF PORTB
CLRF TRISD
CLRF PORTD
CALL DELAY1s
CALL SERIAL_INIT
START_OVER
CALL SET_MSG
MOVLW D'13'
MOVWF CNT
CLRF TEMP1
CLRF TEMP2
REPEAT
CALL READ_MSG
CALL T_X
CALL SEND2PORTB
CALL DELAY1s
CALL R_X
CALL SEND2PORTD
CALL DELAY1s
DECF CNT,F
BNZ REPEAT
BRA START_OVER
ENDD BRA ENDD
SERIAL_INIT
MOVLW B'00100000'
MOVWF TXSTA
MOVLW B'00010000'
MOVWF RCSTA
MOVLW B'00000000'
MOVWF BAUDCON
CLRF TXREG
CLRF RCREG
BCF TRISC,TX
BSF TRISC,RX
MOVLW D'31'
MOVWF SPBRG ;set serial baud 31->9.6kbps
BSF RCSTA,SPEN ;start serial baud
RETURN
SEND2PORTB
MOVFF TEMP1,PORTB
RETURN
SEND2PORTD
MOVFF TEMP2,PORTD
RETURN
;rx call-----------------
R_X
S1 BTFSS PIR1,RCIF
BRA S1
MOVFF RCREG,TEMP2
RETURN
;tx call-----------------
T_X
S2 BTFSS PIR1,TXIF
BRA S2
MOVFF TEMP1,TXREG
RETURN
SET_MSG
CLRF TABLAT
MOVLW high(MSG1)
MOVWF TBLPTRH
MOVLW low(MSG1)
MOVWF TBLPTRL
RETURN
READ_MSG
TBLRD*+
MOVFF TABLAT,TEMP1
RETURN
SETUP_DELAY;------------to be called atleast once to make delays workable
MOVLW 0x08
MOVWF T0CON ;Timer 0 ;16-bit; internal clock; no prescale
RETURN
DELAY1s
MOVLW D'100'
MOVWF D_CNT
D1s CALL DELAY10ms
DECF D_CNT,F
BNZ D1s
RETURN
DELAY100ms
MOVLW D'10'
MOVWF D_CNT
D100ms CALL DELAY10ms
DECF D_CNT,F
BNZ D100ms
RETURN
DELAY10ms
MOVLW 0x3C
MOVWF TMR0H
MOVLW 0xB0
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0A BTFSS INTCON, TMR0IF
BRA TM0A
BSF T0CON,TMR0ON
RETURN
DELAY1ms
MOVLW 0xEC
MOVWF TMR0H
MOVLW 0x78
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0B BTFSS INTCON, TMR0IF
BRA TM0B
BSF T0CON,TMR0ON
RETURN
DELAY100us
MOVLW 0xFE
MOVWF TMR0H
MOVLW 0x0C
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0C BTFSS INTCON, TMR0IF
BRA TM0C
BSF T0CON,TMR0ON
RETURN
DELAY10us
MOVLW 0xFF
MOVWF TMR0H
MOVLW 0xCE
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0D BTFSS INTCON, TMR0IF
BRA TM0D
BSF T0CON,TMR0ON
RETURN
DELAY1us
MOVLW 0xFF
MOVWF TMR0H
MOVLW 0xFB
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0E BTFSS INTCON, TMR0IF
BRA TM0E
BSF T0CON,TMR0ON
RETURN
;messages------------------------
MSG1 DB 0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,"HELLO",0
;============================================================
end ; END OF PROGRAM
;============================================================
End-B
Code:
list p=18f4550
#include p18f4550.inc
config FOSC=HS
; config FOSCS=off
config wdt=off
config pwrt=on
;=====================================================
; constant definitions
;=====================================================
;=====================================================
; PIC register equates(in boot start from 0x7D0)
R1 EQU 0x7D1
R2 EQU 0x7D2
R3 EQU 0x7D3
R4 EQU 0x7D4
CNT EQU 0x7D5
TEMP EQU 0x7D6
D_CNT EQU 0x7D7
;=====================================================
LCD_DATA EQU PORTD
LCD_CTRL EQU PORTB
RS EQU RB0
RW EQU RB1
EN EQU RB2
;=====================================================
; variables in PIC RAM
;=====================================================
;cblock 0x0c
;endc
;============================================================
; program
;============================================================
;============================================================
; program
;============================================================
org 0x800 ; start at address
goto MAIN
; Space for interrupt handler, change interupt address for other processor
org 0x0808
MAIN
CALL SETUP_DELAY
MOVLW 0x0F
MOVWF ADCON1 ;---making portApins[0,1,2,3], portBpins[0,1,2,3,4] and portEpins[0,1,2] as digital I/Os
CALL SERIAL_INIT
CALL LCD_INIT
CALL CLR_LCD
CALL CURSOR_SHFT
AGAIN
MOVLW D'15'
MOVWF CNT
CLRF TEMP
CALL CLR_LCD
CALL CURSOR_SHFT
MOVLW 0x80
CALL POS_CURSOR
REPEAT
CALL R_X
CALL DISPLAY_DATA
CALL DELAY1s
CALL T_X
CALL DELAY1s
DECF CNT,F
BNZ REPEAT
BRA AGAIN
ENDD BRA ENDD
SERIAL_INIT
MOVLW B'00100000'
MOVWF TXSTA
MOVLW B'00010000'
MOVWF RCSTA
MOVLW B'00000000'
MOVWF BAUDCON
CLRF TXREG
CLRF RCREG
BCF TRISC,TX
BSF TRISC,RX
MOVLW D'31'
MOVWF SPBRG ;set serial baud 31->9.6kbps
BSF RCSTA,SPEN ;start serial baud
RETURN
;rx call-----------------
R_X
S1 BTFSS PIR1,RCIF
BRA S1
MOVFF RCREG,TEMP
RETURN
;tx call-----------------
T_X
S2 BTFSS PIR1,TXIF
BRA S2
MOVFF TEMP,TXREG
RETURN
LCD_INIT
CLRF TRISD
CLRF TRISB
CLRF PORTD
CLRF PORTB
BCF LCD_CTRL,EN
CALL DELAY1ms
MOVLW 0x38
CALL COMNWRT
CALL DELAY1ms
MOVLW 0x0E
CALL COMNWRT
CALL DELAY1ms
RETURN
CLR_LCD
MOVLW 0x01
CALL COMNWRT
CALL DELAY1ms
RETURN
;shift cursor to right that is shift/increment cursor positon towards right (0x04 for left)
CURSOR_SHFT
MOVLW 0x06
CALL COMNWRT
CALL DELAY1ms
RETURN
;move cursor to specific position on specific line
;line 1 0x80 and position 81,82,83...93
;line 2 0xC0 and position C1,C2,C3...D3
POS_CURSOR
CALL COMNWRT
CALL DELAY1ms
RETURN
;read from message character by character
SET_MSG
CLRF TABLAT
MOVLW high(MSG1)
MOVWF TBLPTRH
MOVLW low(MSG1)
MOVWF TBLPTRL
RETURN
;send display data to LCD
DISPLAY_DATA
CALL DATAWRT
CALL DELAY1ms
RETURN
COMNWRT
MOVWF LCD_DATA
BCF LCD_CTRL,RS
BCF LCD_CTRL,RW
BSF LCD_CTRL,EN
CALL DELAY1ms
BCF LCD_CTRL,EN
RETURN
DATAWRT
MOVFF TEMP,LCD_DATA
BSF LCD_CTRL,RS
BCF LCD_CTRL,RW
BSF LCD_CTRL,EN
CALL DELAY1ms
BCF LCD_CTRL,EN
RETURN
SETUP_DELAY;------------to be called atleast once to make delays workable
MOVLW 0x08
MOVWF T0CON ;Timer 0 ;16-bit; internal clock; no prescale
RETURN
DELAY1s
MOVLW D'100'
MOVWF D_CNT
D1s CALL DELAY10ms
DECF D_CNT,F
BNZ D1s
RETURN
DELAY100ms
MOVLW D'10'
MOVWF D_CNT
D100ms CALL DELAY10ms
DECF D_CNT,F
BNZ D100ms
RETURN
DELAY10ms
MOVLW 0x3C
MOVWF TMR0H
MOVLW 0xB0
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0A BTFSS INTCON, TMR0IF
BRA TM0A
BSF T0CON,TMR0ON
RETURN
DELAY1ms
MOVLW 0xEC
MOVWF TMR0H
MOVLW 0x78
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0B BTFSS INTCON, TMR0IF
BRA TM0B
BSF T0CON,TMR0ON
RETURN
DELAY100us
MOVLW 0xFE
MOVWF TMR0H
MOVLW 0x0C
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0C BTFSS INTCON, TMR0IF
BRA TM0C
BSF T0CON,TMR0ON
RETURN
DELAY10us
MOVLW 0xFF
MOVWF TMR0H
MOVLW 0xCE
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0D BTFSS INTCON, TMR0IF
BRA TM0D
BSF T0CON,TMR0ON
RETURN
DELAY1us
MOVLW 0xFF
MOVWF TMR0H
MOVLW 0xFB
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON,TMR0ON ;start timer
TM0E BTFSS INTCON, TMR0IF
BRA TM0E
BSF T0CON,TMR0ON
RETURN
;============================================================
end ; END OF PROGRAM
;============================================================
Can some one tell me what am i doing wrong. I have also attach the config pics of boht Xbee modules.