Advertisement
Guest User

can_dashboard

a guest
Jan 21st, 2020
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. /****************************************************************************
  2. CAN Write Demo for the SparkFun CAN Bus Shield.
  3.  
  4. Written by Stephen McCoy.
  5. Original tutorial available here: http://www.instructables.com/id/CAN-Bus-Sniffing-and-Broadcasting-with-Arduino
  6. Used with permission 2016. License CC By SA.
  7.  
  8. Distributed as-is; no warranty is given.
  9. *************************************************************************/
  10.  
  11. #include <Canbus.h>
  12. #include <defaults.h>
  13. #include <global.h>
  14. #include <mcp2515.h>
  15. #include <mcp2515_defs.h>
  16.  
  17. //********************************Setup Loop*********************************//
  18.  
  19. void setup() {
  20.  
  21.   pinMode(53, OUTPUT);
  22.  
  23.   Serial.begin(9600);
  24.   Serial.println("CAN Write - Testing transmission of CAN Bus messages");
  25.   delay(1000);
  26.  
  27.   if(Canbus.init(CANSPEED_500))  //Initialise MCP2515 CAN controller at the specified speed
  28.     Serial.println("CAN Init ok");
  29.   else
  30.     Serial.println("Can't init CAN");
  31.    
  32.   delay(1000);
  33. }
  34.  
  35. //********************************Main Loop*********************************//
  36.  
  37. void loop()
  38. {
  39.   tCAN message;
  40.  
  41.           message.id = 0x700;//0xDA0; //formatted in HEX
  42.           message.header.rtr = 0;
  43.           message.header.length = 8;//8; //formatted in DEC
  44.     message.data[0] = 0x00;
  45.     message.data[1] = 0x80;
  46.     message.data[2] = 0x00;
  47.     message.data[3] = 0x00; //formatted in HEX
  48.     message.data[4] = 0x00;
  49.     message.data[5] = 0x00;
  50.     message.data[6] = 0x00;
  51.     message.data[7] = 0x00;
  52.  
  53.   mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
  54.   mcp2515_send_message(&message);
  55.  
  56.   delay(200);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement