hello_p2
rjo__
Posts: 2,114
I will be getting an addon board for my NanoP2 from Mr. Potatohead in a few days, but this is driving me nuts.
I don't know who posted the following code, but after making the appropriate changes, it runs just fine with the new configuration on my bare NanoP2.
On the other hand, I have tried every variation I can think of in both Spin and P2ASM using the new configuration and the new serial code from Chip and it all seems to hang. I can get the monitor back by resetting the terminal. Does anyone have a working new serial "hello" in Spin that I can try? I don't really care that it doesn't work on my bare Nano, but I would be tickled if that it does. (If you think about it... have a compulsory need for addon boards would be a really good thing if they were for sale:)
Thanks
Rich
I don't know who posted the following code, but after making the appropriate changes, it runs just fine with the new configuration on my bare NanoP2.
' mostly stolen from Chip's P2 ROM monitor
CON
BASE = $e80
CLOCK_FREQ = 80000000
BAUD = 115200
SERIAL_TX = 90 ' must be in the port c
SERIAL_RX = 91
CR = $0d
LF = $0a
DAT
byte 0[BASE]
org
start reps #$1F6-@reserves+@start,#1 'clear reserves
setinda #reserves
mov inda++,#0
setp tx_pin
mov dirc,dirc_mask 'make tx pin an output
jmptask #rx_task,#%0010 'enable serial receiver task
settask #%%1010
' wait for the user to start the terminal emulator
mov x,#5
:pause getcnt w
add w,freq
passcnt w
djnz x,#:pause
setptra hello_addr 'print hello message
call #tx_string 'print hello/error message
setptra hello2_addr
call #tx_string
idle call #rx
cmp x,#CR wz
if_nz jmp #:next
call #tx
mov x,#LF
:next call #tx
jmp #idle
'
'
' Print string (@ptra)
'
tx_string rdbyte x,ptra++ 'get chr
tx_string_ret tjz x,#0 'if 0, done
call #tx 'other?
jmp #tx_string
'
'
' Transmit chr (x)
'
tx shl x,#1 'insert start bit
setb x,#9 'set stop bit
getcnt w 'get initial time
:loop add w,period 'add bit period to time
passcnt w 'loop until bit period elapsed
shr x,#1 wc 'get next bit into c
setpc tx_pin 'write c to tx pin
tjnz x,#:loop 'loop until bits done
tx_ret ret
'
'
' Receive chr (x)
'
rx call #rx_check 'wait for rx chr
if_z jmp #rx
rx_ret ret
'
'
' Check receiver, z=0 if chr (x)
'
rx_check or rx_tail,#$80 'if start or rollover, reset tail
getspb rx_temp wz 'if head uninitialized, z=1
if_nz cmp rx_temp,rx_tail wz 'if head-tail mismatch, byte ready, z=0
if_nz getspa rx_temp 'preserve spa
if_nz setspa rx_tail 'get tail
if_nz popar x 'get byte at tail
if_nz getspa rx_tail 'update tail
if_nz setspa rx_temp 'restore spa
rx_check_ret ret
'************************
'* Serial Receiver Task *
'************************
rx_task chkspb wz 'if start or rollover, reset head
if_z setspb #$80
mov rx_bits,#9 'ready for 8 data bits + 1 stop bit
neg rx_time,period 'get -0.5 period
sar rx_time,#1
jp rx_pin,#$ 'wait for start bit
subcnt rx_time 'get time + 0.5 period for initial 1.5 period delay
:bit rcr rx_data,#1 'rotate c into byte
add rx_time,period 'add 1 period
passcnt rx_time 'wait for center of next bit
getp rx_pin wc 'read rx pin into c
djnz rx_bits,#:bit 'loop until 8 data bits + 1 stop bit received
shr rx_data,#32-8 'align byte
pushb rx_data 'store byte at head, inc head
jmp #rx_task 'wait for next byte
'*************
'* Constants *
'*************
hello byte CR, LF, "Hello, Propeller II!", CR, LF, 0
hello2 byte CR, LF, "Hello again, Propeller III!", CR, LF, 0
hello_addr long @hello
hello2_addr long @hello2
rx_pin long SERIAL_RX
tx_pin long SERIAL_TX
dirc_mask long 1 << (64 - SERIAL_TX)
period long CLOCK_FREQ / BAUD
freq long CLOCK_FREQ
'*************
'* Variables *
'*************
reserves
w res 1 'main task
x res 1
y res 1
z res 1
rx_tail res 1 'serial receiver task
rx_temp res 1
rx_time res 1
rx_data res 1
rx_bits res 1
On the other hand, I have tried every variation I can think of in both Spin and P2ASM using the new configuration and the new serial code from Chip and it all seems to hang. I can get the monitor back by resetting the terminal. Does anyone have a working new serial "hello" in Spin that I can try? I don't really care that it doesn't work on my bare Nano, but I would be tickled if that it does. (If you think about it... have a compulsory need for addon boards would be a really good thing if they were for sale:)
Thanks
Rich

Comments
CON clkfrq = 80_000_000 baudper = clkfrq / 115200 PUB Main ser_start(91,90,115200) repeat 3 passcnt(clkfrq+getcnt) 'wait 1 second ser_str(@hello) '3* Hello World repeat ser_tx(ser_rx) 'then echo input PUB ser_start(rxpin,txpin,baudrt) setpera(baudper) '(clkfrq/baudrt) but no divide yet setsera((2<<7+rxpin)<<9 + 2<<7+txpin) drvc[.txpin] := 1 'works only for pins 64..91 PUB ser_rx : value repeat until serina(value) PUB ser_tx(value) repeat until serouta(value) PUB ser_str(strptr) repeat strsize(strptr) ser_tx(byte[strptr++]) DAT hello byte "Hello World",13,10,0 'Many things in Spin2 do not work yet. Divide and Multiply for example but also STRING(..), so I had to code around that.Andy
In your Spin2 code you have the following line
I assume this means set direction of Port C bit 26
The ".txpin" is the modulus of 90/32?
Where did you get this info on Spin2?
Cheers
Brian
I went ahead and attached it
***Error Strings Address is not long Address is out of range "}" must be preceeded by "{" to form a comment Block designator must be in first column Bitfield not allowed for "@" Blocknest stack overflow Constant cannot exceed $FF Constant exceeds 32 bits Conditional execution not allowed for TASKSW/TASKSWD instructions Constant must be from 0 to 3 Constant must be from 0 to 7 Constant must be from 0 to 15 Constant must be from 0 to 31 Constant must be from 0 to 63 Constant must be from 0 to 127 Constant must be from 0 to 255 Constant must be from 0 to 511 Constant must be from 1 to 64 Constant must be from 1 to 512 Constant must be from 1 to 16384 Conditional not allowed with REPS Conditional not allowed with SETINDx/FIXINDx _CLKFREQ or _XINFREQ must be specified COGINIT source must be a register, not a constant CALL symbol must not exceed 26 characters _CLKFREQ/_XINFREQ not allowed with RCFAST/RCSLOW _CLKFREQ/_XINFREQ specified without _CLKMODE Divide by zero Division overflow Destination register cannot exceed $1FF Expected an assembly effect or end of line Expected an assembly effect Expected an assembly instruction Expected a binary operator or ")" Expected a constant name Expected a constant, unary operator, or "(" Expected a DAT symbol Expected an expression term Expected an instruction or variable Expected a local symbol Expected a subroutine name Expected a subroutine, object name, or ~ Expected a terminating quote Expected a unique object name Expected a variable Expected a unique constant name or "#" Expected a unique name, BYTE, WORD, LONG, or assembly instruction Expected a unique parameter name Expected a unique result name Expected a unique subroutine name Expected a unique variable name Expected BYTE, WORD, or LONG Expected "," or end of line Expected ":" Expected "," Expected "," or ")" Either _CLKFREQ or _XINFREQ must be specified, but not both Expected "." Expected ".." Expected end of line Expected "=" "[" "," or end of line Expected FROM Expected INDA or INDB Expression is too complex Expected "(" Expected "[" Expected "#", "++", or "--" Expected PRECOMPILE or ARCHIVE Expected "#" or "@" Expected "|" or end of line Expected "#" Expected "}" Expected "}}" Expected ")" Expected "]" Empty string Expected STEP or end of line Expected TO Filename too long Floating-point constant must be within +/- 3.4e+38 Floating-point not allowed in integer expression Floating-point overflow Hub origin exceeds $1FFFF limit Invalid binary number Indirect buffer size must range from 1 to 512 Invalid _CLKMODE specified Invalid double-binary number Internal DAT file not found Invalid filename character Invalid filename, use "FilenameInQuotes" Integer not allowed in floating-point expression Internal Integer operator not allowed in floating-point expression Limit of 64 cases exceeded Limit of 8 nested blocks exceeded Limit of 32 unique objects exceeded Limit of 32 unique DAT files exceeded Limit of 32 unique PRECOMPILE files exceeded Limit of 32 unique ARCHIVE files exceeded List is too large Limit of 1024 DAT symbols exceeded Limit of 16 ELSEIF/ELSEIFNOTs exceeded Limit of 4096 local variables exceeded Limit of 15 parameters exceeded Limit of 15 parameters plus local variables exceeded Limit of 256 subroutines + objects exceeded No conditional allowed with INDA/INDB No cases encountered No PUB routines found Origin already exceeds target Object count must be from 1 to 255 Object distiller overflow Origin exceeds FIT limit Object exceeds 128k Origin exceeds $1F6 limit "$" is not allowed here OTHER must be last case PUB/CON list overflow PTRA/PTRB index constant must range from -32 to 31 PTRA/PTRB index constant must range from 0 to 31 PTRA/PTRB index constant must range from 0 to 32 ?_RET address is not long ?_RET address is out of range Register cannot exceed $1FF Register is not allowed here RES is not allowed in ORGX mode RDxxxx/WRxxxx must use a register or PTRA/PTRB expression, not a constant Source constant cannot exceed $1FF Symbols _CLKMODE, _CLKFREQ, _XINFREQ can only be used as integer constants String characters must range from 1 to 255 Symbol _DEBUG can only be used as an integer constant Symbol exceeds 30 characters Symbol is already defined STRING not allowed here Size override must be larger Size override must be smaller Subroutine pointed to must be 1st..63rd PUB/PRI Source register cannot exceed $1FF Symbol table is full This effect is not allowed for this instruction This instruction is only allowed within a REPEAT block Too many string constants Too many string constant characters Too much variable space is declared Unrecognized character Undefined ?_RET symbol Undefined symbol Variable needs an operator WR/NR not allowed for this instructionI'll take a look... Thanks Potatohead
Thanks Potatohead
You've given us a good starting point.
Cheers
Brian
Chip has a Spin2 example in the ZIP (serialio.spin). From that I got the [.bit] syntax and the serina, serouta handling.
The rest is guessing and trial and error and - yes I also looked into the PNUT.exe with a hex-viewer.
I think the syntax with the dot for bits is because in Spin2 you can access the bits of every variable, not only the OUTx, DIRx etc.
Chip has included Spin commands for most new PASM instructions with the same name, so the PASM reference helps also.
But it is not so much fun to code in Spin2 at the moment, because you never know what works and what not. It's more debugging than coding.
@potatohead
Thanks for the ASCII extraction. much better than what I have done.
But I think you need to remove the first character of most Spin command words, they specify some kind of command type.
Andy
Edit: I did a lot of them.
Re: ASCII
On UNIX, just use "strings pnut.exe > text.txt" Microsoft published one that works about the same way, and it can be found on Technet. That's what I used as I'm on a Win32 machine right now.