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
FWIW, I've abandoned using smart pins for SPI -- it takes less effort to bit-bang and you have more flexibility.
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.