Shop OBEX P1 Docs P2 Docs Learn Events
SPI slave in assembly — Parallax Forums

SPI slave in assembly

stinkypetestinkypete Posts: 3
edited 2013-02-28 11:57 in Propeller 1
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:
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

  • jmgjmg Posts: 15,173
    edited 2013-02-27 12:02
    stinkypete wrote: »
    Sorry about the copy paste. I'm not sure how to frame it like I see in other posts. Thanks in advance

    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 ....
    edited to add some format control
    
  • BeanBean Posts: 8,129
    edited 2013-02-27 13:48
    I added the [ code ] and [ /code ] tags for you.

    Bean
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-02-27 14:02
    > add aPTR, #16 'initialize the PTR to 16
    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
  • stinkypetestinkypete Posts: 3
    edited 2013-02-28 09:08
    Thanks for helping me out on the forum and my code. I'm still having problems reading the state of my WaitPNE of the pinCoilOut. Even though I can see it rising and falling on the scope (pin #1 is generating the pulse), my code doesn't seem to see it. I wrote some spin code that performs this same function and it works. What can I do to troubleshoot this part of my code?
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-02-28 09:55
    >pinCoilOut long %0000_0000_0000_0000_0000_0000_0000_0010 'IO port bit 2 is the coiloutput

    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
  • stinkypetestinkypete Posts: 3
    edited 2013-02-28 11:57
    Thanks Tony for the help. Its now working. I'm able to communicate with my dsPIC33F at 2.4Mbs. I'll be happy to post my assembly part of my program the SPIN stuff is not finished and wouldn't be helpful to anyone.
Sign In or Register to comment.