I am working on CAN driver for S32K.
I configured the FlexCAN0 with CAN FD disabled.( I just want use CAN 2.0 ...., CAN FD is not required in our application).
I have query is that how I can use and configure the message buffers for CAN 2.0 format ?
Can you please provide me the link or which document you referred to calculate the Bit Timing segments (Prescaler,PROP_SEG,...) ?
Its seems like I am the different values which you calculated. I have referred https://community.nxp.com/docs/DOC-330446
It will help me to calculate the Bit Timing segments for other baud rate also(Like 250kpbs, 1Mbps)
You can use this document https://www.nxp.com/docs/en/application-note/AN1798.pdf
The time segments I sent you were computed with the bitrate calculator from the graphical interface used for configuring the FlexCAN driver (Design Studio with S32 SDK), which approximates the values as it does not take into consideration the bus length and the bus propagation delay. It only considers the PE clock frequency.
thank you i got the example projects for standard CAN (No CAN FD).
the example code is working fine with CLKSRC = 0 (The CAN engine clock source is the oscillator clock = 8Mhz.) I tested on Evaluation Board. I am bale to see the Frame(0x55) on CANalyzer tool.
But I want to use the CLKSRC = 1 (The CAN engine clock source is the peripheral clock.) in our application.
We have below Slow RUN configure clock setting in our application(S32K144).
SCG_RCCR[SCS] = 0011b .........CORE_CLK 48 MHz
SCG_RCCR[DIVCORE] = 0000b .....SYS_CLK 48 MHz
SCG_RCCR[DIVBUS] = 0000b ......BUS_CLK 48 MHz (max freq. in RUN mode)
SCG_RCCR[DIVSLOW] = 0001b .....FLASH_CLK 24 MHz
I did the Bit Timing calculation with below parameters.(I have refer the simple guide FlexCAN bit timing calculation ).
Bit rate = 500k bit per second
Bus length = 10m
Bus propagation delay = 5 x 10-9 s/m
Physical Interface (TJA1040) transmitter plus receiver propagation delay = 150ns at 85C
CPI_clock = 48 MHz
Calculated Bit Timing parameters values are :
NBT = 16
Prescaler = 6
PROP_SEG = 3
PHASE_SEG1 = 6
PHASE_SEG2 = 6
RJW = 4
CTRL1 register update with below value.
CAN0->CTRL1 = CAN_CTRL1_PRESDIV(6) | CAN_CTRL1_RJW(3) | CAN_CTRL1_PSEG1(6) | CAN_CTRL1_PSEG2(6) | CAN_CTRL1_PROPSEG(3) | CAN_CTRL1_CLKSRC(1) | CAN_CTRL1_SMP(1);
With this all setting I getting the CAN signals on Oscilloscope but on CANalyzer i am getting error frames.
Is there any thing wrong in bit timing calculation or clock setting ?
or I have to change any other settings for CLKSRC = 1 ?
The same example code is working fine with CLKSRC = 0 (The CAN engine clock source is the oscillator clock = 8Mz.)
For a bitrate = 500 Kbit/s and a PE clock = 48 MHz, I computed the following time segments:
Prescaler = 5
PROP_SEG = 7
PHASE_SEG1 = 4
PHASE_SEG2 = 1
RJW = 1
But there can be variations of these values that can achieve the same bitrate. Other than that, if the peripheral clock used to source the CAN PE clock is FIRC, the bitrate will not be exactly 500 kbit/s due to the 2% deviation of FIRC.
When the CAN PE clock uses the peripheral clock, this is sourced from the system clock. In order to avoid the above problem, you can set SCS_CLK to use SPLL_CLK (which has a smaller deviation than FIRC).
If you are using Design Studio, please follow the instructions in the attached image.
Thank you for your feedback.
Please can you send me the Link or Path from where I can find the "flexcan_encrypted" example from the S32 SDK ?
I search the in S32K Design studio installation directory but I found so many FlexCAN examples and I am not sure which one I have to use.
Please see the flexcan_encrypted example from the S32 SDK. This demo application initializes the FlexCAN module, then configures two message buffers, one for reception and the other one for transmission. Depending on the occurred event, the application either sends or receives a message. The example uses the FD feature, but in order to disable it and configure the buffers for this case, you have to take care of the following fields related to the FD feature:
- for the module configuration structure (flexcan_user_config_t):
- fd_enable field should be set to false
- payload field should be set to FLEXCAN_PAYLOAD_SIZE_8
- bitrate and bitrate_cbt fields must be configured the same
- for the buffer configuration structure (flexcan_data_info_t):
- data_length must be <= 8
- enable_brs must be set to false
- fd_enable must be set to false