SPI slave in assembly
Hello, I was wondering if anyone would be willing to give me some advice. I'm writing my own SPI slave for the propeller. I tried a SPIN version but it's just not fast enough. So I'm trying an assembly version. Here's how I want it to work:
1. The code is started in it's own COG and waits for the pinCoilOut to go low.
2. Pin pinADCGo is pulsed high to low.
3. Wait for the pinADCrdy to go high.
4. SPI in 16 bits of data (short version)
I have yet the data that will come out of my code but for now just getting the output to pulse would be a clue I'm on the right track
Here's my code:
Sorry about the copy paste. I'm not sure how to frame it like I see in other posts. Thanks in advance
1. The code is started in it's own COG and waits for the pinCoilOut to go low.
2. Pin pinADCGo is pulsed high to low.
3. Wait for the pinADCrdy to go high.
4. SPI in 16 bits of data (short version)
I have yet the data that will come out of my code but for now just getting the output to pulse would be a clue I'm on the right track
Here's my code:
DAT
ORG $000
SPI_In mov r0, PAR
or DIRA,pinADCGo 'set the ADC as an output
mov input, #0 'Sets the input working register to 0
waitpne pinCoilOut,pinCoilOut 'wait until the coil output goes low
or OUTA,pinADCGo 'turn on the chip select / read line
xor OUTA,pinADCGo 'turn off the chip select / read line
add aPTR, #16 'initialize the PTR to 16
mov rslt, #0 'clear the rslt
waitpeq pinADCrdy, pinADCrdy 'waits for the CS line to pulse high
sp waitpeq pinADCrdy,pinADCrdy 'wait till the clock goes high
mov input, INA
and input, pinADCsda
or rslt, input 'or the value of the ADCsda pin to the rslt
mov input, #0
shl rslt,#1 'shift the result to the left one bit as the MSB comes in first
waitpne pinADCrdy, pinADCrdy 'wait until the clock goes low
djnz aPTR,#sp 'jump back to the top if the ptr > 0.
rtn ret 'ret
r0 long $0
aPTR long 0
rslt long 0
pinADCrdy long %0000_0000_0000_0000_0000_0000_0010_0000 'IO port bit 5 is the signal from the dsPIC
pinCoilOut long %0000_0000_0000_0000_0000_0000_0000_0010 'IO port bit 2 is the coiloutput
pinADCGo long %0000_0000_0100_0000_0000_0000_0000_0000 'IO port bit 22 is ADC output
pinADCclk long %0000_0000_0000_0000_0000_0000_1000_0000 'IO port bit 7 is ADCclk
pinADCsda long %0000_0000_0000_0000_0000_0000_0100_0000 'IO port bit 6 is the signal from the dsPIC
input long 0
Sorry about the copy paste. I'm not sure how to frame it like I see in other posts. Thanks in advance

Comments
If you see any post with formatting you like, just click 'reply with quote' and you now can see all the control tags.
Copy those and cancel, and paste into your edit ....
Bean
change to: mov aPTR, #16
> mov input, INA
> and input, pinADCsda
> or rslt, input 'or the value of the ADCsda pin to the rslt
> mov input, #0
> shl rslt,#1 'shift the result to the left one bit as the MSB comes in first
replace with:
test pinADCsda, INA wc
rcl rslt,#1
Could be replaced with
pinCoilOut long 1<<1 'P1 the coiloutput
or
pinCoilOut long |<1 'P1 the coiloutput
Double check that this wire goes to P1