How to use FLEXCAN RRS?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use FLEXCAN RRS?

Jump to solution
576 Views
SaLan
Contributor II

Hi, If I want to use CTRL2[RRS], how should I configure it? I'm testing whether I can receive remote frames for all ID.So I need to configure it in this way and let the CPU perform the corresponding operations. Could you provide me with an example of using CTRL2[RRS]?

Thank you.

SaLan

Tags (1)
0 Kudos
Reply
1 Solution
444 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@SaLan

I made a demo for your reference, the RRS is set to 1, and will send ID 0x100 frame back if received remote frame with ID 0x105.

Senlent_0-1760346864852.png

View solution in original post

0 Kudos
Reply
10 Replies
551 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@SaLan

I not sure which MCU part number you're using right now, suppose you're using S32K1xx.

So if RRS is set to 1, the highlight explained very clear, it will be treated like data frames but will no automatic generate remote response frames.

Senlent_0-1760177030913.png

 

0 Kudos
Reply
498 Views
SaLan
Contributor II
Yes, I understand. I want to confirm which CS code I should set in order to receive the data correctly.
Here is my code example. Could you please help me identify where the problem lies?
If possible, could you please provide an example of how to correctly receive RRS using SDK?
uint8_t CAN0_RXREMOTE_RRS_Test()
{
uint8_t data[1];
FLEX_CAN0_Config0.is_rx_fifo_needed=false;
FLEX_CAN0_Config0.max_num_mb=32;
FLEX_CAN0_Config0.num_id_filters=FLEXCAN_RX_FIFO_ID_FILTERS_8;
FLEX_CAN0_Config0.transfer_type=FLEXCAN_RXFIFO_USING_INTERRUPTS;
FLEXCAN_DRV_Init(INST_FLEX_CAN0, &FLEX_CAN0_State0, &FLEX_CAN0_Config0);
FLEXCAN_DRV_SetRxMaskType(INST_FLEX_CAN0, FLEXCAN_RX_MASK_GLOBAL);
FLEXCAN_EnterFreezeMode(CAN0);
CAN0->CTRL2 = (CAN0->CTRL2 & ~CAN_CTRL2_EACEN_MASK) | CAN_CTRL2_EACEN(1);
CAN0->CTRL2 = (CAN0->CTRL2 & ~CAN_CTRL2_RRS_MASK) | CAN_CTRL2_RRS(1);

CAN0->RXMGMASK = 0xC0000000;
CAN0->RX14MASK = 0xC0000000;
CAN0->RX15MASK = 0xC0000000;
FLEXCAN_ExitFreezeMode(CAN0);
flexcan_data_info_t RxdataInfo =
{
.data_length = 1U,
.msg_id_type = FLEXCAN_MSG_ID_STD,
.enable_brs = false,
.fd_enable = false,
.fd_padding = 0U,
.is_remote = true
};
for(int i = 0; i<32; i++){
data[0]=i;
FLEXCAN_DRV_ConfigRxMb(INST_FLEX_CAN0, i, &RxdataInfo, i);
}
while(1)
{

/* Define receive buffer */
flexcan_msgbuff_t recvBuff;
for(int i = 0 ; i<32 ; i++)
{
FLEXCAN_DRV_Receive(INST_FLEX_CAN0, i, &recvBuff);
while(FLEXCAN_DRV_GetTransferStatus(INST_FLEX_CAN0, i) == STATUS_BUSY);
PINS_DRV_TogglePins(PTD, (1 << 15));

}

}
}
0 Kudos
Reply
489 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@SaLan

I will take time to make a similar demo for your reference.

Please tell me the IDE and the SDK version you're using right now.

0 Kudos
Reply
486 Views
SaLan
Contributor II

Hi,Senlent

I use S32DS.3.4
Thank you!!

0 Kudos
Reply
472 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@SaLan

RRS bit is set to 0 default, so you can just use this api:

"FLEXCAN_DRV_ConfigRemoteResponseMb(instance, mb_idx, &txMsg);"

Senlent_0-1760339181072.png

If you want to set RRS to 1, then just receive it like normal data frames.

 

 

0 Kudos
Reply
469 Views
SaLan
Contributor II

Hi,Senlent
How can I receive it like normal data frames.
When I set RRS to 1,while(FLEXCAN_DRV_GetTransferStatus(INST_FLEX_CAN0, i) == STATUS_BUSY);not working.
I would like to know when I received this CAN frame.
And after that, I can perform operations such as making judgments.
I need a Demo for receive when RRS = 1 .
Thank you
SaLan

0 Kudos
Reply
445 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@SaLan

I made a demo for your reference, the RRS is set to 1, and will send ID 0x100 frame back if received remote frame with ID 0x105.

Senlent_0-1760346864852.png

0 Kudos
Reply
398 Views
SaLan
Contributor II

Hi Senlent

Thank you for your answer, which has been of great help to me.
I want to set the global mask RTR bit and IDE to receive remote frames. However, I found that using your configuration is not able to receive them.
Then, after I configured RTR=1 in the MB, I was able to only receive remote frames.

Due to the incomplete configuration of the library functions in the SDK for MB and global mask, in reality your example only performs the corresponding logical judgment based on the ID.

As shown in the figure, I used your DEMO. In fact, for both data frames and remote frames, as long as the ID is 0x105, they will be received. I think this is not very rigorous.
My suggestions are as follows:
If you want to accurately receive remote frames, the following configuration is required

/*RRS = 1*/
FLEXCAN_EnterFreezeMode(CAN0);
 
/*Set global mask (IDE and RTR)*/
CAN0->RXMGMASK = 0xC0000000;
CAN0->RX14MASK = 0xC0000000;
CAN0->RX15MASK = 0xC0000000;
 
CAN0->CTRL2 = (CAN0->CTRL2 & ~CAN_CTRL2_EACEN_MASK) | CAN_CTRL2_EACEN(1);
 
/* Enable Global RX masking */
CAN0->CTRL2 = (CAN0->CTRL2 & ~CAN_CTRL2_RRS_MASK) | CAN_CTRL2_RRS(1U);
 
FLEXCAN_ExitFreezeMode(CAN0);
And must set MB(RTR=1).Then you can only receive the remote frames and then perform logical judgment processing.
(The above examples are only applicable to the global mask. If you wish to set a specific MB, you need to configure the corresponding RXIMR.)
0 Kudos
Reply
354 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@SaLan

Global or Individual setting is optional.( you can take a look at this article)

https://community.nxp.com/t5/S32K-Knowledge-Base/S32K1xx-FlexCAN-Mask-Setting-Demo/ta-p/1519753

The demo I made only used the Global mask setting to demonstrate the configuration of RRS bit 1.

 

0 Kudos
Reply
350 Views
SaLan
Contributor II

Hi Senlent
Thank you for your help. I have solved the problem now. The examples of mask also helped me.

Thank you!

SaLan

0 Kudos
Reply