Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <tiny_mcp_can.h>
  2. #include <tinySPI.h>
  3. MCP_CAN CAN0(PB3); // Set CS to pin PB3 Pin no 2 on chip
  4. byte data[8] = {0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8};
  5.  
  6. void setup()
  7. {
  8. pinMode(PB4, OUTPUT);
  9.  
  10. if (CAN0.begin(MCP_ANY, CAN_250KBPS, MCP_16MHZ) == CAN_OK)
  11. {
  12. //Sucsess();
  13. digitalWrite(PB4, HIGH);
  14. delay(2000);
  15. digitalWrite(PB4, LOW);
  16. }
  17. else{
  18. Failure();
  19. Failure();
  20. }
  21. CAN0.setMode(MCP_NORMAL);
  22. }
  23.  
  24. void loop()
  25. {
  26. //byte sndStat = CAN0.sendMsgBuf(0xF2, 0, 8, data);
  27. if (CAN0.sendMsgBuf(5000, 1, 8, data) == CAN_OK) {
  28. //Read();
  29. digitalWrite(PB4, HIGH);
  30. delay(100);
  31. digitalWrite(PB4, LOW);
  32. } else {
  33. //Failure();
  34. delay(100);
  35. }
  36. //delay(100); // send data per 100ms
  37. }
  38.  
  39. #include "tiny_mcp_can.h"
  40.  
  41. #define spi_readwrite SPI.transfer
  42. #define spi_read() spi_readwrite(0x00)
  43.  
  44. void MCP_CAN::mcp2515_reset(void)
  45. {
  46. SPI.begin();//SPISettings(10000000, MSBFIRST, SPI_MODE0));
  47. MCP2515_SELECT(); // digital Write CS low
  48. spi_readwrite(MCP_RESET); // SPI.transfer();
  49. MCP2515_UNSELECT(); // digitalWrite CS High
  50. SPI.end();//Transaction();
  51. delayMicroseconds(10); // just a delay
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement