Datasheet and register question


Closed Thread
Results 1 to 22 of 22

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Thanks for the help Henrik. I still don't understand it. I've been trying for the past four days and I can't get my variables set up correctly. I've been looking at code on here and other places on the internet and I'm more confused than I was before - most of them are in C. The datasheet seems really confusing to me. I think I've wasted more than 100 hours so far.

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


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    I have a hammer in one hand and the 18F4550, along with the MCP2515 are on my table. It would really provide a lot of stress relief.

    I'm going to scrap this and just go with an 18F with CAN built in.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    The 4550 is quite commonly supported... not only that but the datasheets seem (to me) to be written properly...

    I've not played with CAN, however i (along with a lot of other people on here) know the 4550 very well...

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


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Hi Christopher,
    This may be moot if you've already decided to switch devices but it still seems to me like if you're missing one crucial point. You said that you can't get your variable set up correctly which variables are you talking about here and how do you set them? I don't mean to which values you set them but how do you actually assign your values - whatever value it might be - TO the variable?

    The reason I ask is because I still think you may be missing the point that in order for the MCP2515 to work you need to set IT up - ie assign values to the regsiters that are IN the MCP2515. The MCP2515 is an intelligent device, it's not like a MAX232 which has nothing to set up. When you say variables it sounds as if you're still trying to assign values to variables that you create in the PIC and that won't work.

    Are you using SHIFTOUT to write the values or do you use the MSSP module?

    If it was me I start by making a routine which write values to the MCP2515. Then I'd make a routine which reads values from the MCP2515 to verify that the write routine is working properly.

    Can you post some code of your current attempts?

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Quote Originally Posted by comwarrior
    The 4550 is quite commonly supported... not only that but the datasheets seem (to me) to be written properly...

    I've not played with CAN, however i (along with a lot of other people on here) know the 4550 very well...
    Thank you for your substantive post. It has helped me greatly.

    Are you using SHIFTOUT to write the values or do you use the MSSP module?

    If it was me I start by making a routine which write values to the MCP2515. Then I'd make a routine which reads values from the MCP2515 to verify that the write routine is working properly.

    Can you post some code of your current attempts?
    I'm using the MSSP. I think my commands are getting to the MCP but I'm guessing my problem lies in one of these places:

    CNF1, CNF2, CNF3, SSPCON, SSPSTAT OR BAUDCON. It could be anywhere else too. Basically, the entire program is suspect. Thanks for the help Henrik. Maybe you can spot some issues with what I wrote:

    Code:
    INCLUDE "modedefs.bas"
    '          
    DEFINE OSC 20 
    
    
    '==============================================================================
    '                 SETTINGS
    ' ==============================================================================
               '76543210          '76543210
     TRISA   = %11111111: PORTA = %00000000 
     TRISB   = %00010001: PORTB = %00010000   
     TRISC   = %00000000: PORTC = %00000001
     TRISD   = %11111111: PORTD = %00000000
     TRISE   = %00010000: PORTE = %00010111
     ADCON0  = %00000000
     ADCON1  = %00000000
     ADRESH  = %00000000 
     ADRESL  = %00000000
     CMCON   = %00000000
     SSPSTAT = %11000100      
     SSPCON1 = %10110001 
     BAUDCON = %00001111   
        
    
    '===============================================================================
    '                   Register Mapping                          
    '================================================================================
    
     CANSTAT         CON    $0E
     CANCTRL         CON    $0F
     BFPCTRL         CON    $0C
     TEC             CON    $1C
     REC             CON    $1D
     CNF3            CON    $28
     CNF2            CON    $29
     CNF1            CON    $2A
     CANINTE         CON    $2B
     CANINTF         CON    $2C
     EFLG            CON    $2D
     TXRTSCTRL       CON    $0D
    
    ''  Recieve Filters ''
     RXF0SIDH        CON    $00
     RXF0SIDL        CON    $01
     RXF0EID8        CON    $02
     RXF0EID0        CON    $03
     RXF1SIDH        CON    $04
     RXF1SIDL        CON    $05
     RXF1EID8        CON    $06
     RXF1EID0        CON    $07
     RXF2SIDH        CON    $08
     RXF2SIDL        CON    $09
     RXF2EID8        CON    $0A
     RXF2EID0        CON    $0B
     RXF3SIDH        CON    $10
     RXF3SIDL        CON    $11
     RXF3EID8        CON    $12
     RXF3EID0        CON    $13
     RXF4SIDH        CON    $14
     RXF4SIDL        CON    $15
     RXF4EID8        CON    $16
     RXF4EID0        CON    $17
     RXF5SIDH        CON    $18
     RXF5SIDL        CON    $19
     RXF5EID8        CON    $1A
     RXF5EID0        CON    $1B
    
    '' Receive Masks ''
     RXM0SIDH        CON    $20
     RXM0SIDL        CON    $21
     RXM0EID8        CON    $22
     RXM0EID0        CON    $23
     RXM1SIDH        CON    $24
     RXM1SIDL        CON    $25
     RXM1EID8        CON    $26
     RXM1EID0        CON    $27
    
    '' Tx Buffer 0 ''
     TXB0CTRL        CON    $30
     TXB0SIDH        CON    $31
     TXB0SIDL        CON    $32
     TXB0EID8        CON    $33
     TXB0EID0        CON    $34
     TXB0DLC         CON    $35
     TXB0D0          CON    $36
     TXB0D1          CON    $37
     TXB0D2          CON    $38
     TXB0D3          CON    $39
     TXB0D4          CON    $3A
     TXB0D5          CON    $3B
     TXB0D6          CON    $3C
     TXB0D7          CON    $3D
                             
    '' Tx Buffer 1 ''
     TXB1CTRL        CON    $40
     TXB1SIDH        CON    $41
     TXB1SIDL        CON    $42
     TXB1EID8        CON    $43
     TXB1EID0        CON    $44
     TXB1DLC         CON    $45
     TXB1D0          CON    $46
     TXB1D1          CON    $47
     TXB1D2          CON    $48
     TXB1D3          CON    $49
     TXB1D4          CON    $4A
     TXB1D5          CON    $4B
     TXB1D6          CON    $4C
     TXB1D7          CON    $4D
    
    '' Tx Buffer 2 ''
     TXB2CTRL        CON    $50
     TXB2SIDH        CON    $51
     TXB2SIDL        CON    $52
     TXB2EID8        CON    $53
     TXB2EID0        CON    $54
     TXB2DLC         CON    $55
     TXB2D0          CON    $56
     TXB2D1          CON    $57
     TXB2D2          CON    $58
     TXB2D3          CON    $59
     TXB2D4          CON    $5A
     TXB2D5          CON    $5B
     TXB2D6          CON    $5C
     TXB2D7          CON    $5D
                             
    '' Rx Buffer 0 ''
     RXB0CTRL        CON    $60
     RXB0SIDH        CON    $61
     RXB0SIDL        CON    $62
     RXB0EID8        CON    $63
     RXB0EID0        CON    $64
     RXB0DLC         CON    $65
     RXB0D0          CON    $66
     RXB0D1          CON    $67
     RXB0D2          CON    $68
     RXB0D3          CON    $69
     RXB0D4          CON    $6A
     RXB0D5          CON    $6B
     RXB0D6          CON    $6C
     RXB0D7          CON    $6D
                             
    '' Rx Buffer 1 ''
     RXB1CTRL        CON    $70
     RXB1SIDH        CON    $71
     RXB1SIDL        CON    $72
     RXB1EID8        CON    $73
     RXB1EID0        CON    $74
     RXB1DLC         CON    $75
     RXB1D0          CON    $76
     RXB1D1          CON    $77
     RXB1D2          CON    $78
     RXB1D3          CON    $79
     RXB1D4          CON    $7A
     RXB1D5          CON    $7B
     RXB1D6          CON    $7C
     RXB1D7          CON    $7D
    
    
    '===============================================================================
    '                  Register Bit Masks                             
    '===============================================================================
    
     DLC_0          CON   $00
     DLC_1          CON   $01
     DLC_2          CON   $02
     DLC_3          CON   $03
     DLC_4          CON   $04
     DLC_5          CON   $05
     DLC_6          CON   $06
     DLC_7          CON   $07    
     DLC_8          CON   $08
    
    
    
    '===============================================================================
    ' '                  CAN SPI commands                               
    '===============================================================================
    '
    ' CAN_RESET         $C0
    ' CAN_READ          $03
    MCPWRT              CON       $02
    ' CAN_RTS           $80
    ' CAN_RTS_TXB0      $81
    ' CAN_RTS_TXB1      $82
    ' CAN_RTS_TXB2      $84
    ' CAN_RD_STATUS     $A0
    ' CAN_BIT_MODIFY    $05  
    ' CAN_RX_STATUS     $B0
    ' CAN_RD_RX_BUFF    $90
    ' CAN_LOAD_TX       $40  
    
    '===============================================================================
    '                         ALIAS & MODIFIERS
    '==============================================================================
    CS          VAR PORTB.4             ' CS LINE
    SCLK        VAR PORTB.1             ' CLOCK LINE
    SDI         VAR PORTB.0             ' DATA INPUT LINE
    SDO         VAR PORTC.7             ' DATA OUTPUT LINE
    SENDLED     VAR PORTA.5             ' LED TO INDICATE THE PROGRAM IS IN THE SENDING ROUTINE
    MAINLED     VAR PORTE.2             ' LED TO INDICATE THE PROGRAM IS IN THE MAIN ROUTINE
    INT         VAR PORTB.5             ' INTERRUPT OUTPUT FROM 18F4550
    MCPRST      VAR PORTC.0             ' RESET LINE FOR MCP2515
    SW_LOAD     VAR PORTA.4             ' BUTTON CONNECTED TO 18F4550 TO START SENDING DATA (WHEN IMPLEMENTED)
    
    '===============================================================================
    '                       SOFTWARE VARIABLES
    '===============================================================================
    
    DATAOUT VAR BYTE           'FIRST BYTE OF DATA TO BE SENT
    MCPREG VAR BYTE            'ADDRESS OF FIRST BYTE OF DATA TO BE SENT
    
    '==============================================================================
    '                   RESET MCP2515
    '==============================================================================
    
    LOW MCPRST                 ' COMMAND TO RESET THE MCP2515 (SOFTWARE)
    PAUSE 1
    HIGH MCPRST
    PAUSE 20
    
    '==============================================================================
    '                   INITIALIZE MCP2515
    '==============================================================================
    
    
    LOW CS
    SSPBUF = MCPWRT                 ' COMMAND TO WRITE TO THE MCP2515
    PIR1.3 = 0              
    WHILE PIR1.3=0 :WEND 
    
    MCPREG = CANCTRL                ' PUT THE MCP2515 INTO CONFIGURATION MODE 
    DATAOUT =  %10001010
    GOSUB SENDCANDATA  
    
    MCPREG =   CNF3                 'CNF3 - CONFIGURATION REGISTER 3 
    DATAOUT =  $07
    GOSUB SENDCANDATA
    
    MCPREG =   CNF2                 'CNF2 - CONFIGURATION REGISTER 2 
    DATAOUT =  $BA
    GOSUB SENDCANDATA
    
    MCPREG =   CNF1                 'CNF1 - CONFIGURATION REGISTER 1 
    DATAOUT =  $03
    GOSUB SENDCANDATA
        
    MCPREG =   TXB0SIDL             'TRANSMIT BUFFER 0 FOR SIDL
    DATAOUT =  %10000000    
    GOSUB SENDCANDATA 
    
    MCPREG =   TXB0SIDH             'TRANSMIT BUFFER 0 FOR SIDH
    DATAOUT =  %00000001
    GOSUB SENDCANDATA
        
    MCPREG =   CANCTRL              'PUT THE MCP2515 BACK INTO NORMAL MODE
    DATAOUT =  %00001010
    GOSUB SENDCANDATA
    HIGH CS
    
    
    
    '==============================================================================
    '                   MAIN PROGRAM FOR MCP2515
    '==============================================================================
    
    PROGRAMSTART:
    HIGH SENDLED 
    PAUSE 50
    
     LOW CS
    
    SSPBUF = $02                ' COMMAND TO WRITE TO THE MCP2515
    PIR1.3 = 0              
    WHILE PIR1.3=0 :WEND
    
    MCPREG =   CANINTE         ' DISABLE ALL INTERRUPTS
    DATAOUT =  %00000000
    GOSUB SENDCANDATA
                                
    MCPREG =   TXB0CTRL         ' FLAG THE TRANSMIT BUFFER - - 11=HIGH, 10=MEDIUM, 01=LOW, 00=LOWEST 
    DATAOUT =  %00001011
    GOSUB SENDCANDATA
    
    MCPREG =   TXB0SIDL         ' TRANSMIT BUFFER 0 FOR SIDH 
    DATAOUT =  %00110010    
    GOSUB SENDCANDATA 
    
    MCPREG =   TXB0SIDH        ' TRANSMIT BUFFER 0 FOR SIDH  
    DATAOUT =  %00110001
    GOSUB SENDCANDATA
     
    MCPREG =   TXB0DLC         ' NUMBER OF BYTES TO BE TRANSMITTED IN CAN FRAME  
    DATAOUT =  %00000010
    GOSUB SENDCANDATA
    
    MCPREG =   TXB0D0          ' DATA PACKET FOR BYTE 1 
    DATAOUT =  %00000001
    GOSUB SENDCANDATA
        
    MCPREG =   TXB0D1          'DATA PACKET FOR BYTE 2
    DATAOUT =  %00000100
    GOSUB SENDCANDATA
    
    
    HIGH CS
    
    LOW sendled
    pause 50
    
    
    
    goto PROGRAMSTART
    '===============================================================================
    '                           SEND CAN DATA SECTION
    '===============================================================================
    SENDCANDATA:
    
    SSPBUF = MCPREG          ' ADDRESS TO LOAD THE DATA TO THE MCP2515
    PIR1.3 = 0              
    WHILE PIR1.3=0 : WEND 
    SSPBUF = DATAOUT          'DATA BEING LOADED TO THE MCP2515 ON MCPREG
    PIR1.3 = 0              
    WHILE PIR1.3=0 : WEND
        
     RETURN

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Hi Christopher,
    OK, you're making progress, don't give up!

    You have ADCON1 = 0 which will have all 13 analog pins set as analog, you probably want to turn the analog stuff OFF by setting ADCON1 = 15. For example RB0 and RB1 are AN12 and AN10 respectively but they are also the SDI and SCK pins for the MSSP module - that may or may not be part of the problem.

    You have CMOCON = 0 which will leave both analog comparators ON, to turn them OFF on the 4550 you need to do CMCON = 7 - may or may not be part of the problem depending on exactly which pins they are on and what you're using, or trying to use, them for - I haven't looked into it.

    The MCP2515 SPI timing diagrams show the SPI clock idling LOW. You have SSPCON1.4 set to 1 which will make the clock idle HIGH, ie wrong polarity.

    Well, that's three things I see that may have something to do with it. Try adressing those, then try capturing the signals with your scope and see if they look anything like the timing diagrams in the MCP2515 datasheet.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Jag är trött.....snälla hjälp mig!

    It's 1am here so hopefully this post is clear enough and someone can help me! I've been adjusting settings and trying new things and it still doesn't work. Here is what it boils down to. This is a picture of the working code from Microchip (if I knew C I'd be done already).

    Channel 1 (Yellow) SDO from 18F4550
    Channel 2 (Blue) CS from 18F4550
    Channel 3 (Purple) TXCAN from MCP2515
    Channel 4 (Green) CLK from 18F4550?

    Name:  Microchip code.jpg
Views: 1991
Size:  92.8 KB
    This is what I'm looking to achieve.

    This is what my code looks like:
    Name:  My code.jpg
Views: 1399
Size:  71.4 KB
    At least it's not that much different and I'm in the ballpark. What I can see is the signals are similar but way more compressed. It seems like a timing issue but I really don't know.

    I adjusted the oscilloscope to the same seconds/division as the Microchip example and it's very compressed. It looks like this:Name:  My code with the same division as Microchip.jpg
Views: 1268
Size:  105.1 KB

    I tried adjusting the HSPLL to HS and that seemed to make things a little better but didn't do much as far as a working program. The clock still looks strange when I compare it with the Microchip code.
    Name:  My code with the same division as Microchip but with HS instead of HSPLL.jpg
Views: 1259
Size:  93.4 KB

    The other things I see wrong:

    1. The code I'm using is sending one data packet, along with SIDH and SIDL. I setup Microchip's program to do the same thing. I can't figure out why but my code is sending a lot more than a few bytes of data. In fact, it overloads the demo program that Microchip supplies and shuts it down.

    2. Microchip's code sends the CAN data after the CS line goes high. For some reason, my program sends it halfway through the data transfer and my SDO line and the CAN output line are sending data at the same time. I did it once (send data after the CS line went high) but I can't remember what I did.

    3. I'm confused with the CKE/CKP bits and not sure what I need to set them as. I see this "mode 0,0" advertised in the MCP2515 datasheet but it literally means nothing to me and I'm sure it's pretty important.

    4. Did I properly set my BAUDCON?

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