Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <mcp_can.h>
  2. #include <SPI.h>
  3. #include "setup.h"
  4.  
  5. MCP_CAN CAN0(10); // Set CS to pin 10
  6.  
  7. void setup()
  8. {
  9. Serial.begin(115200);
  10.  
  11. // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
  12. if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) Serial.println("MCP2515 Initialized OK!");
  13. else Serial.println("Error Initializing MCP2515...");
  14.  
  15. CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
  16. }
  17.  
  18. void loop()
  19. {
  20.  
  21. for(byte x = 0; x<16; x++)
  22. {
  23.  
  24. byte sndStat = CAN0.sendMsgBuf(Devices[x], 0, 8, matrixArray[16][8]);
  25.  
  26. delay(32);
  27. Serial.println();
  28. // send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send
  29. //byte sndStat = CAN0.sendMsgBuf(0x280, 1, 8, data0);
  30. /*if(sndStat == CAN_OK){
  31. Serial.println("Message Sent OK!");
  32. } else {
  33. Serial.println("Error Sending Message...");
  34. }*/
  35. //delay(1); // send data per 1s
  36. }
  37. }
  38. /*********************************************************************************************************
  39. END FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement