Problem with MSSP module.


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604

    Default Problem with MSSP module.

    Hi,
    I'm working with a SPI flash memory device (SST25VF080B) and I'm having some difficulties with MSSP module.

    I'm trying to write to the status register of the device and this is the subroutine I'm using for that purpose:
    Code:
    SST_WriteStatus:
    PORTB.7 = 1   ' Logic analyzer trig
    PAUSEUS 5
    
        ' First we execute the EWSR instruction to enable writing to the status register.
        SST_CE = 0
        
        SSPBUF = SST_Cmd_EWSR
        GOSUB SST_WaitForSPI
        
        SST_CE = 1
        
        ' Then we execute the WRSR command to actually write the new value to the statusregister.
        SST_CE = 0
        
        SSPBUF = SST_Cmd_WRSR
        GOSUB SST_WaitForSPI
    
        SST_Status = 101010
        'SSPBUF = SST_Status   ' Thru variable
        SSPBUF = 101010    ' Hardcoded
        GOSUB SST_WaitForSPI
    
        SST_CE = 1
    
    PORTB.7 = 0
    RETURN
    The subroutine SST_WaitForSPI consists of the following code:
    Code:
    SST_WaitForSPI:
        While SSPSTAT.0 = 0 : WEND
    RETURN
    I've marked the lines of interest in red in the code above. Here's what's happening:

    When executing the code as it's shown above, ie writing the value 170 (101010) directly to the SSPBUF register everything works as expected which is shown in the following screenshot:
    Name:  3-Working_analyzer.png
Views: 404
Size:  126.6 KB

    As you can see here the ENABLE line is pulled low then the first command (80) in sent. Then there's a pulse on the ENABLE line after which a new command (1) and finally the data (170) is sent. When the last bit is out the ENABLE line goes high. This is all as expected and it works.

    The problem comes when instead of writing 170 directly to SSPBUF I assign it to the variable SST_Status and then write THAT to SSPBUF, what's happening then can be seen here:
    Name:  4-NonWorking_analyzer.png
Views: 489
Size:  125.6 KB

    Here, for whatever reason the ENABLE line goes high BEFORE the data is completely sent. This obviosuly makes the write invalind and not accepted by the device. I admit defeat - I have no idea what's going on.

    The SSPSTAT.0 which I poll in the WaitForSPI subroutine indicates when 8 bits have been shifted IN from the slave device. In this particullar case nothing is, or should be comming in, the MISO-line is idling high. But why does it make a difference if I write a constant or a variable to the SSPBUF register? Why does it think it's received 8 bits? The MISO-line idles high in both cases and there are, as far as I can see, no other difference than SSPBUF being given a value either literally or thru a variable.

    I've tried other values and it behaves exactly the same - when given the value as a constant it works but "thru" a variable it doesn't.

    Any ideas?
    /Henrik.


    EDIT: And again the bloody editor is messing with the code - it's getting REALLY frustrating posting here. The binary values in the code should be 101010 (170) but the editor apparently decides something else for me and I can't change it.

    EDIT2: I can't even write it in the edit comment above it's [Percent sign] [one] [zero] [one] [zero] [one] [zero] [one] [zero].
    Last edited by HenrikOlsson; - 30th December 2011 at 15:02.

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


    Did you find this post helpful? Yes | No

    Default Re: Problem with MSSP module.

    Forgot to mention: 18F25K20 and PBP 3.0.4.4
    Should've editied the post well....you know....

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Problem with MSSP module.

    Hi,
    OK, it LOOKS like a dummy read of SSPBUF before writing the variable to it fixes the problem. The datasheet is fairly clear on this dummyread when expecting valid data - which I don't. And I still don't understand why it makes a difference where the actual value written to SSPBUF is comming from, ie. constant or variable.

    /Henrik.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Problem with MSSP module.

    Totally off the top of my head; maybe the dummy read clears a buffer?

    And this buffer doesn't handle a constant and variable the same way (allocation of space, bit VS byte, etc).

    Robert


    EDIT: Looking over your code again and I just thought of something after seeing the PAUSE. Does the time it takes PBP to access the value stored in a variable interfere with the MSSP module?

    Bear in mind that I have absolutely no clue what a MSSP module eats in wintertime.


    EDIT SOME MORE: Forgot to ask, how are these variables defined?

    SST_Status
    SSPBUF (looks like a BYTE in MSSP section of 18f25k20 datasheet)
    Last edited by Demon; - 5th January 2012 at 02:53.

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