Smart Pins for Async Serial for P2 v27
Cluso99
Posts: 18,069
in Propeller 2
Is the following code the best way to use smart pins?
Are either of the commented out line pairs required (enable DIRn) ?
Are either of the commented out line pairs required (enable DIRn) ?
CON ' constants for serial driver _rxpin = 63 ' P63=SI _txpin = 62 ' P62=SO _baud = 115_200 _bitper = (_clockfreq / _baud) << 16 + 7 ' 115200 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 '-------------------------------------------------------------------------------------------------- ' Serial Routines '-------------------------------------------------------------------------------------------------- _serialinit wrpin ##_txmode, #_txpin ' set asynchronous tx mode in smart pin tx wxpin ##_bitper, #_txpin ' set tx bit period '' setb dirb, #_txpin ' enable smart pin tx ??? '' dirh #_txpin ' enable smart pin tx ??? wrpin ##_rxmode, #_rxpin ' set asynchronous rx mode in smart pin rx wxpin ##_bitper, #_rxpin ' set rx bit period '' setb dirb, #_rxpin ' enable smart pin rx ??? '' dirh #_rxpin ' enable smart pin rx ??? mov lmm_x, #CR ' we have to prime send buffer, jmp #_sendfirst ' ..so send <cr> _send testp #_txpin wc ' busy? if_nc jmp #_send ' _sendfirst wypin lmm_x, #_txpin ' send next byte to tx pin ret _recv testp #_rxpin wc ' char ready? if_nc jmp #_recv ' rdpin lmm_x, #_rxpin ' get data from rx pin ret '-------------------------------------------------------------------------------------------------- lmm_x long 0
Comments
You will need a shift on the received data too.
This is what I use currently.
I have the send working with either but I had to change SETB to BITH.
I forgot abou the shift for receive.
My baud calc works. Not sure what yours is doing.
clkset #$FF
remember I am using a damaged P123-A9
but on the send code... I can't get it to work with either if_c or if_nc
what does work for me is:
I have not tried receiving.
Snippets...
I didn't prime the pump.
Thanks
These Smart Pins really are smart.