Hi,
For transfering the actual data to be sent and setting up the packet lenght etc I'd probably try something like this: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.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
Not saying it'll work but that's what I'd try.
/Henrik.




Bookmarks