What does a setcommand statement do?
JonTitus
Posts: 193
Several SPIN/assembly-language programs include statements such as this one from an SPI object:
PUB SHIFTOUT(Dpin, Cpin, CSpin, Bits, Value)
setcommand(1, @Dpin)
What does this instruction do? Why do programmers use it? I've assumed the @Dpin points to the starting address of the arguments. That's as far as I got. The setcommand statement isn't documented in the Propeller Manual v. 1.2 and I can't find an explanation--and a clear example in the Forum. Thanks for your help. --Jon
Comments
Look for something like this in the code.
PRI setcommand(cmd, argptr) command := cmd << 16 + argptr repeat while commandYou're right, Jon: @Dpin is passing the hub address of the parameters which are used by the PASM cog. A non-zero value in the cmd parameter of setcommand() triggers the operation.I haven't yet developed a comfort with the SPI modes of the smart pins, so I'm working on an inline P2ASM program. This is the shiftout() function from that code. I really like that the P2 allows us to blend Spin2 and P2ASM without invoking a cog. I still need to wring-out my shiftin() and shiftio() functions -- then I will send to Parallax.
pub shiftout(outval, bits, mode) | x, clk, do, di, tix '' TX bits from outval using defined SPI pins '' -- mode determines bit order and clock phase '' * 0 = LSBPRE, 1 = MSBPRE, 2 = LSBPOST, 3 = MSBPOST '' * modes 0..1 are CPHS0; modes 2..3 ard CPHS1 longmove(@clk, @sck, 4) ' copy pins & timing org drvl do ' make sdo output if shared test mode, #%01 wc ' check for lsb mode if_nc rev outval ' lsbfirst -- reverse the bits if_c mov x, #32 if_c sub x, bits if_c shl outval, x ' msbfirst -- slide into position test mode, #%10 wz ' check clock mode rep #9, bits ' shift out the bits rol outval, #1 wc ' c <- outval.[31] if_z drvc do ' c -> sdo (CPHS0) waitx tix ' let sdo settle drvnot clk ' toggle sclk waitx tix if_nz drvc do ' c -> sdo (CPHS1) waitx tix drvnot clk waitx tix so_exit drvl do ' leave sdo low endAndy
-- start() (setup pins, clock mode, and clock timing)
-- shiftout() (as above, works in all modes)
-- shiftin() (needs testing -- waiting on some shift registers)
-- shiftio() (needs testing)
At the moment, I'm not convinced using smart pins is the best way for me to do SPI. That said, I reserve the right to be wrong and to change my mind down the line.