How can SPIN2 test an IN or Carry flag?
JonTitus
Posts: 193
in Propeller 2
I need to set up a synchronous-serial transmit Smart Pin so a Spin2 program can detect whether or not the Smart Pin's buffer is empty. The instructions for that mode note:
With code such as below, can I detect the IN flag in Spin2 this way? Or am I missing something about use of RQPIN? I know the synchronous-serial smart pin works properly.
But when I run the following loop--within a larger program--the transmit and clock outputs work properly, but I never see the Z[31] set to a logic-1.
So I know the IN flag should get raised. The Spin2 Language Documentation described the RQPIN as:Each time the buffer is advanced into the shifter, IN is raised, indicating that a new output word can be written via WYPIN.
Now the Z[31] bit represents the state of the Carry bit/flag. Is that correct?RQPIN(Pin) : Zval --- Read Pin smart pin without acknowledging, Zval[31] = C flag from RQPIN, other bits are RQPIN.
With code such as below, can I detect the IN flag in Spin2 this way? Or am I missing something about use of RQPIN? I know the synchronous-serial smart pin works properly.
repeat until alpha <> $8000_0000 'wait for alpha MSB = 1 alpha := RQPIN(21) & $8000_0000 '21 = Sync Ser Transmit pin, mask Z[31]
But when I run the following loop--within a larger program--the transmit and clock outputs work properly, but I never see the Z[31] set to a logic-1.
PINSTART (20, Transition_Mode, 7496, 0) 'Start Smart Pin 20 PINSTART (21, Sync_Tx_Mode, Sync_Ser_Xreg, 0) 'Start Smart Pin 21 repeat 'Loop forever waitms (100) 'Short delay wypin (20, Numb_Transitions) 'Set clock transitions wypin (21, $82) 'Send $82, %10000010 waitms (100) 'short delay alpha := RQPIN(21) 'Get Z-reg data debug (UHEX_Long(alpha)) 'Display Z-reg dataForum help always appreciated. --Jon

Comments
WaitIn 'wait for smartpin to be done with current sample testp pLeft wc if_nc jmp #WaitInpub shiftin(mode, bits) : value '' Shift data in from a synchronous serial device '' -- mode is bit order: LSBFIRST or MSBFIRST '' -- bits in the number of bits in the value pinf(sdi) ' reset di wxpin(sdi, %0_00000 | (bits-1)) ' configure sampling/bits pinl(sdi) ' enable di wypin(sck, bits) ' start clocking data repeat until pinr(sck) ' wait until clocks finished value := rdpin(sdi) ' get the value if (mode == LSBFIRST) value >>= (32-bits) ' align lsb else value rev= 31 ' flip to align lsb if (bits < 32) ' clear unused bits value zerox= (bits-1)FWIW, I've abandoned using smart pins for SPI -- it takes less effort to bit-bang and you have more flexibility.
pub start(sdipin, sdopin, sckpin, khz) : result | m, x, tix stop() if ((sdipin == sdopin) || (sckpin < 0)) ' validate pins return false longmove(@sdi, @sdipin, 3) ' save pins if (sdi >= 0) m := P_SYNC_RX ' spi rx mode m |= ((sck-sdi) & %111) << 24 ' add SCK offset (B pin) x := %0_00000 | (8-1) ' sample ahead of b pin rise, 8 bits pinstart(sdi, m, x, 0) ' configure smart pin pinf(sdi) ' disable until used if (sdo >= 0) m := P_OE | P_SYNC_TX ' spi tx mode m |= ((sck-sdo) & %111) << 24 ' add SCK offset (B pin) x := %1_00000 | (8-1) ' start/stop mode, 8 bits pinstart(sdo, m, x, 0) ' configure smart pin pinf(sdo) ' disable until used m := P_OE | P_PULSE ' pulses for spi clock x.word[0] := 2 #> (clkfreq / (khz*1000)) <# $FFFF ' ticks in period x.word[1] := x.word[0] >> 1 ' ticks in low cycle (50%) pinstart(sck, m, x, 0) ' configure smart pin setup := true return setupPutting magic numbers for pins into examples leads newcomers down a bad-habit path -- in my opinion.busy := RDPIN(pin) < 0
Could the transmit have been completing so quickly that you were never able to catch BUSY high?
Chip--I'll check that. I see the flag bit now that I can use DEBUG.
Suppose I want to check the flag for the asynchronous receiver mode and I expect 32-bit data. How does the IN flag get tested then in Spin2? Obviously the C flag can't go into bit Z[31]. Maybe resort to a short section of assembly-language?
--Jon
I think I've decided that if it's a single pin it's the same as INA[pin] or INB[pin].
Guessing that if it's multiple pins it's a bitfield with bit 0 being the starting pin...
That right. The TESTP instruction in PASM can only read one pin, but to match all the output instruction in Spin2 which can work on fields of pins, the PINREAD command reads INA or INB and then LSB-justifies the first bit in the field, with any other bits above the LSB.