SPI woes


Closed Thread
Results 1 to 6 of 6

Thread: SPI woes

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default SPI woes

    I'm trying to talk to an accelerometer via software SPI, but can't seem to get the SHIFTIN command working.


    Code:
       iSDO = 0
    
         AccRegister = $F
         
         ACC_Chip_SEL = 0
            AccRegister.7 = 1
            AccRegister.6 = 0
           shiftout SDo,SPICL,5,[AccRegister]; 5 is the mode
           shiftin SDI,SPICL,5,[SPIData]
         ACC_Chip_SEL = 1
          
         hserout [cr,lf,hex2 SPIData]

    A screenshot of what I get out of my logic analyzer is at:

    www.charleslinquist.com/SPI.jpg

    The SHIFTOUT command appears to be working well, but the SHIFTIN command shows "0" even though the logic analyzer shows that 0x32 is being returned.
    What am I doing wrong?
    Charles Linquist

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,569


    Did you find this post helpful? Yes | No

    Default Re: SPI woes

    Can you read the state of the SDI-pin manually?
    I'm thinking perhaps there's some other function enabled on that pin preventing it from being read properly. Though if analog functions are enabled the pin usually reads high, not low...
    If you CAN read it manually then that's probably not the case. Are you probing directly at the input pin on the PIC itself and is that PIN actually the correct one? Or are you probing at the output pin of the accelerometer?

    Which PIC are you using?
    Which pins are you using?

    /Henrik.

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: SPI woes

    I'm using a PIC 18F8723 and Pin H.2 for SDI. It is tristated, and the external memory function is turned OFF.
    Charles Linquist

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,569


    Did you find this post helpful? Yes | No

    Default Re: SPI woes

    Hi Charles,
    I can't help thinking it's a hardware issue.
    Can you read the state of pin "manually" and get the correct state, perhaps the input is damaged?
    Are you probing directly on the pin on the PIC, perhaps there's a bad solder joint or PCB track?

    /Henrik.

  5. #5
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default Re: SPI woes

    Maybe I read the manual wrong, but in Mode5 yhr data is clocked on the falling edge (right before the falling edge); which could potentially give you a 0x10 reading (based on your picture). I don't think that directly answers your question, but you may as well make sure you are using the right mode (and the analyzer picture matches that mode).

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: SPI woes

    I found part of the problem: The accelerometer is running at 2.5 V, the PIC is running at 5. I was using a Tiny Logic buffer to do the level shifting. The buffer was a Schmitt trigger type with a 2.2V threshold. The accelerometer output didn't always reach that level and the output didn't toggle reliably. I'm getting data through the buffer now (I raised the accelerometer Vcc to 3V by choosing a different LDO regulator for it). But the data still isn't right. Languer is probably right, and I'll try changing the mode.

    I don't know why the PBP manual can't use normal datasheet terms, such as "the data is sampled on the clock rising edge" or something like that instead of the way they describe it!
    Charles Linquist

Similar Threads

  1. Capture woes...
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd May 2011, 09:36
  2. More Servo Woes
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th May 2009, 09:40
  3. ICD Woes
    By spad13m in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 14th February 2008, 06:56
  4. Still HSEROUT woes
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 11th July 2006, 22:13
  5. SPI on a pic without hardware SPI?
    By modifyit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th April 2006, 14:29

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts