Jeremy Harris
Senior Member
I've spent the last few hours trying to bottom out an odd problem. I have an OpenLog connected to a 20M2, so that C.3 transmits serial data at 9600 baud to the OpenLog and C.4 receives serial data from the OpenLog. The received data is in ASCII and consists of five ASCII characters read from a file on the OpenLog.
The problem I have is that I used a snippet of code that I'd used on a 14M2 and just changed the pin numbers to use it on the 20M2. This works, in as much as commands can be sent to the OpenLog and data can be received, but for some reason the ASCII receive capability seems to not work on the 20M2 (but works perfectly on the 14M2).
First, here's the working 14M2 test code to read five characters from a file on the card in the OpenLog and spit them out to the terminal:
Next, here's the same code for a 20M2 that stalls at the serin command (only change is that the port designation is different):
I've reluctantly concluded that there may be a problem that's related to the way that the 20M2 handles serial input. I've ascertained that it will receive raw binary OK (if I remove the # qualifiers it receives a CR, LF, and then the first two bytes of data as raw binary, followed by another CR). The serin command just seems to lock up if I try and use the #qualifier though.
Does anyone know why the #qualifier works OK for serin on the 14M2 but doesn't seem to on the 20M2?
Not sure if this is the problem or not, but having been chasing my tail for a fair while over this I'd appreciate another view!
The problem I have is that I used a snippet of code that I'd used on a 14M2 and just changed the pin numbers to use it on the 20M2. This works, in as much as commands can be sent to the OpenLog and data can be received, but for some reason the ASCII receive capability seems to not work on the 20M2 (but works perfectly on the 14M2).
First, here's the working 14M2 test code to read five characters from a file on the card in the OpenLog and spit them out to the terminal:
Code:
;Test code for OpenLog
#Picaxe 14M2
;OpenLog TX = c.1
;OpenLog RX = c.0
;tested and works perfectly on 14M2
symbol CTRLZ = 26 ;ctrl Z
setfreq m8 ;set 8MHz clock to allow 9600 baud comms
init:
pause 200
high c.0 ;this is needed to ensure serial command works first time on OpenLog port
serout c.0,T9600_8,(CTRLZ,CTRLZ,CTRLZ) ;force command mode on OpenLog (should default to this mode)
serin c.1,T9600_8,(">") ;wait for cursor as indication that OpenLog is ready to receive commands
main:
serout c.0,T9600_8,("read DATETIME.TXT 0",CR) ;read datetime.txt file (should have 5 ASCII characters)
serin c.1,T9600_8,#b0,#b1,#b2,#b3,#b4
sertxd (#b0,CR,LF,#b1,CR,LF,#b2,CR,LF,#b3,CR,LF,#b4,CR,LF,CR,LF)
pause 2000
goto main
END
Code:
;Test code for OpenLog
#Picaxe 20M2
;OpenLog TX = c.4
;OpenLog RX = c.3
;Doesn't work on 20M2
symbol CTRLZ = 26 ;ctrl Z
setfreq m8 ;set 8MHz clock to allow 9600 baud comms
init:
pause 200
high c.3 ;this is needed to ensure serial command works first time on OpenLog port
serout c.3,T9600_8,(CTRLZ,CTRLZ,CTRLZ) ;force command mode on OpenLog (should default to this mode)
serin c.4,T9600_8,(">") ;wait for cursor as indication that OpenLog is ready to receive commands
main:
serout c.3,T9600_8,("read DATETIME.TXT 0",CR) ;read datetime.txt file (should have 5 ASCII characters)
serin c.4,T9600_8,#b0,#b1,#b2,#b3,#b4
sertxd (#b0,CR,LF,#b1,CR,LF,#b2,CR,LF,#b3,CR,LF,#b4,CR,LF,CR,LF)
pause 2000
goto main
END
Does anyone know why the #qualifier works OK for serin on the 14M2 but doesn't seem to on the 20M2?
Not sure if this is the problem or not, but having been chasing my tail for a fair while over this I'd appreciate another view!