Guest User

Untitled

a guest
Jul 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <ESP32CAN.h>
  2. #include <CAN_config.h>
  3.  
  4. // do not change the name!
  5. CAN_device_t CAN_cfg;
  6.  
  7. void setup() {
  8. Serial.begin(115200);
  9. Serial.println("hello");
  10.  
  11. CAN_cfg.speed=CAN_SPEED_1000KBPS;
  12. CAN_cfg.tx_pin_id = GPIO_NUM_5;
  13. CAN_cfg.rx_pin_id = GPIO_NUM_4;
  14. CAN_cfg.rx_queue = xQueueCreate(10,sizeof(CAN_frame_t));
  15. ESP32Can.CANInit();
  16. }
  17.  
  18. void loop() {
  19. CAN_frame_t rx_frame;
  20. if(xQueueReceive(CAN_cfg.rx_queue,&rx_frame, 3 * portTICK_PERIOD_MS) == pdTRUE){
  21.  
  22. if(rx_frame.FIR.B.FF == CAN_frame_std)
  23. Serial.println("New standard frame");
  24. else
  25. Serial.println("New extended frame");
  26.  
  27. if(rx_frame.FIR.B.RTR == CAN_RTR){
  28. printf(" RTR from 0x%08x, DLC %d\r\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
  29. }else{
  30. printf(" from 0x%08x, DLC %d\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
  31. for(int i = 0; i < 8; i++){
  32. printf("%x ", rx_frame.data.u8[i]);
  33. }
  34. }
  35. Serial.println();
  36. }
  37. }
Add Comment
Please, Sign In to add comment