Shop OBEX P1 Docs P2 Docs Learn Events
Trying to understand the SPI object. — Parallax Forums

Trying to understand the SPI object.

sharpiesharpie Posts: 150
edited 2006-12-15 19:43 in Propeller 1
Beau, or anyone... Can someone provide some insight for me on how to use this SPI Engine object?· I'm totally lost, not familiar with SPI at all.· Googled it to death, and still lost..· My device has the MISO, MOSI, SCK, CSB, and DRDY lines like I see others that I read about... But the object doesn't seem to use the same names for the signals?· Dpin,Cpin,SLpin, MSBPRE,LSBPRE,MSBPOST,LSBPOST...· ?· I can guess that maybe Cpin is the clock...· MSB is most significant bit, etc...· I never really used shiftin or out for much when using stamps...·

All I want to do is read an 8bit·value from the device's eeprom at 0x1F..· Maybe later on, expand after I've learned a little about the protocol etc...··But I am stumped and at your mercy.

I guess I should mention I am looking at the demo code below in my attempts..·
CON
    _clkmode = xtal1 + pll16x                           
    _xinfreq = 5_000_000
    #0,MSBPRE,LSBPRE,MSBPOST,LSBPOST                                            'Used for SHIFTIN routines
    #4,LSBFIRST,MSBFIRST                                                        'Used for SHIFTOUT routines
    #0,Dpin,Cpin,SLpin,#8,Bits                                                  'Set Dpin,Cpin,SLpin and Bit constant
    
VAR     long          DataValue
OBJ     SPI     : "SPI Engine"
PUB start
{
                        Once called from Spin, SHIFTIN or SHIFTOUT remains running in its own COG.
                        If SHIFTIN or SHIFTOUT are called with 'Bits' set to Zero, then the COG will shut
                        down.  Another way to shut the COG down is to call 'stop' from Spin.
}          
'------------------------------------------------------------------------------------------------------------------------------
    DataValue := %00011111                                                      'DEBUG - Test value
    SPI.SHIFTOUT(Dpin, Cpin, MSBFIRST, Bits, DataValue)                         'Send SHIFTOUT DataVAlue
    
                                                                                'DEBUG - Tested with 74HCT164
                                                                                '        for MSBFIRST and LSBFIRST functions
'------------------------------------------------------------------------------------------------------------------------------
    dira[noparse][[/noparse]23..16] := %11111111                                                   'DEBUG - Make ALL LED's outputs
    dira[noparse][[/noparse]SLpin] := %1                                                           'Set Shift / Load pin as an output
    repeat
      outa[noparse][[/noparse]SLpin] := %1                                                         'Set Shift / Load pin in shift mode "1"
      DataValue := SPI.SHIFTIN(Dpin, Cpin, MSBPRE, Bits)                        'Get SHIFTIN DataValue
      outa[noparse][[/noparse]SLpin] := %0                                                         'Set Shift / Load pin in load mode "0"
      
      outa[noparse][[/noparse]23..16] := DataValue                                                 'DEBUG - Lightup the LED's corresponding to the data
                                                                                '        LED23 = MSB
                                                                                '        LED16 = LSB

Post Edited (sharpie) : 12/14/2006 6:37:41 AM GMT

Comments

  • sharpiesharpie Posts: 150
    edited 2006-12-14 08:11
    So, I know I am grasping for straws..· But I tried the following and it does nothing impressive for me..· Whatever I put in the shiftout last gets returned, whether the device is present or not.. Not a good sign I'll assume.·
      repeat
        repeat 10
    '      outa[noparse][[/noparse]SLpin] := %1                                                         'Set Shift / Load pin in shift mode "1"
          SPI.SHIFTOUT(4, 5, MSBFIRST, 8, %00101001)                         'Send SHIFTOUT DataVAlue
          waitcnt(100_000+cnt)
          SPI.SHIFTOUT(4, 5, MSBFIRST, 8, %00000101)                         'Send SHIFTOUT DataVAlue
          waitcnt(100_000+cnt)
          DataValue := SPI.SHIFTIN(3, 5, MSBFIRST, 8)                        'Get SHIFTIN DataValue
    '      outa[noparse][[/noparse]SLpin] := %0                                                         'Set Shift / Load pin in load mode "0"      
    '      outa[noparse][[/noparse]23..16] := DataValue                                                 'DEBUG - Lightup the LED's corresponding to the data
          t.bin(DataValue,8)
          t.str(string(13))
        waitcnt(10_000_000+cnt)
        t.out($00)
    

    I guess part of what I'm not understanding is how I specify what address and bits I am writing..·

    The datasheet provides an example of a read operation as:

    Write 0x29 in direct register ADDPTR (0x02)

    Write 0x05 in direct register OPERATION (0x03)

    Wait 15ms(minimum)

    Read direct register DATARD8 (0x1F), the register content is in bits [noparse][[/noparse]7:0]





    Help!!! Please!!!
  • parskoparsko Posts: 501
    edited 2006-12-14 08:18
    Sharpie,

    I'm at work, but can give you quick advice. Your eeprom will likely need 4 bytes. 1st is the control, and should at least have "%1010_xxxx", the 1010 part denotes EEproms. The second and third bytes sent are the address bytes of the location you want to read or write. The firth byte is the data you are reading, or writing.

    What hardware (eeprom) are you using?

    I think the I2C object might make it easier. Normally eeproms need to send an ACK bit between the bytes to alert the master (in your case, the Prop) that the previous/last byte was sent and recieved.

    Think about those few important points for a bit. Wikipedia SPI. I was in your boat about 6 months ago, and now I feel like me and SPI are best friends!!! [noparse]:)[/noparse]

    Someone else will come along here and give you more insight. I need to go scan something on an electron microscope now (never done that before!!)

    -Parsko
  • sharpiesharpie Posts: 150
    edited 2006-12-14 08:24
    I am using a SCP1000 Pressure sensor from VTI Technologies. I agree I2C would be easier, but I could only get ahold of the SPI version...
    I will think about your reply for a bit...
    The datasheet is at http://www.vti.fi/midcom-serveattachmentguid-cc8aee01c2fdb69696289d17b704d3d8/SCP1000_Product_Family_Specification_rev_0.07.pdf
    Oh and I've wiki'd it, googled it, I think I'm getting more understanding of the protocol.. just not the implementation on the pchip...
    Thanks for your reply Parsko. That is at least more info than I have.. (I'll assume firth is fifth and not first?)
  • parskoparsko Posts: 501
    edited 2006-12-14 08:31
    www.mct.net/faq/spi.html

    No, I meant forth.

    Just checked the datasheet. Figure 9. Study that, along with the link above. If you want to bit-bang (write your own communication routine), it's not likely going to be ffigured out overnight.

    You should be able to do this with the shiftout command in the BS2functions library. You only need to send 1 6bit command, and recieve your 8 bit back.

    Again, figure 9 is going to be your friend!!!!

    Success!

    -Luke
  • sharpiesharpie Posts: 150
    edited 2006-12-14 08:39
    Thanks, I actually went over that link earlier.. I'll go over it again in greater detail.. I was afraid you'd say figure 9. I really don't want to write my own comm routing =)
    Table 10 and 11 actually just helped me understand a little more about how it works.. I see now that you (I know I wrote this earlier but now I understand it) write 0x29 in the address 0x02, then write the value 0x05 at address 0x03, wait then read 0x1F.. Which sounds great, but now I need to figure out what you are trying to tell me =) Also, I'm not so bright with the hex/binary tidbits... am I correct in assuming 0x29 = 101001 ????

    Thanks for the input, seriously...
  • sharpiesharpie Posts: 150
    edited 2006-12-14 09:18
    Would something like this be more reasonable?
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000
      SCK  = 5
      MOSI = 4
      MISO = 3
      CSB  = 6
      DRDY = 2
      High = 1
      Low  = 0
      Out  = %1
      In   = %0
        
    VAR
    OBJ
            bs2     : "BS2_Functions"
            tv       : "tv_text"
      
    PUB start
      dira[noparse][[/noparse]CSB] := Out
      outa[noparse][[/noparse]CSB] := High
      tv.start(12)
      tv.out($00)
      tv.str(string("Pressure Sensor Test",13,13))
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%10100000,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%11001010,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]CSB] := High
      waitcnt(10_000_000+cnt)    
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%11100000,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%10100000,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]CSB] := High
      waitcnt(100_000_000+cnt)    
      t.bin(BS2.SHIFTIN(MISO,SCK,BS2#MSBPOST,8))
      
    
    

    I'm a little confused about the order of the bits, fig9 shows the order as A5,A4,A3,A2,A1,A0,RB/W and a Zero, then the Data...· And it says the MSB of the words are sent first...· My example above proves my ignorance, so I transposed the numbers...· and sent MSBFIRST..· Is that wrong?·



    Thanks again for the help..· I think I might feel like I'm starting to catch on at least.. at 2.20am... =/
  • parskoparsko Posts: 501
    edited 2006-12-14 13:42
    Sharpie,

    You're probably asleep right now. I'll post a few bits now so I can remember later when I'm home...

    In order to recieve data, you must have three BS2.shiftout and one BS3.shiftin commands, for a total of 4 bytes:
    1st. You need to write the control bit first. There are 4 modes, choose one, probably high speed, ($0x03 = %0000_0011)
    When you write, you will end up sending 2 bytes, the first is the OPERATION bit, the second is the data
    So, you would BS3.shiftout the OPERATION bit "$0x03"
    Then you would BS2.shiftout the OPERATION data, for high speed continuous "$0x0A" (%0000_1010)
    2nd. You need to tell it to send you your data, or the 3rd shiftout and 4th shiftin
    Write to the DATARD8 byte: "0x1F" (%0001_1111)
    Then read the data using BS2.shiftin
    Okay, here it is a bit simplified:
    Write %0000_0011  (BS2.SHIFTOUT(...,%0000_011_1,...)) (NOTE: bit 7 is the read/write bit, 1 for write)
    Write %0000_1010  (BS2.SHIFTOUT(...,%0001_010_1,...))
    Pause for sometime, don't know how long, maybe zero
    Write %0001_1111  (BS2.SHIFTOUT(...,%0011_111_0,...)) (NOTE: bit 7 is the read/write bit, 0 for read)
    Read     (BS2.SHIFTIN(...))
    
    (You also have the CSB pin and delays to deal with)
    
    


    The result you get from the READ step will be your data.

    There are timing issues with this thing, meaning you can't do too much too fast, it seems to want to read at around 1Hz, so if you set it up to do so, that would be best initially.

    From what I read, this seems to be enough to get you reading data. All due respect, you've chosen some tricky hardware to work with.

    I think this is the best I can do for ya!

    -Parsko
  • sharpiesharpie Posts: 150
    edited 2006-12-14 19:01
    Thanks very much Parsko, I am in the office right now but will take all this under advisement and see where it leads.. This is much closer than I was before! I appreciate the input. The sensor is very cool, I knew I was going to have to learn a bit of new stuff.. But I guess I didn't realize the scope! I have tons of incentive to get it to work, it wasn't cheap either..
    Thanks, and I'll let you know if I make any headway! If anyone else has any insight I am all ears!!!

    -thanks
  • parskoparsko Posts: 501
    edited 2006-12-14 21:48
    Sharpie,

    The only thing I'm not so sure on is if you actually need to write to the thing to get it to work. It isn't explicit in the datasheet. I'm not sure if you could just let it "warm up" and then you can read stuff in, without the write. Worth a try...

    -Parsko
  • sharpiesharpie Posts: 150
    edited 2006-12-15 00:00
    As in just perform a shiftin accepting the stream of data?· I did read somewhere in the datasheet that there are several modes it works in..· In continuous measurement mode (which I am hoping is default but haven't figured out yet) - part 2.2.1.1 around figure4 it says the data is refreshed after each measurement.. and then the DRDY line is set high..· and it halts until you clear the DRDY.. In order to clear it you have to read the pressure output data...· And the DRDY must be serviced before the next pressure data update..· =/

    There are apparently other measurement modes, but it looks like you have to configure it to use them..· The triggered mode seems ok, but the module from sparkfun that I bought doesn't give access to the trigger pin.

    I'm going to start working on it now and see what I can find out.. Thanks again!!!· It is greatly appreciated.
  • sharpiesharpie Posts: 150
    edited 2006-12-15 05:41
    Ok.. I've reread your suggestion about 50 times.. Tried about 20 iterations of the code.... I think I have the gist better than before. And I apparently misread part of it while in the office earlier...

    But I am totally still stuck on the idea of the order of bits in the words. The Figure9 shows the order as A5, A4, A3, A2, A1, A0, the Read or Write bit, then a zero bit as the LSB....
    In your example, you have first 0000_011_1... for high speed(0x03) Which is 8 bits, and a 1 on the end to indicate write... but what about the 0 bit for LSB? Also, the order.. is it inversed? Should it be 11000010??? Or 00001110?? Since the 7th bit is the read/write and the 8th is a zero bit...??? ACK! I'm confused!!!
  • parskoparsko Posts: 501
    edited 2006-12-15 07:39
    The first thing to get is that the BS2.shiftout handles the order of bits in a byte, by setting the BS2#MSBFIRST. Just leave your bit as is in the command, let the command sort out the order. Just make sure you specify MSB first.

    second, long deep breathes!!! turn.gif

    Oh, and you're totally right, there is an additional bit of "0" for your LSB, sorry. I missed that one. So, shift everything I suggested left(only when writing the operation bits) and add the trailing "0"

    AND, remember, I think you should need 4 commands (unless it can "warm up"). Regardless, for the reading part of it, you'll need two BS2.... commands:

    TO READ THE DATA
    BS2.shiftout(Operation bit)
    BS2.shiftin(data from x-ducer)

    You might want to try a 16 bit shiftin, since the x-ducer seems to like 16 bits. Cover-your-***, so you can't say you didn't try, that's what I do. In the past, I end up trying about 1000 different things, until that one time I get something right. SAVE-AS, perform a revision change, and keep debuggin!!

    I'm no PRO, so i'm not sure that everything I have said is exactly correct, just my interpretation of the datasheet. burger.gif

    Oh, post some code, keep it simple. Maybe others will be able to help...

    -Parsko
  • sharpiesharpie Posts: 150
    edited 2006-12-15 09:11
    Thanks again..· I took a break, and tried a new approach(which still didn't work)..· But I have got more than all zero's back =/· I did try the 16bit return, should prove useful.·
    I've been studying your posts, and the code listed in this link http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip
    It's in C and meant for a pic... But it shows good examples of communications with the device.· Hasn't helped me figure it out yet, but maybe somebody who knows can see what I'm doing wrong...
    Here's my simplified propeller interpretation..
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000
      SCK  = 5
      MOSI = 4
      MISO = 3
      CSB  = 6
      DRDY = 2
      High = 1
      Low  = 0
      Out  = %1
      In   = %0
        
    VAR
    OBJ
            bs2     : "BS2_Functions"
            tv       : "tv_text"
      
    PUB start
      dira[noparse][[/noparse]CSB] := Out
      dira[noparse][[/noparse]DRDY] := In
    '  outa[noparse][[/noparse]CSB] := High
      bs2.start(20,21)
      tv.start(12)
      tv.out($00)
      tv.str(string("Pressure Sensor Test",13,13))
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%00001010,BS2#MSBFIRST,8)  ' ADDPTR Indirect Register Address
      bs2.shiftout(MOSI,SCK,%00101101,BS2#MSBFIRST,8)  ' 0x2D
      outa[noparse][[/noparse]CSB] := High
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%00000110,BS2#MSBFIRST,8)  ' DATAWR Indirect Register Data
      bs2.shiftout(MOSI,SCK,%00000011,BS2#MSBFIRST,8)  ' 0x03
      outa[noparse][[/noparse]CSB] := High
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%00001110,BS2#MSBFIRST,8)  ' OPERATION Operation Register
      bs2.shiftout(MOSI,SCK,%00000010,BS2#MSBFIRST,8)  ' 0x02
      outa[noparse][[/noparse]CSB] := High
      waitcnt(500_000+cnt)
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%00001110,BS2#MSBFIRST,8)  ' Select High Resolution Mode
      bs2.shiftout(MOSI,SCK,%00001010,BS2#MSBFIRST,8)  ' 0x0A
      outa[noparse][[/noparse]CSB] := High
          
    repeat
      repeat while ina[noparse][[/noparse]DRDY] == low
      tv.out(00)
      if ina[noparse][[/noparse]DRDY] == low
        tv.str(string("LOW",13))
      if ina[noparse][[/noparse]DRDY] == high
        tv.str(string("HIGH",13))
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%01111100,BS2#MSBFIRST,8)  ' 0x1F
      bs2.shiftout(MOSI,SCK,%00000000,BS2#MSBFIRST,8)  ' 0x00
      tv.bin(bs2.shiftin(MISO,SCK,BS2#MSBFIRST,16),16) ' Read next 16bits
      outa[noparse][[/noparse]CSB] := High  
      tv.str(string(13))    
      waitcnt(12_500_000+cnt)    
      
    

    All I get in return from this is 1000000011111111..· I swear, at this point I'd be happy to buy one of these sensors for somebody if they could help me figure this out.!



    Post Edited (sharpie) : 12/15/2006 9:20:32 AM GMT
  • sharpiesharpie Posts: 150
    edited 2006-12-15 10:18
    So, funny thing.. After reading a little more in the datasheet I decided to change the last shiftout and BINGO.. I think I am at least onto something... So I changed the last repeat routine to the following...

    repeat
    repeat while ina[noparse][[/noparse]DRDY] == low
    tv.out(00)
    if ina[noparse][[/noparse]DRDY] == low
    tv.str(string("LOW",13))
    if ina[noparse][[/noparse]DRDY] == high
    tv.str(string("HIGH",13))
    outa[noparse][[/noparse]CSB] := Low
    bs2.shiftout(MOSI,SCK,%10000100,BS2#MSBFIRST,8)
    bs2.shiftout(MOSI,SCK,%00000000,BS2#MSBFIRST,8)
    tmp := bs2.shiftin(MISO,SCK,BS2#MSBFIRST,8)
    tv.dec(tmp)
    tv.str(string(13))
    tv.bin(tmp,8)
    tv.str(string(13))
    outa[noparse][[/noparse]CSB] := High
    waitcnt(10_000_000+cnt)


    And it is returning some values and seems to be responding to air pressure changes... Although it looks a little jittery and the number it returns doesn't mean anything to me yet (I think it's in Pa, but I have to read more on that...).. Anyway... I know I'm not supposed to be converting all 8 bits to the value and the actual value is somewhere around bit123 or something like that..
  • parskoparsko Posts: 501
    edited 2006-12-15 10:25
    In your code above, you only have 3 shiftxxx commands, when (I thinK) you need 4. BUT, if you are getting results, you know you're on to something!!!!! Step one complete. SAVEAS!!!! and onto step 2, figuring out the rest.....

    -Luke
  • sharpiesharpie Posts: 150
    edited 2006-12-15 10:28
    Sorry, I should have posted the whole thing...· Here's what I am using to get the results...
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000
      SCK  = 5
      MOSI = 4
      MISO = 3
      CSB  = 6
      DRDY = 2
      High = 1
      Low  = 0
      Out  = %1
      In   = %0
        
    VAR
    OBJ
            bs2     : "BS2_Functions"
            tv      : "tv_text"
      
    PUB start | tmp
      dira[noparse][[/noparse]CSB] := Out
      dira[noparse][[/noparse]DRDY] := In
    '  outa[noparse][[/noparse]CSB] := High
      bs2.start(20,21)
      tv.start(12)
      tv.out($00)
      tv.str(string("Pressure Sensor Test",13,13))
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%00001010,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%00101101,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]CSB] := High
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%00000110,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%00000011,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]CSB] := High
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%00001110,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%00000010,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]CSB] := High
      waitcnt(500_000+cnt)
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%00001110,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%00001010,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]CSB] := High
          
    repeat
      repeat while ina[noparse][[/noparse]DRDY] == low
      tv.out(00)
      if ina[noparse][[/noparse]DRDY] == low
        tv.str(string("LOW",13))
      if ina[noparse][[/noparse]DRDY] == high
        tv.str(string("HIGH",13))
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%10000100,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%00000000,BS2#MSBFIRST,8)
      tmp := bs2.shiftin(MISO,SCK,BS2#MSBFIRST,8)
      tv.dec(tmp)
      tv.str(string(13))    
      tv.bin(tmp,8)
      tv.str(string(13))    
      outa[noparse][[/noparse]CSB] := High  
      waitcnt(10_000_000+cnt)    
    

    Thanks for the help Parsko..· I'm about·ready to sleep now. =)
  • parskoparsko Posts: 501
    edited 2006-12-15 10:35
    Okay, the CSB is your Chip Select, it stays low the whole conversion. So, you toggle it low, send your 4 shiftxxx commands, then toggle it high. This is done so you can share many of these on the same bus, but simply "Chip Select" which one you want to read.

    Also, make your overall waitcnt longer, like 1 second. I remember reading the throughput to be 1.8Hz...

    Why is there 8 SHIFTxxx commands in your loop?

    -Luke
  • parskoparsko Posts: 501
    edited 2006-12-15 10:39
    Wait, I see. You have two parts, the first is setting and getting your first read. The second is your read loop. I see why you have the 8 shiftxxx commands now...
  • sharpiesharpie Posts: 150
    edited 2006-12-15 19:43
    So, after some more tweaking today... It looks like I got something going that is a real value.. However it looks like the following code gives me the temperature.. So, I am closer.. I just have to figure out what I did to read the temp instead of pressure...· From looking at the code in that zip file, 0x21 looked like the 16bit LSB pressure value.·
    It certainly appears to be temp too, I hold my finger next to the sensor.. the value goes up quick.. pull away and it drops back to around what it was...· soldering iron about an inch away drives it up even quicker.. and then back to around 605..
    Here's what I did to get this.. not much different, just different registers and values...
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000
      SCK  = 5
      MOSI = 4
      MISO = 3
      CSB  = 6
      DRDY = 2
      High = 1
      Low  = 0
      Out  = %1
      In   = %0
        
    VAR
    OBJ
            bs2     : "BS2_Functions"
            tv      : "tv_text"
      
    PUB start | tmp
      dira[noparse][[/noparse]CSB] := Out
      dira[noparse][[/noparse]DRDY] := In
    '  outa[noparse][[/noparse]CSB] := High
      bs2.start(20,21)
      tv.start(12)
      tv.out($00)
      tv.str(string("Pressure Sensor Test",13,13))
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%000011_10,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%00001010,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]CSB] := High
      outa[noparse][[/noparse]CSB] := Low
      bs2.shiftout(MOSI,SCK,%011111_10,BS2#MSBFIRST,8)
      bs2.shiftout(MOSI,SCK,%00000000,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]CSB] := High
      waitcnt(100_000_000+cnt)
          
      repeat
        repeat while ina[noparse][[/noparse]DRDY] == low
          if ina[noparse][[/noparse]DRDY] == low
            tv.str(string("LOW",13))
        tv.out(00)
        if ina[noparse][[/noparse]DRDY] == high
          tv.str(string("HIGH",13))
        outa[noparse][[/noparse]CSB] := Low
    '    bs2.shiftout(MOSI,SCK,%100001_00,BS2#MSBFIRST,8)
        bs2.shiftout(MOSI,SCK,%100001_00,BS2#MSBFIRST,8)
    '    bs2.shiftout(MOSI,SCK,%00000000,BS2#MSBFIRST,8)
        tmp := bs2.shiftin(MISO,SCK,BS2#LSBFIRST,16)
        tv.dec(tmp)
        tv.str(string(13))    
        tv.bin(tmp,16)
        tv.str(string(13))    
        outa[noparse][[/noparse]CSB] := High  
        waitcnt(100_000_000+cnt)    
    
Sign In or Register to comment.