GreenLeader
Senior Member
I decided to put this up under its own thread this time:
(Since earlier posts, I've exhausted the advice given so far. I need to use HSERIN/HSEROUT because I need the higher baud rates that it offers).
I am using the "hardware serial port" and HSEROUT to upload data from my 40X1 to the PE serial terminal. I have a cable connecting pins 25/26 to the PC serial port, similar to the recommended "download" circuit shown in the manual. This works fine for sending from 40X1 to PC.
I'd also like to have the 40X1 receive keystrokes from the connected PC using HSERIN - just a single number between 1 and 6.
I am using the code below to test this (works fine on the PE simulator). However, when I test on hardware I find that I get a scrambled response:
key | decimal response (in b2)
-----------------------------
1 | 103
2 | 51
3 | 102
4 | 25
5 | 101
6 | 50
7 | 100
I could probably just write code to map 103 to 1, 51 to 2 etc, but I'd rather understand what the issue is and do it correctly.
Is there any reason that my hardware could send ok, but not receive?
Should I be looking at the hardware, or I am missing something in the code?
(Since earlier posts, I've exhausted the advice given so far. I need to use HSERIN/HSEROUT because I need the higher baud rates that it offers).
I am using the "hardware serial port" and HSEROUT to upload data from my 40X1 to the PE serial terminal. I have a cable connecting pins 25/26 to the PC serial port, similar to the recommended "download" circuit shown in the manual. This works fine for sending from 40X1 to PC.
I'd also like to have the 40X1 receive keystrokes from the connected PC using HSERIN - just a single number between 1 and 6.
I am using the code below to test this (works fine on the PE simulator). However, when I test on hardware I find that I get a scrambled response:
key | decimal response (in b2)
-----------------------------
1 | 103
2 | 51
3 | 102
4 | 25
5 | 101
6 | 50
7 | 100
I could probably just write code to map 103 to 1, 51 to 2 etc, but I'd rather understand what the issue is and do it correctly.
Is there any reason that my hardware could send ok, but not receive?
Should I be looking at the hardware, or I am missing something in the code?
Code:
#PICAXE 40X1
' Test keyboard input from PC into hardware serial port
'set up the hardware
hsersetup B38400_4, %10
' clear 20x4 lcd
pause 1000
serout 6,T2400,(254,1)
b2 = 0 'initialise variable to receive keystroke
Start:
serout 6,T2400,(254,1) 'clear LCD
' ask user to enter number (between 1 and 6)
hserout 0,("Hit a number ",CR,LF)
hserin 4,1 'receive 1 byte to scratchpad loc'n 4
ptr = 4 'set scratchpad pointer
b2 = @ptr ' copy the byte to b2
'display on LCD Line 1
serout 6,T2400,(254,128,"Number was ",#b2)
goto Start