STM32CubeMX STM32F103C8-CAN

 

1- F103C8 BlockBlock

STM32CubeMX STM32F103C8-CAN_第1张图片

CAN 位于APB1 Bus freq=36MHz,

2- STM32CubeMX 中设置

STM32CubeMX STM32F103C8-CAN_第2张图片

CAN baud rate = 500Kbps;

36MHz/72= 500K   ==>   Prescaler * ( Bit_Segment_1 + Bit_Segment_2 + ReSync_Jump_Width)  = 72  ==> 可以设置

Prescaler =12; Bit_Segment_1 = 3; Bit_Segment_2 = 2; ReSync_Jump_Width = 1;

 

Keil-MDK-PACK-install

STM32CubeMX STM32F103C8-CAN_第3张图片

 

 

 

3- CAN发送code

REF:

https://www.cnblogs.com/birdBull/p/10905067.html


		HAL_CAN_Start(&hcan);
		CAN_TxHeaderTypeDef TxHeader;
		uint8_t TxData[8] = {0x23, 0x81, 0x60, 0x00, 0x55, 0x55, 0x08, 0x00};
		uint32_t TxMailbox; 
		uint32_t std_id = 0x601;  

		TxHeader.RTR = CAN_RTR_DATA;
		TxHeader.IDE = CAN_ID_STD;            
		TxHeader.StdId=std_id;
		TxHeader.TransmitGlobalTime = DISABLE;
		TxHeader.DLC = 8;
						
		if (HAL_CAN_AddTxMessage(&hcan, &TxHeader, TxData, &TxMailbox) != HAL_OK)
		{
			 /* Transmission request Error */
			 Error_Handler();
		}

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(STM32CubeMX STM32F103C8-CAN)