@@ -30,6 +30,11 @@ static uint32_t can_irq_ids[CAN_NUM] = {0};
30
30
static can_irq_handler irq_handler ;
31
31
32
32
void can_init (can_t * obj , PinName rd , PinName td )
33
+ {
34
+ can_init_freq (obj , rd , td , 100000 );
35
+ }
36
+
37
+ void can_init_freq (can_t * obj , PinName rd , PinName td , int hz )
33
38
{
34
39
CANName can_rd = (CANName )pinmap_peripheral (rd , PinMap_CAN_RD );
35
40
CANName can_td = (CANName )pinmap_peripheral (td , PinMap_CAN_TD );
@@ -80,8 +85,8 @@ void can_init(can_t *obj, PinName rd, PinName td)
80
85
error ("Cannot initialize CAN" );
81
86
}
82
87
83
- // Set initial CAN frequency to 100 kb/s
84
- can_frequency (obj , 100000 );
88
+ // Set initial CAN frequency to requested kb/s
89
+ can_frequency (obj , hz );
85
90
86
91
uint32_t filter_number = (obj -> can == CAN_1 ) ? 0 : 14 ;
87
92
can_filter (obj , 0 , 0 , CANStandard , filter_number );
@@ -227,16 +232,16 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
227
232
} else {
228
233
can -> sTxMailBox [transmitmailbox ].TIR |= ((msg .id << 3 ) | CAN_ID_EXT | msg .type );
229
234
}
230
-
235
+
231
236
/* Set up the DLC */
232
237
can -> sTxMailBox [transmitmailbox ].TDTR &= (uint32_t )0xFFFFFFF0 ;
233
238
can -> sTxMailBox [transmitmailbox ].TDTR |= (msg .len & (uint8_t )0x0000000F );
234
-
239
+
235
240
/* Set up the data field */
236
241
can -> sTxMailBox [transmitmailbox ].TDLR = (((uint32_t )msg .data [3 ] << 24 ) |
237
- ((uint32_t )msg .data [2 ] << 16 ) |
238
- ((uint32_t )msg .data [1 ] << 8 ) |
239
- ((uint32_t )msg .data [0 ]));
242
+ ((uint32_t )msg .data [2 ] << 16 ) |
243
+ ((uint32_t )msg .data [1 ] << 8 ) |
244
+ ((uint32_t )msg .data [0 ]));
240
245
can -> sTxMailBox [transmitmailbox ].TDHR = (((uint32_t )msg .data [7 ] << 24 ) |
241
246
((uint32_t )msg .data [6 ] << 16 ) |
242
247
((uint32_t )msg .data [5 ] << 8 ) |
0 commit comments