Mikael
Many thanks - that solves that.
For anyone who is interested code to run a 38400 baud software UART on a 64Mhz 18F25K22 (picaxe 28X2) using the standard picaxe download pins (RX = RA4, TX=RA5) is attached. It also works at 19200 baud on a 32Mhz part.
In addition the variable definitions block need to be amended as follows:
BLPLP and BLSIZEP need to be set to 9 in settings.inc and as per Mikael's note this need to be mirrored in the DS30 GUI and/or command line interface
Best regards
Peter
Many thanks - that solves that.
For anyone who is interested code to run a 38400 baud software UART on a 64Mhz 18F25K22 (picaxe 28X2) using the standard picaxe download pins (RX = RA4, TX=RA5) is attached. It also works at 19200 baud on a 32Mhz part.
Code:
;------------------------------------------------------------------------------
; CommInit()
;------------------------------------------------------------------------------
CommInit
banksel ANSELA
bcf ANSELA,4
bcf ANSELA,5
banksel TRISA
bcf TRISA,5
bsf TRISA,4
bcf LATA,5 ; SET PIN TO A "MARK"(-RS232) FOR THE STOP BIT
return
Receive movlw BLDELAY
RcvIni movwf cnt1 ;
rpt2 movlw DELBASE ;
movwf cnt2 ;
rpt3 clrf cnt3
rptc btfsc PORTA,4 ; SKIP ON START BIT != "SPACE" (+RS232)
bra readbits
notrcv decfsz cnt3
bra rptc
decfsz cnt2
bra rpt3
decfsz cnt1
bra rpt2
; Receive timed out if we get here
bra exit
readbits
movlw d'08' ; START SERIAL INPUT SEQUENCE
movwf TEMP ; COLLECT 8 DATA BITS
clrf serbuf ; CLEAR SERIAL CHARACTER BUFFER
rcall HALFBAUD ; WAIT HALF ONE BAUD TIME
btfss PORTA,4 ; FALL THRU IF START BIT STILL = "SPACE"
bra rpt2 ; ELSE IT WAS JUST A NOISE SPIKE, LOOP
Receive1
rcall BAUD ; WAIT ONE BAUD TIME
bcf STATUS,0 ; CLEAR THE CARRY BIT
rrcf serbuf,F ; ROTATE CRY -> MSB, ROTATE MSB RIGHT
btfss PORTA,4 ; IS INPUT = "SPACE" (+RS232) ?
bsf serbuf,7 ; ...SKIP IF YES, ELSE SET BIT TO LOGIC '1'
decfsz TEMP,F ; EIGHT COUNTS YET?
bra Receive1 ; ...NO, GET ANOTHER BIT
rcall BAUD ; WAIT ONE BAUD TIME
movf serbuf,W ; Put the character in reg 'W'
addwf crc, f ; compute crc
return
;
Send ; THIS ROUTINE USES 8 DATA BITS
banksel serbuf
movwf serbuf ; W CONTAINS CHARACTER TO XMT
movlw 8 ; THE CHARACTER HAS 8 BITS
movwf TEMP
bsf LATA,5 ; SET START-BIT TO A "SPACE"
rcall BAUD ; WAIT ONE BAUD TIME
Send1
rrcf serbuf,F ; ROTATE THE FIRST BIT INTO CARRY
btfss STATUS,0 ; TEST THE CARRY BIT
bsf LATA,5 ; IF BIT IS 0 SET OUTPUT PIN TO A "1" (SPACE)
btfsc STATUS,0 ; TEST THE CARRY BIT AGAIN
bcf LATA,5 ; IF BIT IS 1 SET OUTPUT PIN TO A "0" (MARK)
rcall BAUD ; WAIT ONE BAUD TIME
decfsz TEMP,F ; IF COUNT IS ZERO THEN XMIT A STOP BIT
bra Send1 ; ...ELSE XMIT NEXT BIT
rrcf serbuf,F ; ROTATE CARRY, GET THE MSB BACK INTO BIT 7
bcf LATA,5 ; SET PIN TO A "MARK"(-RS232) FOR THE STOP BIT
rcall BAUD ; WAIT ONE BAUD TIME
rcall BAUD ; WAIT ONE BAUD TIME
return
;
BAUD ;wait loops tuned for 64Mhz 38400 baud use only
rcall HALFBAUD
rcall HALFBAUD
return
;
HALFBAUD
movlw 0x2
banksel Delay2
movwf Delay2,1
Delay
banksel Delay1
decfsz Delay1,1 ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0
goto Delay
movlw 0x17
nop ;Tune the delay
nop
banksel Delay1
movwf Delay1,1
banksel Delay2
decfsz Delay2,1
goto Delay
return
CommExit
return
Code:
#define BUFFERSIZE (ROWSIZEB + 1 ) ;row + checksum
cblock 0x0
buffer : BUFFERSIZE
crc : 1 ;receive checksum
dcnt : 1 ;datacount
dcnt2 : 1 ;datacount
cnt1 : 1 ;receive timeout timer
cnt2 : 1 ;receive timeout timer
cnt3 : 1 ;receive timeout timer
cntHello : 1 ;
rowcnt : 1 ;row iterator
rowcnt2 : 1 ;
cmd : 1 ;command
doerase : 1 ;do erase before next write
ttblptru : 1
ttblptrh : 1
ttblptrl : 1
Delay1 : 1
Delay2 : 1
serbuf : 1
TEMP : 1
endc
BLPLP and BLSIZEP need to be set to 9 in settings.inc and as per Mikael's note this need to be mirrored in the DS30 GUI and/or command line interface
Best regards
Peter