Shop OBEX P1 Docs P2 Docs Learn Events
Prop2 V8 questions re testing — Parallax Forums

Prop2 V8 questions re testing

Cluso99Cluso99 Posts: 18,069
edited 2016-04-14 11:52 in Propeller 2
I have successfully loaded the base code into my DE-Nano and compiled/downloaded pasm code with pnut to flash my external rgb leds.

How are you guys testing the serial?

I have been compiling and loading with pnut v8 using F11, then running PST to see the serial output.
But I am not seeing anything being output so I am unsure what is happening. Here is my code in case there is a bug that I cannot see. Its a mix of Chip & Ozprop's code with a bit of mine thrown in.
CON
  _xinfreq_     = 80_000_000

  _SIpin        = 63            ' \ usual serial input pin  (from TXD on pc)
  _SOpin        = 62            ' |              output pin (to   RXD on pc)
'  _SIOmode      = 0             ' | usual mode
  _SIObaud      = 115200        ' / common baud (serial speed)
'  _SIOpins      = _SIOmode << 16 | _SIpin << 8 | _SOpin
  _SIObits      = 8             ' 8-bit char
  nco_baud = round(float($1_0000) / (float(_xinfreq_) / float(_SIObaud)))
  
dat             org

'                pinsetm pm_tx,  #_SOpin         'set asynchronous tx mode in smart pin 0
'                pinsetx bitper, #_SOpin         'set tx bit period
                pinsetm #%1_11110_0,#_SOpin
                pinsetx ##$8000_0000 | nco_baud << 16 | %1_00000 | _SIObits-1,#_SOpin
		setb	dirb,#_SOpin		'set tx to output

cloop   	call    send_char
		add     tx_char, #1		' char++
		and	tx_char, #$3F
		waitx 	#500
              	jmp	#cloop              

send_char       pingetz temp, #_SOpin   wc      'wait if busy
        if_c    jmp     #send_char
                pinsety tx_char,#_SOpin
                ret                     wz,wc

pm_tx           long    %0000_0000_000_0000000000000_01_11110_0 'async tx mode, output enabled for smart output
bitper          long    (_xinfreq_/_SIObaud)<<16 + (_SIObits - 1)                      ' clocks/bit, 8-bit char
x               long    0
y               long    0
temp            long    0
tx_char		long	$30

Comments

  • The DE0-Nano only has 8 smartpins. I think they are P0 to P7?

  • Cluso99Cluso99 Posts: 18,069
    Thanks Brian,
    Totally forgot.
  • Cluso99Cluso99 Posts: 18,069
    No lockups with pnut today :)

    However, I cannot get anything to output correctly using async uart with tx on P0 on De0-nano.
    Here are two versions I have tried
    CON
      _xinfreq_     = 80_000_000
      _txuart	= 0		' P0
      _SIObits      = 8             ' 8-bit char
      _SIObaud      = 115200        ' baud (serial speed)
      nco_baud	= round(float($1_0000) / (float(_xinfreq_) / float(_SIObaud)))
      
    dat             org
    
                    pinsetm ##%0000_0000_000_0000000000000_01_11110_0,#_txuart
                    pinsetx ##$8000_0000 | nco_baud << 16 | %1_00000 | _SIObits-1,#_txuart
    		setb	dira,#_txuart		
    
    cloop   	call    send_char
    		add     tx_char, #1		' char++ (limits $30-$3F)
    		and	tx_char, #$3F
    '		waitx 	delay
                  	jmp	#cloop              
    
    send_char       pingetz tmp, #_txuart   wc      
            if_c    jmp     #send_char		' wait if busy
                    pinsety tx_char,#_txuart
                    ret                     wz,wc
    
    tmp             long    0
    tx_char		long	$30
    delay		long	_xinfreq_
    
    and
    ' 10M baud 8-bit serial demo
    
    dat		org
    
    		pinsetm	pm_tx,	#0	'set asynchronous tx mode in smart pin 0
    		pinsetx	bitper,	#0	'set tx bit period
    
    '		pinsetm	pm_rx,	#1	'set asynchronous rx mode in smart pin 1
    '		pinsetx	bitper,	#1	'set rx bit period
    
    		mov	dira,#%11110011	'enable pins 7..4 and smart pins 1..0
    
    		pinsety	#0,#0		'send initial byte to tx pin
    
    .loop	'	waitx	#200		'uncomment for delay between bytes
    
    .full		testb	ina,#0	wc	'wait for buffer empty on tx pin
    	if_nc	jmp	#.full
    
    		pinack	#0		'acknowledge tx pin
    
    		pinsety	x,#0		'send next byte to tx pin
    
    '		incmod	x,#$FF		'increment byte, constrain to $FF for faster pinsety
    
    		jmp	#.loop
    
    .recv		testb	ina,#1	wc	'wait for smart pin 1 to signal rx data received
    	if_nc	jmp	#.recv
    
    		pinack	#1		'acknowledge rx pin
    
    		pingetz	y,#1		'get data from rx pin
    
    		setnib	outa,y,#1	'write 4 lsb's of rx data to to pins 7..4
    
    		notb	outa,#1		'make scope trigger on pin 1 (since smart pin 1 is
    		notb	outa,#1		'...reading pin 0, pin 1 is still usable for normal output)
    
    		jmp	#.loop		'loop
    
    
    'pm_tx		long	%0000_0000_000_0000000000000_01_11110_0	'async tx mode, output enabled for smart output
    pm_tx		long	%0000_0000_000_0000001000000_01_11110_0	'async tx mode, output enabled for smart output  invert OUT
    'pm_tx		long	%1000_1000_000_0000000000000_01_11110_0	'async tx mode, output enabled for smart output
    pm_rx		long	%0111_0000_000_0000000000000_01_11111_0	'async rx mode, output enabled for normal output, inputs pin 0
    
    'bitper		long	8<<16 + 7	'number of clocks per bit period, 3..65536, 8-bit words
    'bitper		long	(80_000_000/115_200)<<16 + 7
    bitper		long	694<<16 + 7	'115200 baud
    x		long	$39
    y		long	0
    
    I have tried both with inversions.

    Does anyone have working P0 TX UART code working on De-Nano at 115,200 baud to a PC via propplug or equivalent???
  • ozpropdevozpropdev Posts: 2,792
    edited 2016-04-15 11:04
    In first program spotted this typo, missing # character
    cloop   	call    #send_char
    
    P0 to P3 are DACs, your code worked on P4 on a bare DE0-Nano. :)

  • cgraceycgracey Posts: 14,134
    Cluso99 wrote: »
    No lockups with pnut today :)

    However, I cannot get anything to output correctly using async uart with tx on P0 on De0-nano.
    Here are two versions I have tried
    CON
      _xinfreq_     = 80_000_000
      _txuart	= 0		' P0
      _SIObits      = 8             ' 8-bit char
      _SIObaud      = 115200        ' baud (serial speed)
      nco_baud	= round(float($1_0000) / (float(_xinfreq_) / float(_SIObaud)))
      
    dat             org
    
                    pinsetm ##%0000_0000_000_0000000000000_01_11110_0,#_txuart
                    pinsetx ##$8000_0000 | nco_baud << 16 | %1_00000 | _SIObits-1,#_txuart
    		setb	dira,#_txuart		
    
    cloop   	call    send_char
    		add     tx_char, #1		' char++ (limits $30-$3F)
    		and	tx_char, #$3F
    '		waitx 	delay
                  	jmp	#cloop              
    
    send_char       pingetz tmp, #_txuart   wc      
            if_c    jmp     #send_char		' wait if busy
                    pinsety tx_char,#_txuart
                    ret                     wz,wc
    
    tmp             long    0
    tx_char		long	$30
    delay		long	_xinfreq_
    
    and
    ' 10M baud 8-bit serial demo
    
    dat		org
    
    		pinsetm	pm_tx,	#0	'set asynchronous tx mode in smart pin 0
    		pinsetx	bitper,	#0	'set tx bit period
    
    '		pinsetm	pm_rx,	#1	'set asynchronous rx mode in smart pin 1
    '		pinsetx	bitper,	#1	'set rx bit period
    
    		mov	dira,#%11110011	'enable pins 7..4 and smart pins 1..0
    
    		pinsety	#0,#0		'send initial byte to tx pin
    
    .loop	'	waitx	#200		'uncomment for delay between bytes
    
    .full		testb	ina,#0	wc	'wait for buffer empty on tx pin
    	if_nc	jmp	#.full
    
    		pinack	#0		'acknowledge tx pin
    
    		pinsety	x,#0		'send next byte to tx pin
    
    '		incmod	x,#$FF		'increment byte, constrain to $FF for faster pinsety
    
    		jmp	#.loop
    
    .recv		testb	ina,#1	wc	'wait for smart pin 1 to signal rx data received
    	if_nc	jmp	#.recv
    
    		pinack	#1		'acknowledge rx pin
    
    		pingetz	y,#1		'get data from rx pin
    
    		setnib	outa,y,#1	'write 4 lsb's of rx data to to pins 7..4
    
    		notb	outa,#1		'make scope trigger on pin 1 (since smart pin 1 is
    		notb	outa,#1		'...reading pin 0, pin 1 is still usable for normal output)
    
    		jmp	#.loop		'loop
    
    
    'pm_tx		long	%0000_0000_000_0000000000000_01_11110_0	'async tx mode, output enabled for smart output
    pm_tx		long	%0000_0000_000_0000001000000_01_11110_0	'async tx mode, output enabled for smart output  invert OUT
    'pm_tx		long	%1000_1000_000_0000000000000_01_11110_0	'async tx mode, output enabled for smart output
    pm_rx		long	%0111_0000_000_0000000000000_01_11111_0	'async rx mode, output enabled for normal output, inputs pin 0
    
    'bitper		long	8<<16 + 7	'number of clocks per bit period, 3..65536, 8-bit words
    'bitper		long	(80_000_000/115_200)<<16 + 7
    bitper		long	694<<16 + 7	'115200 baud
    x		long	$39
    y		long	0
    
    I have tried both with inversions.

    Does anyone have working P0 TX UART code working on De-Nano at 115,200 baud to a PC via propplug or equivalent???

    I don't what else might be wrong, but the formula for computing the 16-bit NCO baud is:

    $1_0000 * (baudrate/clkrate)

    For 115.2kb at 80MHz clock, it would be:

    $1_0000 * (115_200/80_000_000) = 94

    You'd use: '$8000 + 94' for the baud field.
  • cgraceycgracey Posts: 14,134
    ozpropdev wrote: »
    The DE0-Nano only has 8 smartpins. I think they are P0 to P7?

    That's right.

    I just added the NCO baudrate formula into the Google doc.
  • Cluso99Cluso99 Posts: 18,069
    Thanks Chip & Brian.

    Chip,
    Do the De0-nano smart pins wrap from 0 to 63 for the pin -1/-2/-3 options ???
    I am thinking this way could use P0 & P1 smart pins with actual P62 & P63 pins. Just trying to get the serial back to the programming propplug pins.
  • Cluso99Cluso99 Posts: 18,069
    Async TX finally working on P0.
    Fixed a couple of bugs pointed out above. Thanks for your help.
    Then removed a serial 1K resistor - I am using a CP2102 USB/serial which is operating at 5V.

    Both NCO & Counter Mode work.
    '' RR20160416 working :)
    CON
      _xinfreq_     = 80_000_000
      _txuart	= 0		' P0
      _SIObits      = 8             ' 8-bit char
      _SIObaud      = 115200        ' baud (serial speed)
      nco_baud	= $1_0000 * (_SIObaud / _xinfreq_) '=94 
      
    dat             org
    
                    pinsetm ##%0000_0000_000_0000000000000_01_11110_0,#_txuart
    '                pinsetx ##(($8000 + 94) << 16) + 7, #_txuart
                    pinsetx ##(80_000_000 / 115_200)<< 16 +7,#_txuart
    		setb	dira,#_txuart		
    
    send_char       pingetz tmp, #_txuart   wc      
            if_c    jmp     #send_char		' wait if busy
                    pinsety #$37, #_txuart
                  	jmp	#send_char
    
    tmp             long    0
    

    Now to try redirecting to P62 ;)
  • Cluso99Cluso99 Posts: 18,069
    edited 2016-04-15 15:30
    Chip,

    PINSETM ##%0110_0000_000_0000000000000_01_11110_0,#_txuart ' P0-2=P62

    Is the above supposed to redirect the output to pin - 2 in Async Transmit ???

    It still outputs on P0, not on P62. Am I understanding the smart pins correctly, or does it only work for inputs ???
  • Only inputs benefit from +/- 123 selection.
Sign In or Register to comment.