Shop OBEX P1 Docs P2 Docs Learn Events
Can a smart pin receive and buffer serial data ? — Parallax Forums

Can a smart pin receive and buffer serial data ?

BeanBean Posts: 8,129
edited 2019-11-28 13:42 in Propeller 2
Looking at the smart pin modes it looks like it can receive a single character.
Is there a way to use the streamer to automatically store more characters ?
Or must you use an interrupt ?

Thanks,
Bean
P.S. Happy Thanksgiving to all.

Comments

  • The smart pin has room for at most 32 bits, so even in the best case you could only buffer 4 characters. But I think in fact it's limited to just one character, so you'll have to use interrupts or some other method to store more characters.
  • evanhevanh Posts: 15,916
    edited 2019-11-28 13:58
    Streamers have no data paths to smartpins so no they can't do that. Streamers have access to hubRAM, lutRAM, DACs and digital I/O (includes ADCs and comparators). Smartpins have access to just the pins (DACs, digital).

    For small stuff like key presses, polling works fine. For bulk data, it's either set it up for temporary burst or dedicate a whole cog like the original full-duplex-serial. Msrobots has done one of the latter already.

    Or you can try interrupts.

  • BeanBean Posts: 8,129
    Ok, So it looks like interrupts is the way to go.

    Thanks for the help,

    Bean
  • Bean wrote: »
    Ok, So it looks like interrupts is the way to go.

    Thanks for the help,

    Bean

    If it's any help this is what I use in TAQOZ for serial. While the serial receive interrupts and buffers characters, I find it is easier to transmit without buffering because this is a far more efficient way at high speeds. I think I've tested mine up to about 12Mbd.
    '#######################################################################'
    ' 	serial.p2a
    '#######################################################################'
    
    
    InitSerial
    		drvh	#tx_pin
    		wrpin	#$7C,#tx_pin			' asynchronous transmit
    		wrpin	#$3E,#rx_pin			' asynchronous receive
    'SETBAUD 						' calculate baud timing at runtime'
    		rdlong	r0,#@_CPUHZ
    		rdlong	r1,#@_BAUD
    		qdiv	r0,r1
    		getqx	r0
    		shl	r0,#16
    		add	r0,#7				' 8 data bits '
    		wxpin	r0,#rx_pin			' baud 8 data
    		wxpin	r0,#tx_pin			' baud 8 data
    		wypin   #$0D,#tx_pin
    		rdlong	PTRA,#@_TERMINAL
    		dirh    #rx_pin				' enable smartpin mode'
    		rdpin	rxz,#rx_pin wc			' clear rx?
    		setint1	#0				' disable int0'
    		mov 	rxwrC,#0
    		wrlong 	rxwrC,#@rxrd
    
    		setse1  #%110<<6+rx_pin        		' set se1 to trigger on  rx char event?????
                    mov     ijmp1,##@taqoz_rxisr     	' set int1 jump vector to receive buffer
    		setint1	#4				' Enable int0 to trigger on se1'
    		ret
    
    ' ( SERIAL RECEIVE INTERRUPT SERVICE ROUTINE )'
    taqoz_rxisr	shl 	rxlong,#8
                    rdpin   rxz,#rx_pin       		' recv byte (bits31:24) from rx pin
    		shr	rxz,#24				' right justify'
    		or	rxlong,rxz wz			' update history word'
    		cmp	rxlong,##$1B1B1B1B wz		' check for sequence'
    	if_z	coginit #0,#0	''@_RESET		' force reset '
    
    		cmp	rxlong,##$1A1A1A1A wz		' check for sequence '
    	if_z	decod	rxz,#28				' reboot via hub'
    	if_z	hubset	rxz
    		mov	rxwrP,rxwrC			' update write pointer'
    		add	rxwrP,##rxbuffers
    		wrbyte	rxz,rxwrP			' write char to buffer'
    		wrbyte	rxz,#@lastkey			' write directly to global variable in low hub'
    		incmod	rxwrC,##rxsize-1		' update write index'
    		wrword	rxwrC,#@rxwr			' update write index in hub'
    		reti1
    
    CONEMIT		or	tos,stopbits
    TXR1
    		mov	txpin,#tx_pin
                    wypin   tos,txpin             	'..send byte
    		waitx	#0
    .wait           testp   txpin         wc      	'..wait for buffer empty
     if_nc          jmp     #.wait
                    jmp     #DROP
    
    txpin		long	tx_pin
    stopbits	long	$FFFF_FF00
    
  • BeanBean Posts: 8,129
    edited 2019-11-29 16:08
    Peter,
    Thanks that helps a lot.

    Bean

    P.S. Can you explain the line "rdlong PTRA,#@_TERMINAL" ?
Sign In or Register to comment.