Hi Christopher,
OK, hang on a minute.... I may have spotted something here.
Lets take a look at the SPI section of the MCP2515 datasheet again, section 12.5Now let's take a look at your configuration section again, with my comments in it.The Write instruction is started by lowering the CS pin. The Write instruction is then sent to the MCP2515 followed by the adress and then at least one byte of data.So far so good, as far as I can see. Now lets continue where we left off in the datasheet:Code:LOW CS ' The Write instruction is started by lowering the CS pin SSPBUF = mcpwrt ' The Write instruction then sent to the MCP2515 PIR1.3 = 0 ' Wait for it to tranfer WHILE PIR1.3=0 :WEND MCPREG = CANCTRL ' followed by the adress DATAOUT = $08 ' and at least one byte of data. GOSUB SEND_CAN_DATAKeyword here: sequential. Now back to your code again:It is possible to write sequential registers by continuing to clock in data bytes, as long as CS is held low.If I understand this correctly the intention of your code is to write the value $07 to register CNF3 (at adress $28) but since you haven't deasserted the CS line the next byte transfered to the MCP2515 will automatically get written to next adress (right after CANCTRL in this case). So what actually happens is that the value $28 (which is the adress of CNF3) gets written to the register after CANCTRL (CANCTRL is at $0F so $28 will end up at adress $10) and then value $07 gets written to the register after that ($11).Code:SSPBUF = cnf3 ' CNF3 REGISTER PIR1.3 = 0 WHILE PIR1.3=0 :WEND SSPBUF = $07 ' PART OF BAUD RATE PIR1.3 = 0 WHILE PIR1.3=0 :WEND SSPBUF = $BA ' PART OF BAUD RATE PIR1.3 = 0 WHILE PIR1.3=0 :WEND SSPBUF = $03 ' PART OF BAUDRATE PIR1.3 = 0 WHILE PIR1.3=0 :WEND MCPREG = CANCTRL 'PUT THE MCP2515 BACK INTO NORMAL MODE DATAOUT = $0 GOSUB SEND_CAN_DATA high cs
If you intend to write to registers which aren't sequential in the MCP2515 I think you need must deassert the CS line and start all over again: CS low, write instruction, adress, data.
I'd try with the slowest SPI clock possible to begin with. Ie SSPM3:SSPM0 = 0010
/Henrik.




Bookmarks