// macro to format the timing register value from the timing parameters #define CAN_TIMING(tseg1, tseg2, sjw, brp) (((tseg2-1) & 0x07) << 12) | (((tseg1-1) & 0x0F) << 8) | (((sjw-1) & 0x03) << 6) | ((brp-1) & 0x3F)
/******************************************************************************* * Function Name : CAN_SetTiming * Description : Setup the CAN timing with specific parameters * Input 1 : Time Segment before the sample point position, from 2 to 16 * Input 2 : Time Segment after the sample point position, from 1 to 8 * Input 3 : Synchronisation Jump Width, from 1 to 4 * Input 4 : Baud Rate Prescaler, from 1 to 1024 * Output : None * Return : None * Note : CAN must be in initialization mode *******************************************************************************/ void CAN_SetTiming(u32 tseg1, u32 tseg2, u32 sjw, u32 brp) { CAN->BTR = CAN_TIMING(tseg1, tseg2, sjw, brp); CAN->BRPR = ((brp-1) >> 6) & 0x0F; }