AnsweredAssumed Answered

[solved] STM32F373 CAN filters 32bit list add std id

Question asked by Valentin on May 10, 2016
Latest reply on May 10, 2016 by Valentin
Hi there,

I'd like to use the can filters in 32bit list mode and add a std-id to it. Below is part of the code I'm using.
basically my question is whether I can add std ids to a 32bit list-mode filter and how to shift the address bits accordingly?
As per reference manual, the FR1/2 register contents are:
CAN_Filter_Aufbau_32bit.png
[STDID[10:0] EXTID[17:0] IDE RTR 0]
Therefore I need to shift std-ids by 20 digits left if the ide_bit is reset.
Extended ids are shifted 3 digits left. Please have a look at my code snippet below.

Is this the right way to do it? I can't receive any messages this way. Only extended IDs seem to work.


void can_whitelist_add(CAN_HandleTypeDef* canhandle, unsigned long can_id, uint8_t ide_bit, uint8_t assign_fifo) {

    assert_param(assign_fifo == CAN_FIFO0 || assign_fifo == CAN_FIFO1);
    assert_param(can_id > 0 && can_id < 0x3FFFFFFF);

    // ensure ide_bit is either 1 or 0
    ide_bit = ide_bit > 0;

        /*
         * ----------
         * Fresh filter bank
         * ----------
         */
        CAN_FilterConfTypeDef sFilterConfig;
        sFilterConfig.FilterNumber = filter_index;
        sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
        sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
        sFilterConfig.FilterIdHigh = (can_id << (3 + 17 * (1 - ide_bit))) >> 16; // place STD_ID in bits 19:31, EXT_ID in bits 3:31
        sFilterConfig.FilterIdLow = (can_id << (3 + 17 * (1 - ide_bit)));
        sFilterConfig.FilterIdLow ^= (-ide_bit ^ sFilterConfig.FilterIdLow) & (1 << 2); // set / reset IDE bit
        sFilterConfig.FilterMaskIdHigh = 0x0000; //FR2 is empty, set to 0
        sFilterConfig.FilterMaskIdLow = 0x0000; //FR2 is empty, set to 0
        sFilterConfig.FilterFIFOAssignment = assign_fifo;
        sFilterConfig.FilterActivation = ENABLE;
        sFilterConfig.BankNumber = 26; // irrelevant if only using one can controller.

        if (HAL_CAN_ConfigFilter(canhandle, &sFilterConfig) != HAL_OK) {
            static uint8_t error = 0;
            error++;
        }

Outcomes