SPI and 18F4550


Closed Thread
Results 1 to 11 of 11

Thread: SPI and 18F4550

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: SPI and 18F4550

    Yeah, but that register is in the MCP2515 - you're only assigning values to variables in the PIC, there's currently nothing that transfers the data TO the register in the MCP2515.

    Look at the SPI section of the datasheet for the MCP2515, under Write instruction it says
    The Write instruction is started by lowering the CS pin. The Write instruction is then sent to the MCP2515 followed by the address and at least one byte of data.
    Then, looking at table 12-1 we can see that the Write instruction is (in binary) 00000010 or 2 in decimal. As you can see in your screenshot from the datasheet the adress of the TXBnDLC register(s) in the MCP2515 is $35, $45 and $55 respectively (apparently there's three of them, I haven't read enough yet to understand exactly what they do).

    So to set the first of the TXBnDLC registers you need to shift out the WriteCommand (2), the adress ($35) and the actual data (7). The SPI section of the datasheet also tells us the device supports mode 0,0 and 1,1 and the timing diagram shows that it expects (and sends) MSB first. So, using SHIFTOUT the above would look something like
    Code:
    INCLUDE "modedefs.bas"
    
    Write_Cmd CON %00000010    ' Value for the Write Command
    TXB1DLC CON $35                  ' Adress of the 1st TXBnDLC register in the MCP2515
    
    LOW CS
    SHIFTOUT DataPin, ClkPin, MSBFIRST, [Write_Cmd, TXB1DLC, 7]
    HIGH CS
    The example I linked to earlier and the article gadelhas wrote shows you how to set up and use the MSSP module.

    /Henrik.

  2. #2
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: SPI and 18F4550

    Henrik,

    You've made it a little clearer for me, thanks. I'm going to work with this today to see if I can get it to work. Something is strange with the demo boards I've received from Microchip. I can't erase the chip and even blinking an LED can be a task. I'm not even sure if the program I'm compiling is even getting to the 18F4550 at certain times. When I make the same circuit on a breadboard it doesn't give me any problems so I may have two issues at the same time, which makes things even more difficult.

    Chris

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: SPI and 18F4550

    I'm getting closer. I couldn't figure out what was going on so I pulled out my scope and it seems pretty clear......at least for this step. This is a picture of the scope with a known good program (I'm using the same board for the working program and my program so I know the hardware is good). Yellow is the data and blue is the CS line.

    Name:  Known working CAN data.jpg
Views: 1577
Size:  528.6 KB

    Now look at the scope with my program:

    Name:  My code transmitting CAN data.jpg
Views: 1557
Size:  505.4 KB

    So my signal looks like it's inverted. They speak about this in the BAUDCON, TXSTA and RXSTA settings but I tried adjusting them and it didn't help. Any ideas?

    EDIT - It was under the SSPSTAT.6. The signal is correct now but still no CAN data. At least I'm getting closer......
    Last edited by Christopher4187; - 10th July 2012 at 18:43.

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


    Did you find this post helpful? Yes | No

    Default Re: SPI and 18F4550

    Ok, what exactly are we looking at?
    My guess is the MOSI pin on the PIC (Ch1) and the CS line (Ch2)?

    Without seeing your code it's a bit hard to guess what you're actually doing but what I can say is that BAUDCON, TXSTA and RXSTA (if we're talking about the PIC) are control registers for the USART and has nothing to do with the either the MSSP module or the SHIFTOUT/SHIFTIN - whatever you're actually using. Post the code ;-)

    /Henrik.

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