2018-03-27 01:40 AM
Hello, How can ı calculate CANBUS communication boudrate ?
2018-03-28 02:03 AM
Hello, I dont get data with canbus interrupt. Can you help me please? my canbus config function :
void CAN_Config(void)
{ __HAL_RCC_CAN2_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE();// CAN2 RX Pin
GPIO_InitStruct.Pin = GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Alternate = GPIO_AF9_CAN2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);// CAN2 TX Pin
GPIO_InitStruct.Pin = GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Alternate = GPIO_AF9_CAN2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); CAN2_Handle.Instance = CAN2; CAN2_Handle.Init.Prescaler = 56; //56.25 CAN2_Handle.Init.Mode =CAN_MODE_NORMAL; CAN2_Handle.Init.SyncJumpWidth = CAN_SJW_4TQ; CAN2_Handle.Init.TimeSeg1 = CAN_BS1_9TQ; CAN2_Handle.Init.TimeSeg2 = CAN_BS2_6TQ; CAN2_Handle.Init.AutoBusOff = DISABLE; CAN2_Handle.Init.AutoRetransmission = DISABLE; CAN2_Handle.Init.AutoWakeUp = DISABLE; CAN2_Handle.Init.ReceiveFifoLocked = DISABLE; CAN2_Handle.Init.TimeTriggeredMode = DISABLE; CAN2_Handle.Init.TransmitFifoPriority = DISABLE; CAN2_Handle.State = HAL_CAN_STATE_READY;// HAL_CAN_Init(&CAN2_Handle);
if(HAL_CAN_Init(&CAN2_Handle) != HAL_OK) { /* Initialization Error */ Error_Handler(); }CAN2_Filter.FilterBank = 0;
CAN2_Filter.FilterMode = CAN_FILTERMODE_IDMASK; CAN2_Filter.FilterScale = CAN_FILTERSCALE_32BIT; CAN2_Filter.FilterIdHigh = 0x0000; CAN2_Filter.FilterIdLow = 0x0000; CAN2_Filter.FilterMaskIdHigh = 0x0000; CAN2_Filter.FilterMaskIdLow = 0x0000; CAN2_Filter.FilterFIFOAssignment = CAN_RX_FIFO0; CAN2_Filter.FilterActivation = ENABLE; CAN2_Filter.SlaveStartFilterBank = 14;if (HAL_CAN_ConfigFilter(&CAN2_Handle, &CAN2_Filter) != HAL_OK)
{ /* Filter configuration Error */ Error_Handler(); } HAL_CAN_Start(&CAN2_Handle); HAL_CAN_ActivateNotification(&CAN2_Handle, CAN_IT_RX_FIFO0_MSG_PENDING); __HAL_CAN_ENABLE_IT(&CAN2_Handle, CAN_IT_RX_FIFO0_MSG_PENDING); // HAL_NVIC_SetPriority(CAN2_TX_IRQn, 2, 2); HAL_NVIC_SetPriority(CAN2_RX0_IRQn, 0, 0); // HAL_NVIC_SetPriority(CAN2_RX1_IRQn, 1, 1); // HAL_NVIC_EnableIRQ( CAN2_TX_IRQn); HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn);2018-04-03 10:30 AM
CAN2_Handle.Init.Prescaler = 56; //56.25
The comment differ from the used value. Why?
Seems, that you did not have found working values for your bitrate.
Second, you should transmit a message on an open CAN bus with an connected resistor and measure your bitrate in real.
2018-04-05 02:47 AM
Thank you for answered. I solved it. this prescalar = 56