Complete P2 assembly-language synchronous receiver-transmitter code
JonTitus
Posts: 193
I hope this example might help. A large thank you to Forum members who helped. --Jon
' Synchronous serial transmission, Rev. 3, 06-13-2020 at 1007 MDT 'positive edge-trigger (Jon Titus) CON clkout = 40 ' Pin P40 'Transmitter's clock out, to P31 txout = 41 ' Pin P41 'Transmitter data out, to P30 rxin = 30 ' Pin P30 'Receiver data in rxclkin = 31 ' Pin P31 'Receiver clock in 'Remember to connect these pins as noted! dat org 0 coginit id, ##@sync_receive ' Initialize an available cog for sync receive '==================================== ' Sync-serial transmit of data at set intervals. dirl #txout 'Transmitter setup wrpin sync_tx_mode, #txout 'Set sync tx mode for pin 41 wxpin #%1_00111, #txout 'Set up stop/start mode, X[5] = 1, 8 bits (7 + 1) dirh #txout 'Enable transmitter output dirl #clkout 'Clock output setup wrpin clock_mode, #clkout 'Set pin as transition-output mode wxpin ##$1000, #clkout 'Set base period for transition output dirh #clkout 'Enable clock-output .loop waitx ##10_000_000 'Delay between transmissions wypin ##$11, #txout '8-bit data to transmit, your choice wypin #16, #clkout 'Start clock, transmit data jmp #.loop 'Continue to transmit sync_tx_mode long %0000_1111_000_0000000000000_01_11100_0 'Positive-edge clock mode clock_mode long %0000_0000_000_000000_0_000000_01_00101_0 'Clock-mode id long 16 'Need the variable, but not used '==================================== ' Sync-serial receive, data to 8 LEDs on P7-P0 ' This software runs in a separate cog org 0 sync_receive mov dira, ##$00FF 'Pins P7--P0 set as outputs dirl #rxin 'Reset receiver Smart Pin wrpin sync_rx_mode, #rxin 'Set sync receiver mode wxpin #%1_00111, #rxin 'Set receiver to sample on B-input edge dirh #rxin 'Enable Smart-Pin sync receiver .test_loop testp #rxin wc 'Wait in loop for received data; IN flag raised nop if_nc jmp #.test_loop 'If no C flag, repeat testing rqpin rcvd_data, #rxin 'Put 32-bit data (see text) in rcvd_data shr rcvd_data, #24 'shift-right data 24 places to LSB mov outa, rcvd_data 'Send 8 bit data to LEDs jmp #.test_loop 'Continue to receive and display data sync_rx_mode long %0000_0001_000_0000000000000_01_11101_0 rcvd_data long $00
Comments
I'm assuming you have the unnecessary nop inside .test_loop to save some power while waiting. If you really want to save power, you can entirely avoid the busy-wait loop using SETSE1/2/3/4 and WAITSE1/2/3, or SETPAT and WAITPAT.
Is there any reason you used RQPIN and not RDPIN? I've never used RQPIN; I was under the impression that you normally only ever use RQPIN instead of RDPIN if you AKPIN or RDPIN that it somewhere else.
Sandy