Shop OBEX P1 Docs P2 Docs Learn Events
Assembly driver for ADIS15350 — Parallax Forums

Assembly driver for ADIS15350

electric550electric550 Posts: 122
edited 2009-08-11 23:24 in Propeller 1
Hello I am still trying to learn PASM and I am tyring to write a minimal assembly SPI driver for the ADIS16350...This has led to some bad code. The code is supposed to read the x axis gyro value but it is locking up...Any Suggestions would be great thanks!
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 6_000_000                                  

OBJ 
                                                       
  uarts         : "pcFullDuplexSerial4FC"               '1 COG for 4 serial ports


VAR

  Long GX, GXV 

Pub ADIS16350 
'Launch cog to start assembly PinTester
  uarts.Init
  uarts.AddPort(0,31,30,{
}   UARTS#PINNOTUSED,UARTS#PINNOTUSED,UARTS#DEFAULTTHRESHOLD, {
}   UARTS#NOMODE,UARTS#BAUD115200)                      'Add debug port
  uarts.Start                                           'Start the ports
GX := $05
GXV := 00
uarts.str(0,string("Starting"))
cognew(@SensorStart, @GX)
repeat
  
  uarts.str(0,string("GyroTest:")) 
  uarts.dec(0,GXV)
  uarts.tx(0,10)
  uarts.tx(0,13)
  waitcnt(clkfreq/10 + cnt)
  

DAT
'--------------------Read the Value from the Sensor-------------------------------------
        org 0
SensorStart              OR DIRA, ADISout       'Set Appropriate Pins to Outputs
                         ANDN DIRA, ADISDin     'Set Appropriate Pins to Inputs
Sensor                   RDLONG R0, PAR         'Read in the Parameter to read from sensor 
                         OR OUTA, ADISCS        'Set CS High
                         OR OUTA, ADISCLK       'Set Clk High
                         CALL #Delay            'Delay
                         MOV M1, #01            'Mov mask one
                         ANDN DIRA, ADISCS      'Set CS low
                         CALL #Delay            'Delay
                         MOV Bits, NumberBits   'Set the number of bits to shift
                         SHL R0, #08            'Shift right R0 so room for 16 clks
'This is where the write loop begins to write value to sensor register
ClkOutWrite              MOV R1, R0             'Mov Register value to temp
                         ANDN outa, ADISCS      'Set clk low
                         CALL #Delay            'delay for clock low
                         
                         SHR R1, Bits           'Shift the data right to put bit in LSB
                         AND R1, M1             'Mask all upper bits
                         TJNZ R1, #NZ           'Check to see if one or zero
                         ANDN OUTA, ADISDout    'If it is  zero write a 0 to DOout
                         JMP NextBit            'Jmp over zero condition                          
                      NZ
                         OR OUTA, ADISDout      'If Value is not zero write a 1
                 NextBit
                         OR OUTA, ADISCLK       'Set Clk High to clk out data
                         CALL #Delay            'Delay while Clk is high
                         SUB Bits, #01          'Decriment the shift amount
                         TJNZ Bits, ClkOutWrite 'Fall through if done
                                                'Continue if not yet finished
'This should be the end of the write part of the read command now time to read in value from sensor
                         OR OUTA, ADISCS        'Set CS High 
                         CALL #Delay            'Delay
                         CALL #Delay            'Delay
                         ANDN DIRA, ADISCS      'Set CS low
                         CALL #Delay            'Delay 
                         MOV SenVal, #00        'Clear SenVal                         
                         MOV Bits, #16          'Set number of bits to shift                        
CLKInRead                MOV R0, #00            'Clear R0 
                         ANDN outa, ADISCS      'Set clk low
                         CALL #Delay            'Delay
                         OR OUTA, ADISCLK       'Set Clk High to clk in data 
                         MOV R0, INA            'Read in Data
                         AND R0, ADISDin        'Mask off other pins
                         SHR R0, MaskShift      'Shift all the way to the right
                         SHL R0, Bits           'Shift to proper position
                         OR  SenVal, R0         'Or with Previous data
                         CALL #Delay            'Delay
                         SUB Bits, #01          'Decriment the bit shifter
                         TJNZ Bits, ClkOutWrite 'Fall through if done
                                                 'Loop

                         MOV     R1,par                  ' reset sample pointer
                         ADD     R1, #04                 ' add offset
                         WRWORD  SenVal,R1               ' write sample backto mainram at GXV 
                         JMP #Sensor


Delay                   MOV     T1, CNT        'Delay waits 1000clk ticks 
                        ADD     T1, OneThous
                        WAITCNT T1, OneThous                                                 
Delay_Ret
RET

              'use ANDN to set bit low, use OR to set bit high
              ADISout        Long               %00000000_11100000_00000000_00000000   'Value for 3 output pins Quick
              ADISDin        Long               %00000000_10000000_00000000_00000000   'Mask for Din  P26
              ADISClk        Long               %00000000_01000000_00000000_00000000   'Mask for CLk  P25
              ADISDout       Long               %00000000_00100000_00000000_00000000   'Mask for Dout P24
              ADISCS         Long               %00000000_00010000_00000000_00000000   'Mask for Chip Select  P23
              MaskWrite      Long               %00000000_00010000_00000000_10000000
              OneThous       Long               1000
              NumberBits     Long               16
              SenVal         Long               00
              MaskShift      Long               23
            ' MaskRead       Long            %00000000_00010000_00000000_00000000 all zero  
R0            RES       1
R1            RES       1
R3            RES       1
R4            RES       1
M1            RES       1
T1            RES       1
T2            RES       1
Bits          Res       1
        FIT 496


Post Edited (electric550) : 8/8/2009 8:57:47 AM GMT

Comments

  • Erik FriesenErik Friesen Posts: 1,071
    edited 2009-08-08 13:31
    The # bites again.

    JMP NextBit needs to be JMP #Nextbit

    and TJNZ Bits, #ClkOutWrite
  • electric550electric550 Posts: 122
    edited 2009-08-08 20:00
    Thanks that fixed the locking up problem. Now It is running but it is return 16 ones for 65534 now. So I guess there is some other problem...

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 6_000_000                                  
    
    OBJ 
                                                           
      uarts         : "pcFullDuplexSerial4FC"               '1 COG for 4 serial ports
    
    
    VAR
    
      Long GX, GXV 
    
    Pub ADIS16350 
    'Launch cog to start assembly PinTester
      uarts.Init
      uarts.AddPort(0,31,30,{
    }   UARTS#PINNOTUSED,UARTS#PINNOTUSED,UARTS#DEFAULTTHRESHOLD, {
    }   UARTS#NOMODE,UARTS#BAUD115200)                      'Add debug port
      uarts.Start                                           'Start the ports
    GX := $05
    GXV := 02
    uarts.str(0,string("Starting"))
    cognew(@SensorStart, @GX)
    repeat
      
      uarts.str(0,string("GyroTest:")) 
      uarts.dec(0,GXV)
      uarts.tx(0,10)
      uarts.tx(0,13)
      waitcnt(clkfreq/10 + cnt)
      
    
    DAT
    '--------------------Read the Value from the Sensor-------------------------------------
            org 0
    SensorStart              OR DIRA, ADISout       'Set Appropriate Pins to Outputs
                             ANDN DIRA, ADISDin     'Set Appropriate Pins to Inputs
    Sensor                   RDLONG R0, PAR         'Read in the Parameter to read from sensor 
                             OR OUTA, ADISCS        'Set CS High
                             OR OUTA, ADISCLK       'Set Clk High
                             CALL #Delay            'Delay
                             MOV M1, #01            'Mov mask one
                             ANDN DIRA, ADISCS      'Set CS low
                             CALL #Delay            'Delay
                             MOV Bits, #16          'Set the number of bits to shift
                             SHL R0, #08            'Shift right R0 so room for 16 clks
    'This is where the write loop begins to write value to sensor register
    ClkOutWrite              MOV R1, R0             'Mov Register value to temp
                             ANDN outa, ADISCS      'Set clk low
                             CALL #Delay            'delay for clock low
                             
                             SHR R1, Bits           'Shift the data right to put bit in LSB
                             AND R1, M1             'Mask all upper bits
                             TJNZ R1, #NZ           'Check to see if one or zero
                             ANDN OUTA, ADISDout    'If it is  zero write a 0 to DOout
                             JMP #NextBit            'Jmp over zero condition                          
                          NZ
                             OR OUTA, ADISDout      'If Value is not zero write a 1
                     NextBit
                             OR OUTA, ADISCLK       'Set Clk High to clk out data
                             CALL #Delay            'Delay while Clk is high
                             DJNZ Bits, #ClkOutWrite'Decriment Fall through if done
                                                    'Continue if not yet finished
    'This should be the end of the write part of the read command now time to read in value from sensor
                             OR OUTA, ADISCS        'Set CS High 
                             CALL #Delay            'Delay
                             CALL #Delay            'Delay
                             ANDN DIRA, ADISCS      'Set CS low
                             CALL #Delay            'Delay 
                             MOV SenVal, #00        'Clear SenVal                         
                             MOV Bits, #16          'Set number of bits to shift                        
    CLKInRead                MOV R0, #00            'Clear R0 
                             ANDN outa, ADISCS      'Set clk low
                             CALL #Delay            'Delay
                             OR OUTA, ADISCLK       'Set Clk High to clk in data 
                             MOV R0, INA            'Read in Data
                             AND R0, ADISDin        'Mask off other pins
                             SHR R0, MaskShift      'Shift all the way to the right
                             SHL R0, Bits           'Shift to proper position
                             OR  SenVal, R0         'Or with Previous data
                             CALL #Delay            'Delay
                             DJNZ Bits, #ClkInRead  'Decriment and Fall through if done
                                                    'Loop
                             MOV     R1,par         'reset sample pointer
                             ADD     R1, #04        'add offset
                             WRWORD  SenVal,R1      ' write sample backto mainram at GXV 
                             JMP #Sensor
    
    
    Delay                   MOV     T1, CNT        'Delay waits 1000clk ticks 
                            ADD     T1, OneThous
                            WAITCNT T1, OneThous                                                 
    Delay_Ret
    RET
    
                  'use ANDN to set bit low, use OR to set bit high
    ADISout        Long               %00000000_11100000_00000000_00000000   'Value for 3 output pins Quick
    ADISDin        Long               %00000000_10000000_00000000_00000000   'Mask for Din  P26
    ADISClk        Long               %00000000_01000000_00000000_00000000   'Mask for CLk  P25
    ADISDout       Long               %00000000_00100000_00000000_00000000   'Mask for Dout P24
    ADISCS         Long               %00000000_00010000_00000000_00000000   'Mask for Chip Select  P23
    OneThous       Long               1000
    NumberBits     Long               16
    SenVal         Long               00
    MaskShift      Long               23
    R0            RES       1
    R1            RES       1
    R3            RES       1
    R4            RES       1
    M1            RES       1
    T1            RES       1
    T2            RES       1
    Bits          Res       1
    
    FIT 496
    
    



    Output is ....

    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
    GyroTest:65534
  • TimmooreTimmoore Posts: 1,031
    edited 2009-08-08 20:36
    I dont see where you set clk to an output?
  • electric550electric550 Posts: 122
    edited 2009-08-08 21:17
    Ohh I used the ADISout variable to set all three outputs at once, I did not set them individually

     org 0
    SensorStart              OR DIRA, ADISout       'Set Appropriate Pins to Outputs
                             ANDN DIRA, ADISDin     'Set Appropriate Pins to Inputs
    ....
    ....
    ...
    ....
                  'use ANDN to set bit low, use OR to set bit high
    ADISout        Long               %00000000_11100000_00000000_00000000   'Value for 3 output pins Quick
    ADISDin        Long               %00000000_10000000_00000000_00000000   'Mask for Din  P26
    ADISClk        Long               %00000000_01000000_00000000_00000000   'Mask for CLk  P25
    ADISDout       Long               %00000000_00100000_00000000_00000000   'Mask for Dout P24
    

    Post Edited (electric550) : 8/8/2009 9:22:12 PM GMT
  • TimmooreTimmoore Posts: 1,031
    edited 2009-08-08 21:33
    sure you have the right bits for dout? its in, clk and out?

    The first line sets in/out/clk to an output,
    2nd sets in back to an input
    4th sets cs to high but its not an output - its still an input
    5 sets clk high - its a output so it goes high

    later you set cs back to an input - doyou have a pull down on the pin?

    later you andn outa, dout - was it meant to set in/clk and dout low

    also you have a line commented set clk low but it sets cs low - which is corret?
    ANDN outa, ADISCS 'Set clk low
  • electric550electric550 Posts: 122
    edited 2009-08-08 22:59
    "sure you have the right bits for dout? its in, clk and out?

    The first line sets in/out/clk to an output,
    2nd sets in back to an input
    4th sets cs to high but its not an output - its still an input
    5 sets clk high - its a output so it goes high
    "
    >>>I think I got confused because the names are from the perspective of the sensor, not the prop I change the mask around a little the names are from the perspective of the Propeller now.


    "Later you set cs back to an input - do you have a pull down on the pin?"
    That was supposed to be an outa
    >>>>No pull downs...I think the 5 to 3.3 volts is alright, but I assume you meant that due to the fact that i had things Reversed


    "later you andn outa, dout - was it meant to set in/clk and dout low"
    >>>Looks like I got confused with the names again


    "also you have a line commented set clk low but it sets cs low - which is correct?
    ANDN outa, ADISCS 'Set clk low"
    >>>That was supposed to be CLK ...ANDN outa, ADISCLK


    It is now outputing all zeros but that was definitely helpful Thanks! Here is the updated code.
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 6_000_000                                  
    
    OBJ 
                                                           
      uarts         : "pcFullDuplexSerial4FC"               '1 COG for 4 serial ports
    
    
    VAR
    
      Long GX, GXV 
    
    Pub ADIS16350 
    'Launch cog to start assembly PinTester
      uarts.Init
      uarts.AddPort(0,31,30,{
    }   UARTS#PINNOTUSED,UARTS#PINNOTUSED,UARTS#DEFAULTTHRESHOLD, {
    }   UARTS#NOMODE,UARTS#BAUD115200)                      'Add debug port
      uarts.Start                                           'Start the ports
    GX := $05
    GXV := 02
    uarts.str(0,string("Starting"))
    cognew(@SensorStart, @GX)
    repeat
      
      uarts.str(0,string("GyroTest:")) 
      uarts.dec(0,GXV)
      uarts.tx(0,10)
      uarts.tx(0,13)
      waitcnt(clkfreq/10 + cnt)
      
    
    DAT
    '--------------------Read the Value from the Sensor-------------------------------------
            org 0
    SensorStart              OR DIRA, ADISout       'Set Appropriate Pins to Outputs
                             ANDN DIRA, ADISDin     'Set Appropriate Pin to Input
    Sensor                   RDLONG R0, PAR         'Read in the Parameter to read from sensor 
                             OR OUTA, ADISCS        'Set CS High
                             OR OUTA, ADISCLK       'Set Clk High
                             CALL #Delay            'Delay
                             MOV M1, #01            'Mov mask one
                             ANDN DIRA, ADISCS      'Set CS low
                             CALL #Delay            'Delay
                             MOV Bits, #16          'Set the number of bits to shift
                             SHL R0, #08            'Shift right R0 so room for 16 clks
    'This is where the write loop begins to write value to sensor register
    ClkOutWrite              MOV R1, R0             'Mov Register value to temp
                             ANDN OUTA, ADISCLK     'Set clk low
                             CALL #Delay            'delay for clock low
                             
                             SHR R1, Bits           'Shift the data right to put bit in LSB
                             AND R1, M1             'Mask all upper bits
                             TJNZ R1, #NZ           'Check to see if one or zero
                             ANDN OUTA, ADISDout    'If it is  zero write a 0 to Dout
                             JMP #NextBit           'Jmp over one condition                          
                          NZ
                             OR OUTA, ADISDout      'If Value is not zero write a 1 to Dout
                     NextBit
                             OR OUTA, ADISCLK       'Set Clk High to clk out data
                             CALL #Delay            'Delay while Clk is high
                             DJNZ Bits, #ClkOutWrite'Decriment Bits or Fall through if Bits is zero
                                                    'Continue if not yet finished
    'This should be the end of the write part of the read command now time to read in value from sensor
                             OR OUTA, ADISCS        'Set CS High 
                             CALL #Delay            'Delay
                             CALL #Delay            'Delay
                             ANDN OUTA, ADISCS      'Set CS low
                             CALL #Delay            'Delay 
                             MOV SenVal, #00        'Clear SenVal                         
                             MOV Bits, #16          'Set number of bits to shift                        
    CLKInRead                MOV R0, #00            'Clear R0 
                             ANDN OUTA, ADISCLK     'Set clk low
                             CALL #Delay            'Delay
                             OR OUTA, ADISCLK       'Set Clk High to clk in data 
                             MOV R0, INA            'Read in Data
                             AND R0, ADISDin        'Mask off other pins besides the input pin from the sensor
                             SHR R0, MaskShift      'Shift all the way to the right
                             SHL R0, Bits           'Shift to proper position
                             OR  SenVal, R0         'Or with Previous data
                             CALL #Delay            'Delay
                             DJNZ Bits, #ClkInRead  'Decriment and Fall through if done
                                                    'Loop
                             MOV     R1,par         'reset sample pointer
                             ADD     R1, #04        'add offset
                             WRWORD  SenVal,R1      'write sample backto mainram at GXV 
                             JMP #Sensor
    
    
    Delay                   MOV     T1, CNT        'Delay waits 1000clk ticks 
                            ADD     T1, OneThous
                            WAITCNT T1, OneThous                                                 
    Delay_Ret
    RET
    
                  'use ANDN to set bit low, use OR to set bit high
    ADISout        Long               %00000000_11010000_00000000_00000000   'Value for 3 output pins Quick
    ADISDout       Long               %00000000_10000000_00000000_00000000   'Mask for Dout P23 on prop Din for Sensor
    ADISClk        Long               %00000000_01000000_00000000_00000000   'Mask for CLk  P22
    ADISDin        Long               %00000000_00100000_00000000_00000000   'Mask for Din P21 on Prop. Dout for Sensor
    ADISCS         Long               %00000000_00010000_00000000_00000000   'Mask for Chip Select  P20
    OneThous       Long               1000
    NumberBits     Long               16
    SenVal         Long               00
    MaskShift      Long               23
    R0            RES       1
    R1            RES       1
    R3            RES       1
    R4            RES       1
    M1            RES       1
    T1            RES       1
    T2            RES       1
    Bits          Res       1
    
    FIT 496
    
    


    Now it is outputting all zeros...

    GyroTest:0
    GyroTest:0
    GyroTest:0
    GyroTest:0
    GyroTest:0
    GyroTest:0
    GyroTest:0
    GyroTest:0
    GyroTest:0

    Even though it is not working yet that was very helpful, Thanks Again!, any other suggestions are appreciated!
  • TimmooreTimmoore Posts: 1,031
    edited 2009-08-08 23:42
    1. You still have
    ANDN DIRA, ADISCS 'Set CS low
    on the 8th pasm line.

    2. Also I haven't used the 16350 but I have the 16250 and found reading odd registers give prolems, I suggest yu change
    GX := $05
    to
    GX := $04

    3. Also from figure 3 timing diagram, the data is read by the chip on the falling edge of clk. and you dont have the 1st data output for the 1st falling edge.

    4. also
                             SHR R1, Bits           'Shift the data right to put bit in LSB
                             AND R1, M1             'Mask all upper bits
                             TJNZ R1, #NZ           'Check to see if one or zero
                             ANDN OUTA, ADISDout    'If it is  zero write a 0 to Dout
                             JMP #NextBit           'Jmp over one condition                          
                          NZ
                             OR OUTA, ADISDout      'If Value is not zero write a 1 to Dout
                     NextBit
    
    


    If I am reading this correctly you are outputing msb first.
    look at teh rev instruction you can reverse the bits
    e.g. this reverses the 16 bits, rotates 1 bit into carry and sets adisout bit to the carry bit
    note there is a probelm with adisdout having multiple bits set. but I think your code has the same problem
     rev r1, #16
     rcr r1, #1 nc
     muxc outa, adisdout
    
    


    If you use the above instructions you can remove r1 and just use r0
    I think you need 2 varibles adisdout with just the dout bit set and another with the dira bits sets.

    6. Also I am attached my spin code for the 16250, this may help.
  • electric550electric550 Posts: 122
    edited 2009-08-09 01:03
    Thanks again...line8 got it outa not dira. Where is the can I find the "SPI_Engine" object I am looking on obex, but I cant seem to find it. That way you have suggested looks a bit better I will have to try that out. Oh I was trying to read and write data on the rising edge because it looked like it was in the middle. I will give the falling edge a shot.

    Post Edited (electric550) : 8/9/2009 1:21:40 AM GMT
  • TimmooreTimmoore Posts: 1,031
    edited 2009-08-09 01:30
    Dont remember where spi_engie came from but it was done by Beau, I have attached it

    I looked at the spec again I was wrong about the clk edge. dout is availble upto 100ns after falling edge s rising edge is the time to read it
    Din needs to be stable 24.5ns before the rising edge so the chip is reading input on the rising ege.
  • electric550electric550 Posts: 122
    edited 2009-08-09 04:15
    I switched the reads to occur before the rising edge. So the bits are set by the prop right after the falling edge now, and I also changed the write to a 4...Still all Zeros. I am not sure how to implement the reverse command deal. I think I will try to get that spin code to return some values just to make sure the thing is working. I am having some issues...it is locking up right now, but I will keep working on it Thanks!
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 6_000_000                                  
    
    OBJ 
                                                           
      uarts         : "pcFullDuplexSerial4FC"               '1 COG for 4 serial ports
    
    
    VAR
    
      Long GX, GXV 
    
    Pub ADIS16350 
    'Launch cog to start assembly PinTester
      uarts.Init
      uarts.AddPort(0,31,30,{
    }   UARTS#PINNOTUSED,UARTS#PINNOTUSED,UARTS#DEFAULTTHRESHOLD, {
    }   UARTS#NOMODE,UARTS#BAUD115200)                      'Add debug port
      uarts.Start                                           'Start the ports
    GX := $04
    GXV := 02
    uarts.str(0,string("Starting"))
    cognew(@SensorStart, @GX)
    repeat
      
      uarts.str(0,string("GyroTest:")) 
      uarts.dec(0,GXV)
      uarts.tx(0,10)
      uarts.tx(0,13)
      waitcnt(clkfreq/10 + cnt)
      
    
    DAT
    '--------------------Read the Value from the Sensor-------------------------------------
            org 0
    SensorStart              OR DIRA, ADISDout      'Set Dout to Output
                             OR DIRA, ADISCS        'Set CS to Output
                             OR DIRA, ADISClk       'Set Clk to Output
                             ANDN DIRA, ADISDin     'Set Din to Input
    Sensor                   RDLONG R0, PAR         'Read in the ADIS Parameter to read from sensor 
                             OR OUTA, ADISCS        'Set CS High
                             OR OUTA, ADISCLK       'Set Clk High
                             CALL #Delay            'Delay
                             MOV M1, #01            'Mov mask one
                             ANDN OUTA, ADISCS      'Set CS low
                             CALL #Delay            'Delay
                             MOV Bits, #16          'Set the number of bits to shift
                             SHL R0, #08            'Shift Left R0 so room for 16 clks
    'This is where the write loop begins to write value to sensor register
    ClkOutWrite              MOV R1, R0             'Mov ADIS Register value to R0
                             ANDN OUTA, ADISCLK     'Set clk low    
                             SHR R1, Bits           'Shift the data right to put bit in LSB
                             AND R1, M1             'Mask all upper bits
                             TJNZ R1, #NZ           'Check to see if one or zero
                             ANDN OUTA, ADISDout    'If it is  zero write a 0 to Dout
                             JMP #NextBit           'Jmp over one condition                          
                          NZ
                             OR OUTA, ADISDout      'If Value is not zero write a 1 to Dout
                     NextBit
                             CALL #Delay            'delay for clock low
                          
                             OR OUTA, ADISCLK       'Set Clk High to clk out data
                             CALL #Delay            'Delay while Clk is high
                             DJNZ Bits, #ClkOutWrite'Decriment Bits or Fall through if Bits is zero
                                                    'Continue if not yet finished
    'This should be the end of the write part of the read command now time to read in value from sensor
                             OR OUTA, ADISCS        'Set CS High 
                             CALL #Delay            'Delay
                             CALL #Delay            'Delay
                             ANDN OUTA, ADISCS      'Set CS low
                             CALL #Delay            'Delay 
                             MOV SenVal, #00        'Clear SenVal                         
                             MOV Bits, #16          'Set number of bits to shift                        
    CLKInRead                MOV R0, #00            'Clear R0 
                             ANDN OUTA, ADISCLK     'Set clk low
                             CALL #Delay            'Delay
                             OR OUTA, ADISCLK       'Set Clk High to clk in data 
                             MOV R0, INA            'Read in Data
                             AND R0, ADISDin        'Mask off other pins besides the input pin from the sensor
                             SHR R0, MaskShift      'Shift all the way to the right
                             SHL R0, Bits           'Shift to proper position
                             OR  SenVal, R0         'Or with Previous data
                             CALL #Delay            'Delay
                             DJNZ Bits, #ClkInRead  'Decriment and Fall through if done
                                                    'Loop
                             MOV     R1,par         'reset sample pointer
                             ADD     R1, #04        'add offset
                             WRWORD  SenVal,R1      'write sample backto mainram at GXV 
                             JMP #Sensor
    
    
    Delay                   MOV     T1, CNT        'Delay waits 1000clk ticks 
                            ADD     T1, OneThous
                            WAITCNT T1, OneThous                                                 
    Delay_Ret
    RET
    
                  'use ANDN to set bit low, use OR to set bit high
    ADISDout       Long               %00000000_10000000_00000000_00000000   'Mask for Dout P23 on prop Din for Sensor
    ADISClk        Long               %00000000_01000000_00000000_00000000   'Mask for CLk  P22
    ADISDin        Long               %00000000_00100000_00000000_00000000   'Mask for Din P21 on Prop. Dout for Sensor
    ADISCS         Long               %00000000_00010000_00000000_00000000   'Mask for Chip Select  P20
    OneThous       Long               1000
    NumberBits     Long               16
    SenVal         Long               00
    MaskShift      Long               23
    R0            RES       1
    R1            RES       1
    R3            RES       1
    R4            RES       1
    M1            RES       1
    T1            RES       1
    T2            RES       1
    Bits          Res       1
    
    FIT 496
    
    
  • electric550electric550 Posts: 122
    edited 2009-08-09 05:54
    I'm not sure if I am callin this wrong...but the spin code is not working. It works until it gets to the Shiftout, then it locks up. I had to modify the the "adis 16250" because the compiler gave an error so I added
    CON
    #1,_SHIFTOUT,_SHIFTIN
    #0,mMSBPRE,mLSBPRE,mMSBPOST,mLSBPOST 'Used for SHIFTIN routines
    #4,mLSBFIRST,mMSBFIRST

    and I changed the names in send and receive to match.

    Then When I run
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 6_000_000                                  
    
    OBJ 
                                                           
      uarts         : "pcFullDuplexSerial4FC"               '1 COG for 4 serial ports
      Spi           : "adis16250"  
    
    VAR
    
      Long GX, GXV 
    
    Pub ADIS16350 
    'Launch cog to start assembly PinTester
      uarts.Init
      uarts.AddPort(0,31,30,{
    }   UARTS#PINNOTUSED,UARTS#PINNOTUSED,UARTS#DEFAULTTHRESHOLD, {
    }   UARTS#NOMODE,UARTS#BAUD115200)                      'Add debug port
      uarts.Start                                           'Start the ports
    GX := $05
    GXV := 02
    uarts.str(0,string("Starting"))
    uarts.tx(0,10)
    uarts.tx(0,13)
    Spi.Start(2, 22, 20, 23, 21)
    repeat 
      uarts.str(0,string("LoopStart"))
      GXV := Spi.GetGyro
      uarts.str(0,string("GyroTest:")) 
      uarts.dec(0,GXV)
      uarts.tx(0,10)
      uarts.tx(0,13)
      waitcnt(clkfreq/10 + cnt)
    



    I get

    Starting
    LoopStart


    I dont think the 6MHz would cause a problem. I am not sure what it is I will have to take a look later.
  • TimmooreTimmoore Posts: 1,031
    edited 2009-08-09 06:29
    couple of things - I took your code and it complied without changing adis16250 - so there is a problem somewhere.
    there is a concern if its locking up in shiftout - its clking and reading without waiting for anything external so there shouldn't be a lock up. The only wait is in spi_engine waiting for the pasm code to return and it should always return. Check your shiftin/shiftout the 4th arg must not be 0 or the pasm code will stop its cog.
  • electric550electric550 Posts: 122
    edited 2009-08-09 12:16
    Well the code runs fine now that the I re downloaded the code, it is returning zero when I run the code that I posted above. I am not sure what is going on right now. I will take another look. I can't think of what I would need to change to get the code to work with the 16350 vs the 16250.
  • TimmooreTimmoore Posts: 1,031
    edited 2009-08-09 18:49
    I remember I had a lot of problems getting the 16250 to work reliably but its installed in another system at the moment and I can't try it on the prop.
    I would do a couple of things - double check dout/din pins, the data spec is with respect to the adis16350 but the driver is with respect to the prop so its confusing.
    the other thing to try is change SPI#mMSBPOST in Receive to SPI#mMSBPRE (twice). Looking the spec it seems that the MSB output should be before the clk that shouldn't mean you see 0 though (but may explain the inconsistent output I have had).
    I just looked through the code on the system that is running the adis16250 and the only thing it looks like I changed from the prop code is the reset procedure. I hold the adis16250 in reset for 100ms and wait 200ms after I take it out of reset before I access it. So you may want to try a waitcnt(clkfreq/10 + cnt) after the dira in the start routine of adis16250.
  • electric550electric550 Posts: 122
    edited 2009-08-09 20:21
    I am just running the reset routine to set the pins. I have the Reset connected to 5V. I assumed that I would just keep the chip out of reset all the time. I am not sure if this could be the problem or not. I just tried it at a different frequency and still all zeros....Oh well I will keep lookin at it. Thanks again for the help.
    392 x 342 - 37K
  • TimmooreTimmoore Posts: 1,031
    edited 2009-08-09 20:38
    You should have a 1K resistor inline in the dout from the adis16350 (the adis16350 is outputing 5V which the prop will not like). Also looking at your code you have dout and din the wrong way round
    Spi.Start(2, 22, 20, 23, 21)
    23 is into prop
    21 is out of prop

    but on your diag pin 5 is din on adis16350
    so
    Spi.Start(2, 22, 20, 21, 23)
    and put a 1K resistor between pin 4 of adis16350 and pin 21 of prop rather than a direct connection
  • electric550electric550 Posts: 122
    edited 2009-08-09 21:07
    I have nowtried both pin setups DI/DO and both give zeros back....time to continue the search
  • electric550electric550 Posts: 122
    edited 2009-08-11 22:22
    Are you sure that the code you gave me works? When I run the following code with Pin23 connected to ground, or connected to 5 volts. I still get the same value returned. If it read all zeros and ones I would assume that the value returned would be different...perhaps I did something funny I am not sure. I also tried it on the Pin22 to see if DI and Do were backwards but I got the same results.
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 6_000_000                                  
    
    OBJ 
                                                           
      uarts         : "pcFullDuplexSerial4FC"               '1 COG for 4 serial ports
      Spi           : "adis16250"  
    
    VAR
    
      Long GXV, GXT, GXS 
    
    Pub ADIS16350 
    'Launch cog to start assembly PinTester
      uarts.Init
      uarts.AddPort(0,31,30,{
    }   UARTS#PINNOTUSED,UARTS#PINNOTUSED,UARTS#DEFAULTTHRESHOLD, {
    }   UARTS#NOMODE,UARTS#BAUD115200)                      'Add debug port
      uarts.Start                                           'Start the ports
    uarts.str(0,string("Starting"))
    uarts.tx(0,10)
    uarts.tx(0,13)
    Spi.Start(2, 22, 20, 21, 23)   'Start(_RstPin, _SClkPin, _CSPin, _DIPin, _DOutPin)
    waitcnt(clkfreq/10 + cnt)
    repeat 
      GXV := Spi.GetGyro
      uarts.str(0,string("Gyro:"))
      uarts.dec(0,GXV) 
      uarts.tx(0,10)
      uarts.tx(0,13)
      waitcnt(clkfreq/10 + cnt)
    
    



    Output

    Gyro:0
    Gyro:0
    Gyro:0
    Gyro:0
    Gyro:0
    Gyro:0
    Gyro:0
    Gyro:0


    Even though it is not working thanks again for the help!
  • TimmooreTimmoore Posts: 1,031
    edited 2009-08-11 22:31
    din and dout are from props point of view so you should have connected pin21 to 0/3.3V (not 5V). You need a 1K resistor if you are inputing froma 5V device. The adis16250 ha been on another system for quite a while so I dont remember the state of the driver when it got moved. I believe it was working but dont take that as 100%, it also probably had relability problems because I had to work a while on the other system from getting it to work to working relability.
  • electric550electric550 Posts: 122
    edited 2009-08-11 23:24
    Ok well I will take another look and see if I can find what I am doing wrong. Thanks again.
Sign In or Register to comment.