Skip to content

STM32 CAN filter #5351

Closed
Closed
@pilotak

Description

@pilotak

I would like to set up CAN filtering so that i receive only ID=0xFF0080 and don't care about last byte (0x80) and bytes before so the mask i expect would be MASK=0xFFFF00, but when i run following code and start sending CAN messages I will receive all messages 0xFF00xx, 0xFF01xx, 0xFF05xx etc. however messages below 0xFF00xx are rejected so the filter partly works.

Also as well the handle param in can.filter() doens't work with 0 but works with 14, why is that? is it because it's actualy CAN2 so CAN1 has 0-13 and CAN2 has 14-27?

What am I doing wrong?

#include <mbed.h>
CAN can(PB_12, PB_13);
DigitalOut can_sleep(PB_14, 0);

#define ID   0xFF0080
#define MASK 0xFFFF00

int main()
{
    can.frequency(250000);
    can.mode(CAN::Normal);
    can.filter(ID, MASK, CANExtended, 14);

    // how filters works
    if ( (0x18FF0080 & MASK) == (ID & MASK)) // will pass
        printf("0xFF0080 ok\n");
    else
        printf("0xFF0080 failed\n");

    if ( (0x18FF0580 & MASK) == (ID & MASK)) // will fail
        printf("0FF0580 ok\n");
    else
        printf("0xFF0580 failed\n");

    CANMessage msg;

    while (1) {
        if (can.read(msg)) 
            printf("Message received ID: %X\n", msg.id);

        wait(0.2);
    }
}

Thank you in advance

Description

  • Type: Bug | Question
  • Priority: Minor

Target
STM32

Toolchain:
GCC_ARM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions