Hi,
I use the CAN Bus Library, Works fine. But I have problems with the extended ID an filtering.
The filter works only with the standard ID. How can I use it for extended IDs?
That’s my code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <HardwareCAN.h>
#define BPIN 0
#define SPIN 1
byte msgD0 ;
uint32_t lastSent = 0;
int count = 1;
int ledState = 0;
int extID = 1;
float cTemp;
float pressure;
union t_tag {byte b[4]; float tempVal;} t;
union p_tag {byte b[4]; float pressVal;} p;
// Instanciation of CAN interface
HardwareCAN canBus(CAN1_BASE);
CanMsg msg ;
// Set the LCD address to 0x3E for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3E, 20, 4);
void CANSetup(void)
{
CAN_STATUS Stat ;
// Initialize CAN module
canBus.map(CAN_GPIO_PB8_PB9);
Stat = canBus.begin(CAN_SPEED_1000, CAN_MODE_NORMAL); // set speed to 1000 kbps
CAN_ID_EXT;
lcd.setCursor(0, 1);
lcd.print("Status: ");
lcd.println(Stat);
canBus.filter(0, 0x00ffee00, 0x1fffffff); // filter don't work for ID 0x00FFEE00
canBus.filter(1, 0x3f, 0x1fffffff); // filter work for ID 0x00FFEE00
canBus.set_irq_mode(); // Use irq mode (recommended), so the handling of incoming messages
Stat = canBus.status();
if (Stat != CAN_OK) {
lcd.println("CAN initialization Failed");
/* Your own error processing here */ ; // Initialization failed
}
}