How is it possible to implement more mailboxes to receive different CAN messages? No SDK, No RXFIFO

cancel
Showing results for 
Search instead for 
Did you mean: 

How is it possible to implement more mailboxes to receive different CAN messages? No SDK, No RXFIFO

Jump to solution
138 Views
Contributor III

Hi,

I have a problem with the example "S32K144_Project_FlexCAN". In order to no use SDK driver or RX FIFO, how is it possible to modify the code for the reception of four message? The messages that I want to receive have as Identifier:
-0xEE
-0xFE
-0x101
-0x103
 
In the header file FlexCAN.h, I defined the Node B. In the C file FlexCAN.c, I commented the function of transmission because the board s32k144 is the slave that should receive all CAN messages and so it must not transmit any CAN message.
I append my code so that it's easier to find where I make a mistakes

FlexCAN.c

p_decesare_0-1600789635324.pngp_decesare_1-1600789723138.png

p_decesare_2-1600789754794.png

 

I chose as message Buffer 4, 5, 6, 7. But I'm not able to receive any messages.

In the main function

p_decesare_3-1600789809711.png

 

I studied that for the reception of more message I should implement more mailboxes to receive different messages or I could use the individual mask to filter the messages receive and accept more ID in the same mailbox. But in order to implement more mailboxes, where is the problem of my code?
For an important project with a famous automotive industry, I need to implement a code for the reception of more IDs. Where do I wrong?
Thank you
Best regards,
Paola

 

0 Kudos
1 Solution
103 Views
NXP TechSupport
NXP TechSupport

Hi,

 

the link you mentioned does not work for me.

Anyway, RXIMR and RXMGMASK setting you have should be OK. If MCR[IRMQ] is cleared then individual masking registers are not used and masking is based on RXMGMASK, RX14MASK, RX15MASK registers (RX14MASK, RX15MASK is for MB14 and MB15).

So if you have RXMGMASK = 0x1FFFFFFF then there must be exact match between incoming ID and the one programmed in MB ID.

You can rewrite FLEXCAN0_receive_msg to have input parameter saying which MB to read, eg.

 

void FLEXCAN0_receive_msg(uint8_t mbnum)
{
    /*! Receive msg using msg buffer "mbnum"
    * =============================================
    */
    uint8_t j;
    uint32_t dummy; 

    RxCODE = (CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 0] & 0x07000000) >> 24; /* Read CODE field   */
    RxID = (CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 1] & CAN_WMBn_ID_ID_MASK) >>          CAN_WMBn_ID_ID_SHIFT; /* Read ID */
    RxLENGTH = (CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 0] & CAN_WMBn_CS_DLC_MASK) >> CAN_WMBn_CS_DLC_SHIFT; /* Read Message Length */

    for (j=0; j<2; j++)
    { /* Read two words of data (8 bytes) */  
         RxDATA[j] = CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 2 + j];
    }
    RxTIMESTAMP = (CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 0] & 0x000FFFF);
    dummy = CAN0->TIMER; /* Read TIMER to unlock message buffers */
    CAN0->IFLAG1 = 1 << mbnum; /* Clear CAN 0 MB "mbnum" flag without clearing others*/
}

 

BR, Petr

View solution in original post

3 Replies
122 Views
NXP TechSupport
NXP TechSupport

Hi,

 

you need to activate MB for reception, by setting MB's CODE field to 0x4 and specifying if standard or extended ID is expected, that is set/clear IDE bit. Use

CAN0->RAMn[ 4*MSG_BUF_SIZE + 0] = 0x04000000; /* Msg Buf 4, word 0: Enable for reception,                                                                                            CODE=4: MB set to RX inactive, IDE=0: Standard ID */

Do the same for other MBs used.

 

Also you should read MB once its MB flag is set. In your FLEXCAN0_receive_msg you read all MBs each time. Note, reading MB CS word locks this MB, so will not participate in receive process. You unlock it soon by reading another MB CS word or global timer but it can happen message will not be received due to this.

 

BR, Petr

You 

117 Views
Contributor III

Hi @PetrS 

thank you for your help.
In the function void FLEXCAN0_init(void) I write this code:

p_decesare_0-1600864219155.png

where NUM_IDS is 4 -> so from buffer 4 to buffer 7 I wrote 0x04000000 that means CODE equal to 4 and standard ID. 
I saw this post https://community.nxp.com/t5/S32K/FlexCan-S32K142-Need-quot-simple-quot-CAN0-Filters-matching/td-p/1... where the same problem it is discussed. Maybe can you tell me if I wrong the setting of registers RXIMR and RXMGMASK?

You said that:

Also you should read MB once its MB flag is set. In your FLEXCAN0_receive_msg you read all MBs each time. Note, reading MB CS word locks this MB, so will not participate in receive process. You unlock it soon by reading another MB CS word or global timer but it can happen message will not be received due to this.

How can I solve the problem of function void FLEXCAN0_receive_msg(void)? 

Thanks,

Best regards

Paola

0 Kudos
104 Views
NXP TechSupport
NXP TechSupport

Hi,

 

the link you mentioned does not work for me.

Anyway, RXIMR and RXMGMASK setting you have should be OK. If MCR[IRMQ] is cleared then individual masking registers are not used and masking is based on RXMGMASK, RX14MASK, RX15MASK registers (RX14MASK, RX15MASK is for MB14 and MB15).

So if you have RXMGMASK = 0x1FFFFFFF then there must be exact match between incoming ID and the one programmed in MB ID.

You can rewrite FLEXCAN0_receive_msg to have input parameter saying which MB to read, eg.

 

void FLEXCAN0_receive_msg(uint8_t mbnum)
{
    /*! Receive msg using msg buffer "mbnum"
    * =============================================
    */
    uint8_t j;
    uint32_t dummy; 

    RxCODE = (CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 0] & 0x07000000) >> 24; /* Read CODE field   */
    RxID = (CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 1] & CAN_WMBn_ID_ID_MASK) >>          CAN_WMBn_ID_ID_SHIFT; /* Read ID */
    RxLENGTH = (CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 0] & CAN_WMBn_CS_DLC_MASK) >> CAN_WMBn_CS_DLC_SHIFT; /* Read Message Length */

    for (j=0; j<2; j++)
    { /* Read two words of data (8 bytes) */  
         RxDATA[j] = CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 2 + j];
    }
    RxTIMESTAMP = (CAN0->RAMn[ mbnum*MSG_BUF_SIZE + 0] & 0x000FFFF);
    dummy = CAN0->TIMER; /* Read TIMER to unlock message buffers */
    CAN0->IFLAG1 = 1 << mbnum; /* Clear CAN 0 MB "mbnum" flag without clearing others*/
}

 

BR, Petr

View solution in original post