Datasheet and register question


Closed Thread
Results 1 to 22 of 22

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Hi,
    For transfering the actual data to be sent and setting up the packet lenght etc I'd probably try something like this:
    Code:
    CAN_DATA VAR BYTE[8]
    CAN_LENGTH VAR BYTE
    CAN_ID_H VAR BYTE
    CAN_ID_L VAR BYTE
    i VAR BYTE
    
    ' Prepare a message
    ArrayWrite CAN_DATA[$11, $22, $33, $44, $55, $66, $77, $88]  ' Actual data, 8 bytes
    CAN_LENGTH = 8   ' 8 because that's how many bytes we want to transfer
    CAN_ID_H = 0
    CAN_ID_L = 0
    
    GOSUB Transfer_CAN_Data
    
    END
    
    '----Subrotuine to set the packet length, Standard identifiers, load the data to be sent from array and tell MCP2515 to send it when it can (CAN).
    Tranfer_CAN_Data:
    
    	LOW CS					' Select device
    
    	SSPBUF = MCPWRT : PAUSE 1		' Send write command
    	SSPBUF = TXB0SIDL : PAUSE 1		' Select TXB0SIDL register.
    	SSPBUF = CAN_ID_L : PAUSE 1		' Send low byte of standard identifier	
    
    	' Next register is te TXB0SIDH so we can continue spitting out bytes.
    	SSPBUF = CAN_ID_H : PAUSE 1		' Send high byte of standard identifier
    
    	HIGH CS					' Deselect device to end write operation
    	PAUSE 10
    	LOW CS					' Select device
    
    	' Now set the Transmit bufferdata length register
    	SSPBUF = MCPWRT : PAUSE 1		' Send write command
    	SSPBUF = TXB0DLC : PAUSE 1		' Point at register
    	SSPBUF = CAN_LENGTH : PAUSE 1		' Send length of packet
    
    
    
    	' The first databyte register in the TX buffer is located right after the message
    	' length register so we can use the sequential write feature and just keep going
    	' with the actual data.	
    
    	FOR i = 0 to CAN_LENGHT - 1		' Iterate thru the array and transfer
    		SSPBUF = CAN_LENGTH[i]		' one byte at the time
    		PAUSE 1				' Wait for it
    	NEXT
    
    	HIGH CS					' Deselect device to end write operation
    	PAUSE 10
    	LOW CS					' Select device
    
    	' Now the the message lenth is set and the data to be sent is transfered.
    
    	SSPBUF = MCPWRT : PAUSE 1		' Send write command
    	SSPBUF = TXB0CTRL : PAUSE 1		' Transmitt buffer control register
    	SSPBUF = %00001011 : PAUSE 1		' Request message to be sent with highest priority
    
    	' According to the datasheet this does NOT inititare the actual transfer. It politely
    	' tells the MCP2515 that the databuffer is ready and can be sent whent the bus is available.
    
    RETURN
    Now, I don't know about the Standard Identifier, if they need to be set on a message per message basis or if they are like a node adress or something. In the code above they gets set each time which might be unneccessary. I'm also using PAUSE to wait for the MSSP module, looking at the interrupt flag or buffer free flag as you've been doing is obviously better but it cluttered up the overall structure so I used PAUSE for clarity.

    Not saying it'll work but that's what I'd try.

    /Henrik.

  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 still have version 2.5. I think you need 2.6 for arraywrite, correct? I have a program that will only work with 2.5 so I haven't moved past that point yet but it looks like I may need to. Is there a similar command that will work?

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


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Just load the array manually
    Code:
    CAN_DATA[0] = $00
    CAN_DATA[1] = $11
    CAN_DATA[2] = $22
    ' and so on

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


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Something changed and I can't figure out what I did. My waveforms appear to match the Microchip program, except for one. The SDO from the 18F4550 is at 5V instead of 0V. I can't find any reference to change that. The only thing I've found is commands to change the clock signal but nothing for the SDO. Any ideas?

    I'm very close now.

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