Smart-Pin asynchronous transmission logic level
JonTitus
Posts: 193
in Propeller 2
When I run the attached test code the bits appear properly on my scope but the initial state of the Smart-Pin transmitter pin appears as a logic-0. After the first transmission, this pin remains a logic-1 between transmissions. Based on experience with UARTs, the output should start at logic-1 so the receiving device "sees" the logic-1 to logic-0 edge of the start bit. How can I get the output pin to start as a logic-1? Thanks. --Jon
'Async Transmit Ver 2, 6-10-2020 at 1528H MDT
'Thanks to Ray Rodrick, et al.
CON
' Constants for serial-port control
_rxpin = 21 ' P21, serial in
_txpin = 20 ' P20 serial out
'_baud = 115_200 ' not used
_bitper = $3640_0007 ' bit rate for tests
_txmode = %0000_0000_000_0000000000000_01_11110_0 'async tx mode, output enabled for smart output
DAT
wrpin ##_txmode, #_txpin ' set Smart-Pin asynchronous transmit mode
wxpin ##_bitper, #_txpin ' set transmit bit period for 8 bits of data
dirh #_txpin ' enable smart pin tx
nop
wypin #$55, #_txpin ' transmit test bit pattern 01010101
nop
.flag_test testp #_txpin wc ' wait for transmit buffer empty
if_nc jmp #.flag_test ' if not empty, test again
waitx ##25_000_000 / 70 ' delay inserted for testing
wypin #$99, #_txpin ' send testing byte to tx pin
jmp #.flag_test ' transmit "forever"

Comments
If you are ok with a floating pin during reset, you can pgm an internal pullup before the pin is used as TXD.
CON _BAUD = 115_200 _bitper = (_clkfreq / _BAUD) << 16 + 7 ' eg ?? baud, 8 bits _txmode = %0000_0000_000_0000000000000_01_11110_0 ' async tx mode, output enabled for smart output _rxmode = %0000_0000_000_0000000000000_00_11111_0 ' async rx mode, input enabled for smart input ..... DAT _SerialInit wrpin ##_txmode, #tx_pin ' set asynchronous tx mode in smart pin tx wxpin mon.x, #tx_pin ' set tx bit period + #(bits-1) dirh #tx_pin ' enable smart pin tx wrpin ##_rxmode, #rx_pin ' set asynchronous rx mode in smart pin rx wxpin mon.x, #rx_pin ' set rx bit period + #(bits-1) dirh #rx_pin ' enable smart pin rx mov mon.x, #mon.CR ' we have to prime send buffer empty flag, wypin mon.x, #tx_pin ' ... so send <cr> to tx pin RET wcz ' <--- return to calling routine ---> _HubTx MOV mon.w, mon.x ' < push: 'x' #0 > ' ---------------------------------------- .send testp #tx_pin wc ' wait for buffer empty on tx pin if_nc jmp #.send ' wypin mon.x, #tx_pin ' send byte (bits7:0) to tx pin shr mon.x, #8 wz ' any more chars to send? if_nz jmp #.send '> br back: (nz = another char in mon.x) ' ---------------------------------------- MOV mon.x, mon.w ' < pop: 'x' #0 > RET wcz ' <--- return to calling routine --->This code configures P54 as serial transmit. The moment WYPIN which is equivalent to the PASM WRPIN is executed, then P54 switches from a floating input and becomes a high output.
Normally in TAQOZ the pin would be configured at a higher level like this: which sets the baud rate and 8-bit data by default and also writes a null character to prime the ready signal.
EDIT: Just to confirm exactly when the pin goes high, I added a test pulse around WYPIN and scoped it. Trace 1 = P54=TX
Trace 2 = P55 test pulse