@@ -135,12 +135,24 @@ static void _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz
135
135
int ntq = 10000000 / hz ;
136
136
#endif
137
137
138
+ int nominalPrescaler = 1 ;
139
+ // !When the sample point should be lower than 50%, this must be changed to
140
+ // !IS_FDCAN_NOMINAL_TSEG2(ntq/nominalPrescaler), since
141
+ // NTSEG2 and SJW max values are lower. For now the sample point is fix @75%
142
+ while (!IS_FDCAN_NOMINAL_TSEG1 (ntq /nominalPrescaler )){
143
+ nominalPrescaler ++ ;
144
+ if (!IS_FDCAN_NOMINAL_PRESCALER (nominalPrescaler )){
145
+ error ("Could not determine good nominalPrescaler. Bad clock value\n" );
146
+ }
147
+ }
148
+ ntq = ntq /nominalPrescaler ;
149
+
138
150
obj -> CanHandle .Init .FrameFormat = FDCAN_FRAME_CLASSIC ;
139
151
obj -> CanHandle .Init .Mode = FDCAN_MODE_NORMAL ;
140
152
obj -> CanHandle .Init .AutoRetransmission = ENABLE ;
141
153
obj -> CanHandle .Init .TransmitPause = DISABLE ;
142
154
obj -> CanHandle .Init .ProtocolException = ENABLE ;
143
- obj -> CanHandle .Init .NominalPrescaler = 1 ; // Prescaler
155
+ obj -> CanHandle .Init .NominalPrescaler = nominalPrescaler ; // Prescaler
144
156
obj -> CanHandle .Init .NominalTimeSeg1 = ntq * 0.75 ; // Phase_segment_1
145
157
obj -> CanHandle .Init .NominalTimeSeg2 = ntq - 1 - obj -> CanHandle .Init .NominalTimeSeg1 ; // Phase_segment_2
146
158
obj -> CanHandle .Init .NominalSyncJumpWidth = obj -> CanHandle .Init .NominalTimeSeg2 ; // Synchronization_Jump_width
@@ -278,6 +290,19 @@ int can_frequency(can_t *obj, int f)
278
290
int ntq = 10000000 / hz ;
279
291
#endif
280
292
293
+ int nominalPrescaler = 1 ;
294
+ // !When the sample point should be lower than 50%, this must be changed to
295
+ // !IS_FDCAN_DATA_TSEG2(ntq/nominalPrescaler), since
296
+ // NTSEG2 and SJW max values are lower. For now the sample point is fix @75%
297
+ while (!IS_FDCAN_DATA_TSEG1 (ntq /nominalPrescaler )){
298
+ nominalPrescaler ++ ;
299
+ if (!IS_FDCAN_NOMINAL_PRESCALER (nominalPrescaler )){
300
+ error ("Could not determine good nominalPrescaler. Bad clock value\n" );
301
+ }
302
+ }
303
+ ntq = ntq /nominalPrescaler ;
304
+
305
+ obj -> CanHandle .Init .NominalPrescaler = nominalPrescaler ;
281
306
obj -> CanHandle .Init .NominalTimeSeg1 = ntq * 0.75 ; // Phase_segment_1
282
307
obj -> CanHandle .Init .NominalTimeSeg2 = ntq - 1 - obj -> CanHandle .Init .NominalTimeSeg1 ; // Phase_segment_2
283
308
obj -> CanHandle .Init .NominalSyncJumpWidth = obj -> CanHandle .Init .NominalTimeSeg2 ; // Synchronization_Jump_width
0 commit comments