;--------------------;TX485 Routine;--------------------tx485 bset RS485EN2,PTCD bset SCI2C2_TE,SCI2C2 jsr idelay jsr idelay clr TXCHK lda TXADRtx485a brclr SCI2S1_TDRE,SCI2S1,tx485a sta SCI2D add TXCHK sta TXCHK rts ;--------------------;TX Data;--------------------txdata lda CARDADR sta TXADR jsr tx485 lda #$3C jsr tx485a lda #$07 jsr tx485a lda #$07 jsr tx485a lda #$07 jsr tx485a lda #$07 jsr tx485a lda TXCHK and #$7F jsr tx485atxdata2 brclr SCI2S1_TC,SCI2S1,txdata2 jsr idelayh bclr RS485EN2,PTCD
sta SCI2D
TXBUF rmb 8 ;transmit bufferTXSTAT rmb 1 ;transmit status bitsTXCHK rmb 1 ;checksumTXCNT rmb 1 ;transmit buffer index*somewhere in your code... mov #$3C,TXBUF mov #$07,TXBUF+1 mov #$07,TXBUF+2 mov #$07,TXBUF+3 mov #$07,TXBUF+4 mov #$00,TXBUF+5 ;mark end of string bset 0,TXSTAT ;mark to send STARTMAIN BLAH,BLAH BLAHTXNEED BRCLR 0,TXSTAT,MAINEND ;bail if don't need to transmit BRCLR TDRE,SCI2S1,MAINEND ;bail if Tx reg not MT BRSET 1,TXSTAT,SENTADR ;check if address sent BSET 1,TXSTAT BSET RS485EN2,PTCD ;enable transmitter MOV CARDADR,SCI2D ;send address BRA CHK1SENTADR BRSET 2,TXSTAT,SCITC ;check if TXCHK sent LDX TXCNT ;GET TX'D CHAR COUNT INC TXCNT LDA TXBUF,X ;GET NEXT CHAR FROM TX1BUF BEQ CHKSM STA SCI2D ;SEND CHAR ADD TXCHKCHK1 STA TXCHK BRA MAINEND ;KEEP GOING IF NOT ENDCHKSM LDA TXCHK AND #$7F STA SCI2D ;SEND TXCHK BSET 2,TXSTAT ;set TXCHK sent BRA MAINENDSCITC BRCLR TC,SCI2S1,MAINEND ;WAIT FOR TRANSMISSION COMPLETE CLR TXSTAT ;clear status bits BCLR RS485EN2,PTCD ;disable transmitter (enable recieve) CLR TXCNT ;RESET TX COUNTERMAINEND JMP STARTMAIN
Hi Peg,
I've tried my buffering rx routine as follow.
it seems to work.
Any comment to make it more efficient?
Thanks.
Code:;--------------------;RX485 rxirq routine;--------------------XDEF isrVsci2rxisrVsci2rx: pshh clr RXCHK jsr rx485 sta RXDEV bne rxirq jmp rxirqz rxirq lda RXDEV cmp #DEVICE beq rxirq1 jmp rxirqzrxirq1 jsr rx485 sta RXADR cmp CARDADR beq rxirq2 jmp rxirqzrxirq2 jsr rx485 sta RXCMD rx0 cmp #$55 ;poll status bne rx1 jmp rxpoll rx1 rxirqy bclr LBUSYF,SR2 rxirqz pulh rti;--------------------;RX485 Routine;--------------------rx485 clr RXCTR clr RXLEN mov #$04,RXDEL bset LBUSYF,SR2rx485a lda #$00 feed_watchdog ldx RXLEN brset SCI2S1_RDRF,SCI2S1,rx485b dec RXCTR bne rx485a dec RXDEL bne rx485a rx485b lda SCI2D sta RXDATA sta RXBUF,X add RXCHK sta RXCHK lda RXDATA inc RXLENrx485z rts
Regards,
mingyee
rxpoll jsr rxchksum ;chksum bne rxirqzrxpoll1 lda CARDADR ;slave adr for master to identify sta TXADR jsr tx485 lda #$3C ;command jsr tx485a lda #$07 ;txdta jsr tx485a lda #$07 ;txdta1 jsr tx485a lda #$07 ;txdta2 jsr tx485a lda #$07 ;txdta3 jsr tx485a lda TXCHK ;txchksum and #$7F jsr tx485a rxpoll2 brclr SCI2S1_TC,SCI2S1,rxpoll2 jsr idelayh bclr RS485EN2,PTCD pulh rti
isrVsci2rx: pshh jsr rx485 psha lda RXPTR bne rxirq0 pula cmp #DEVICE beq rxirq1 jmp rxirqz rxirq0 pularxirq1 ldhx #RXBUF ldx RXPTR sta ,X incx stx RXPTR cmp #$FA beq rxirq1a ;to routine to process the data received jmp rxirqz1 ;exit irq