'Rotate Left' Not Rotating
lardom
Posts: 1,659
in Propeller 1
The manual says 'rotate left' causes the MSB to rotate to the LSB. The second expression 'should' return 225. What am I missing?
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
pst : "Parallax Serial Terminal"
VAR
byte temp
PUB main
pst.Start(57600)
WAITCNT(clkfreq + CNT)
one := (%00011110 << 4) 'shift left
pst.dec(one)
pst.Chars(pst#NL, 1)
pst.bin(one, 8)
pst.Chars(pst#NL, 1)
one := (%00011110 <- 4) 'rotate left
pst.dec(one) 'both return 224
pst.Chars(pst#NL, 1)
pst.bin(one, 8)
pst.Chars(pst#NL, 1)

Comments
Here's a routine that may help you do 8-bit SPI -- output and input is MSBFIRST.
pub shift_io(b) b <<= 24 ' move to byte[3] repeat 8 outa[mosi] := b <-= 1 ' rotate MSB (bit31) to bit0 for output outa[sclk] := 1 ' clock the bit outa[sclk] := 0 if (ina[miso]) ' if input is 1 b |= 1 ' set bit 0 else ' else b &= !1 ' clear bit 0 return b.byte[0]The output byte gets moved into BYTE3 so that it the MSB can be rotated into BIT0 for output. After clocking that bit out, the input (MISO) line is checked b.bit0 is set or cleared as required. There are not bit operators in Spin, so we have to do with with a mask.As soon as I saw: I said "That's it!"
MISO was the next hurdle. Thank you. The datsheet for the nRF24L01 says MISO and MOSI are shifted in/out simultaneously. I believe I have to shift out $FF for every byte I want to read out of the device. I have been trying to get telemetry to work.
pri spi_readwrite(datain) : dataout '' Shifts datain into MCP2515, receives and returns dataout (from MCP2515) datain <<= 24 ' prep for MSB output repeat 8 outa[mosi] := datain <-= 1 ' datain msb --> MOSI dataout := (dataout << 1) | ina[miso] ' MISO <-- dataout msb outa[sck] := 1 ' clock high outa[sck] := 0 ' clock low return dataout.byte[0]In 'my' experiments I assumed '+=' would be the logical choice because it 'didn't' overwrite the previous value.