_CAN_func.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. void CAN_READ() {
  2. // If pin 2 is low, read receive buffer
  3. {
  4. CAN0.readMsgBuf(&CANrxId, &CANlen, CANrxBuf); // Read data: len = data length, buf = data byte(s)
  5. Serial.print("#5555CAN_READ read ID: ");
  6. Serial.print(CANrxId, HEX);
  7. Serial.print(" Data: [");Serial.print(CANlen); Serial.print("]");
  8. if(CANlen == CAN_MSG_DATA8_LEN) {
  9. DISPLAY__print_loop(DISPLAY_CURSOR_Y_CHARS_CAN_DEBUG, "CAN RECV DATA", 13, DISPLAY__print_loop_ACTION_ADD ) ;
  10. } //if(CANlen == CAN_MSG_DATA8_LEN) {
  11. for(int i = 0; i<CANlen; i++) // Print each byte of the data
  12. {
  13. if(CANrxBuf[i] < 0x10) // If data byte is less than 0x10, add a leading zero
  14. {
  15. Serial.print("0");
  16. }
  17. Serial.print(CANrxBuf[i], HEX);
  18. Serial.print(" ");
  19. }
  20. Serial.println();
  21. // else Serial.println(" [CAN] [NOT][digitalRead(CAN_INTpin)] ");
  22. }
  23. }