本帖最后由 1156807738 于 2020-4-2 10:32 编辑
各位前辈,请指导下我这个菜**,一直找不到原因。板子是F103ZET6
现象:
USB-CAN连接板子后,通过CANTEXT发送数据给F103,发送成功,但板子一直未进入接收中断。
F103可正常发送数据给上位机软件。
有前辈,有时间可以给看下到底哪的问题吗
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
CarCanInit();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
//unsigned char len;
// unsigned char buf[20] = {1,2,3,4,5,6,7,8,9};
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
// HAL_UART_Transmit(&huart1,buf,20,1000);
// HAL_Delay(1000);
/* USER CODE END WHILE */
#if 1
CAN_RX_FRAME * pxRecFrame = NULL;
CAN_TX_FRAME xTxCarData;
/*
xTxCarData.xTxHeader.StdId = 0x123;
xTxCarData.xTxHeader.IDE = CAN_ID_STD; //标准帧
xTxCarData.xTxHeader.RTR = CAN_RTR_DATA; //数据帧
xTxCarData.xTxHeader.DLC = 4;
xTxCarData.ucData[0] = 0;
xTxCarData.ucData[1] = 1;
xTxCarData.ucData[2] = 2;
xTxCarData.ucData[3] = 3;
PHY_CAN1_TX(&xTxCarData);
HAL_Delay(500);
*/
pxRecFrame = PHY_CAN1_READ();
if(NULL==pxRecFrame)
{
continue;
}
//HAL_UART_Transmit(&huart1,buf,20,1000);
HAL_UART_Transmit(&huart1,pxRecFrame->ucData,4,1000);
PHY_CAN1_FIFO_RELEASE(); //处理结束清空对应的fifo
HAL_Delay(1000);
#endif
}
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
}
void CarCanInit(void)
{
Phy_CanInit(CAN1, CAN_BAUD_50K, &pxCarCan);
Obj_CarCanFilterSet(&hcan1);
HAL_CAN_Start(&hcan1);
}
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
{
if(hcan->Instance==CAN1)
{
/* USER CODE BEGIN CAN1_MspInit 0 */
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE END CAN1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_CAN1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin= GPIO_PIN_12; //PA12
GPIO_InitStruct.Mode=GPIO_MODE_AF_PP; //推挽复用
GPIO_InitStruct.Pull=GPIO_PULLUP; //上拉
GPIO_InitStruct.Speed=GPIO_SPEED_FREQ_HIGH; //高速
HAL_GPIO_Init(GPIOA,&GPIO_InitStruct); //初始化
GPIO_InitStruct.Pin=GPIO_PIN_11; //PA11
GPIO_InitStruct.Mode=GPIO_MODE_AF_INPUT; //推挽复用
HAL_GPIO_Init(GPIOA,&GPIO_InitStruct); //初始化
/* USER CODE BEGIN CAN1_MspInit 1 */
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 2, 0); //仅次于SPI
HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
/* USER CODE END CAN1_MspInit 1 */
}
}
//直接再这里写的中断处理函数,上位机发送数据,不进入这里的中断
void CAN1_RX1_IRQHandler(void)
{
/* USER CODE BEGIN CAN1_RX1_IRQn 0 */
/* USER CODE END CAN1_RX1_IRQn 0 */
PHY_CAN1_RX_IRQ_HANDLER();
/* USER CODE BEGIN CAN1_RX1_IRQn 1 */
/* USER CODE END CAN1_RX1_IRQn 1 */
}
|