Hi i'm tryin to make the filtering working on my canbus example sketch, i connected the tensy to the PCAN and the bus is ok i send and receive correctly. I've tryed to setup the 8 filters on the frame 0x002 but i'm still getting all the frames i send to the bus, any idea on what is wrong on the sketch ?
this is what i get from the canbus:
this is the pcan screenshot
Code:
// -------------------------------------------------------------
// CANtest for Teensy 3.1
// by teachop
//
// This test is talking to a single other echo-node on the bus.
// 6 frames are transmitted and rx frames are counted.
// Tx and rx are done in a way to force some driver buffering.
// Serial is used to print the ongoing status.
//
#include <Metro.h>
#include <FlexCAN.h>
Metro sysTimer = Metro(1);// milliseconds
int led = 13;
FlexCAN CANbus(500000);
static CAN_message_t msg,rxmsg;
static uint8_t hex[17] = "0123456789abcdef";
int txCount,rxCount;
unsigned int txTimer,rxTimer;
static CAN_filter_t myFilter;
static CAN_filter_t myMask;
// -------------------------------------------------------------
static void hexDump(uint8_t dumpLen, uint8_t *bytePtr)
{
uint8_t working;
while( dumpLen-- ) {
working = *bytePtr++;
Serial.write( hex[ working>>4 ] );
Serial.write( hex[ working&15 ] );
}
Serial.write('\r');
Serial.write('\n');
}
// -------------------------------------------------------------
void setup(void)
{
Serial.begin(115200);
CANbus.begin(myMask);
pinMode(led, OUTPUT);
digitalWrite(led, 1);
myFilter.id = 0x002;
delay(5000);
Serial.println(F("Hello Teensy 3.1 CAN Test."));
CANbus.setFilter(myFilter,0);
CANbus.setFilter(myFilter,1);
CANbus.setFilter(myFilter,2);
CANbus.setFilter(myFilter,3);
CANbus.setFilter(myFilter,4);
CANbus.setFilter(myFilter,5);
CANbus.setFilter(myFilter,6);
CANbus.setFilter(myFilter,7);
sysTimer.reset();
}
// -------------------------------------------------------------
void loop(void)
{
// service software timers based on Metro tick
if ( sysTimer.check() ) {
if ( txTimer ) {
--txTimer;
}
if ( rxTimer ) {
--rxTimer;
}
}
// if not time-delayed, read CAN messages and print 1st byte
if ( !rxTimer ) {
while ( CANbus.read(rxmsg) ) {
//hexDump( sizeof(rxmsg), (uint8_t *)&rxmsg );
Serial.print(rxmsg.id,HEX);
Serial.print(":");
Serial.print(rxmsg.buf[0],HEX);
Serial.print(":");
Serial.print(rxmsg.buf[1],HEX);
Serial.print(":");
Serial.print(rxmsg.buf[2],HEX);
Serial.print(":");
Serial.print(rxmsg.buf[3],HEX);
Serial.print(":");
Serial.print(rxmsg.buf[4],HEX);
Serial.print(":");
Serial.print(rxmsg.buf[5],HEX);
Serial.print(":");
Serial.print(rxmsg.buf[6],HEX);
Serial.print(":");
Serial.println(rxmsg.buf[7],HEX);
rxCount++;
}
}
// insert a time delay between transmissions
if ( !txTimer ) {
// if frames were received, print the count
if ( rxCount ) {
Serial.write('=');
Serial.print(rxCount);
rxCount = 0;
}
txTimer = 100;//milliseconds
msg.len = 8;
msg.id = 0x222;
for( int idx=0; idx<8; ++idx ) {
msg.buf[idx] = '0'+idx;
}
// send 6 at a time to force tx buffering
txCount = 6;
digitalWrite(led, 1);
Serial.println(".");
while ( txCount-- ) {
CANbus.write(msg);
msg.buf[0]++;
}
digitalWrite(led, 0);
// time delay to force some rx data queue use
rxTimer = 3;//milliseconds
}
}
this is what i get from the canbus:
Code:
Hello Teensy 3.1 CAN Test.
6:0:FF:0:0:0:0:0:0
6:0:FF:0:0:0:0:0:0
6:0:FF:0:0:0:0:0:0
6:0:FF:0:0:0:0:0:0
7:0:0:0:0:0:0:0:0
8:0:0:FF:FF:0:0:0:0
=6.
6:0:FF:0:0:0:0:0:0
6:0:FF:0:0:0:0:0:0
6:0:FF:0:0:0:0:0:0
6:0:FF:0:0:0:0:0:0
7:0:0:0:0:0:0:0:0
8:0:0:FF:FF:0:0:0:0
9:0:0:FF:0:FF:0:0:0
10:0:0:FF:FF:0:0:0:0
11:0:0:FF:0:0:0:0:0
12:0:0:FF:0:0:0:0:0
23:0:0:0:45:0:0:0:0
26:0:0:FF:0:0:0:FF:0
106:0:0:FF:0:0:FF:0:0
146:AA:AA:AA:AA:AA:AA:AA:AA
226:0:0:FF:0:AB:AB:FF:0
261:FF:FF:FF:FF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