加入大疆C板例程bsp
This commit is contained in:
45
bsp/boards/bsp_can.c
Normal file
45
bsp/boards/bsp_can.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "bsp_can.h"
|
||||
|
||||
void can_filter_init(void)
|
||||
{
|
||||
CAN_FilterTypeDef can_filter_st;
|
||||
can_filter_st.FilterActivation = ENABLE;
|
||||
can_filter_st.FilterMode = CAN_FILTERMODE_IDMASK;
|
||||
can_filter_st.FilterScale = CAN_FILTERSCALE_32BIT;
|
||||
can_filter_st.FilterIdHigh = 0x0000;
|
||||
can_filter_st.FilterIdLow = 0x0000;
|
||||
can_filter_st.FilterMaskIdHigh = 0x0000;
|
||||
can_filter_st.FilterMaskIdLow = 0x0000;
|
||||
can_filter_st.FilterBank = 0;
|
||||
can_filter_st.FilterFIFOAssignment = CAN_RX_FIFO0;
|
||||
HAL_CAN_ConfigFilter(&hcan1, &can_filter_st);
|
||||
HAL_CAN_Start(&hcan1);
|
||||
HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
|
||||
|
||||
can_filter_st.SlaveStartFilterBank = 14;
|
||||
can_filter_st.FilterBank = 14;
|
||||
HAL_CAN_ConfigFilter(&hcan2, &can_filter_st);
|
||||
HAL_CAN_Start(&hcan2);
|
||||
HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO0_MSG_PENDING);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 发送控制数据
|
||||
* @param[in] can_handle 选择CAN1或CAN2
|
||||
* @param[in] tx_header CAN发送数据header
|
||||
* @param[in] tx_data 发送数据
|
||||
* @return none
|
||||
*/
|
||||
void CAN_SendTxMessage(CanCtrlData_s * can_ctrl_data)
|
||||
{
|
||||
uint32_t send_mail_box;
|
||||
uint8_t cnt = 20; // 重复检测次数
|
||||
|
||||
uint32_t free_TxMailbox =
|
||||
HAL_CAN_GetTxMailboxesFreeLevel(can_ctrl_data->hcan); // 检测是否有空闲邮箱
|
||||
while (free_TxMailbox < 3 && cnt--) { // 等待空闲邮箱数达到3
|
||||
free_TxMailbox = HAL_CAN_GetTxMailboxesFreeLevel(can_ctrl_data->hcan);
|
||||
}
|
||||
HAL_CAN_AddTxMessage(
|
||||
can_ctrl_data->hcan, &can_ctrl_data->tx_header, can_ctrl_data->tx_data, &send_mail_box);
|
||||
}
|
||||
Reference in New Issue
Block a user