资源简介

stm32f407的CAN的通信功能的实现

资源截图

代码片段和文件信息

/**
  ******************************************************************************
  * @file    can.c
  * @brief   This file provides code for the configuration
  *          of the CAN instances.
  ******************************************************************************
  * @attention
  *
  * 

© Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.


  *
  * This software component is licensed by ST under BSD 3-Clause license
  * the “License“; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include “can.h“
#include 

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

CAN_HandleTypeDef hcan1;
CAN_HandleTypeDef hcan2;
CAN_TxHeaderTypeDef TxMessage; //发送缓冲区
CAN_RxHeaderTypeDef RxMessage; //接收缓冲区
HAL_StatusTypeDef  HAL_Status;
uint8_t RxData[8];
uint8_t TxData[8]={0x010x020x030x040x050x060x070x08};
/* CAN1 init function */
void MX_CAN1_Init(void)
{

  hcan1.Instance = CAN1;
  hcan1.Init.Prescaler = 14;
  hcan1.Init.Mode = CAN_MODE_NORMAL;
  hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
  hcan1.Init.TimeSeg1 = CAN_BS1_4TQ;
  hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;
  hcan1.Init.TimeTriggeredMode = DISABLE;
  hcan1.Init.AutoBusOff = DISABLE;
  hcan1.Init.AutoWakeUp = DISABLE;
  hcan1.Init.AutoRetransmission = ENABLE;
  hcan1.Init.ReceiveFifoLocked = DISABLE;
  hcan1.Init.TransmitFifoPriority = DISABLE;
  if (HAL_CAN_Init(&hcan1) != HAL_OK)
  {
    Error_Handler();
  }

}
/* CAN2 init function */
void MX_CAN2_Init(void)
{

  hcan2.Instance = CAN2;
  hcan2.Init.Prescaler = 14;
  hcan2.Init.Mode = CAN_MODE_NORMAL;
  hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ;
  hcan2.Init.TimeSeg1 = CAN_BS1_4TQ;
  hcan2.Init.TimeSeg2 = CAN_BS2_1TQ;
  hcan2.Init.TimeTriggeredMode = DISABLE;
  hcan2.Init.AutoBusOff = DISABLE;
  hcan2.Init.AutoWakeUp = DISABLE;
  hcan2.Init.AutoRetransmission = ENABLE;
  hcan2.Init.ReceiveFifoLocked = DISABLE;
  hcan2.Init.TransmitFifoPriority = DISABLE;
  if (HAL_CAN_Init(&hcan2) != HAL_OK)
  {
    Error_Handler();
  }

}

static uint32_t HAL_RCC_CAN1_CLK_ENABLED=0;

void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle)
{

  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(canHandle->Instance==CAN1)
  {
  /* USER CODE BEGIN CAN1_MspInit 0 */

  /* USER CODE END CAN1_MspInit 0 */
    /* CAN1 clock enable */
    HAL_RCC_CAN1_CLK_ENABLED++;
    if(HAL_RCC_CAN1_CLK_ENABLED==1){
      __HAL_RCC_CAN1_CLK_ENABLE();
    }

    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**CAN1 GPIO Configuration
    PA11     ------> CAN1_RX
    PA12     ------> CAN1_TX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
    GPIO_InitSt

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       8023  2021-01-01 00:06  STM32F407_CubeMX_DEMO\.mxproject

     文件       1607  2021-01-03 13:28  STM32F407_CubeMX_DEMO\Core\Inc\can.h

     文件       1433  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Inc\gpio.h

     文件       2181  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Inc\main.h

     文件      20047  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Inc\stm32f4xx_hal_conf.h

     文件       2232  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Inc\stm32f4xx_it.h

     文件       1465  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Inc\tim.h

     文件       1552  2021-01-03 15:29  STM32F407_CubeMX_DEMO\Core\Inc\usart.h

     文件       9904  2021-01-10 11:22  STM32F407_CubeMX_DEMO\Core\Src\can.c

     文件       2825  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Src\gpio.c

     文件       5836  2021-01-03 16:47  STM32F407_CubeMX_DEMO\Core\Src\main.c

     文件       2409  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Src\stm32f4xx_hal_msp.c

     文件       6900  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Src\stm32f4xx_it.c

     文件      26457  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Core\Src\system_stm32f4xx.c

     文件       2873  2021-01-01 00:06  STM32F407_CubeMX_DEMO\Core\Src\tim.c

     文件       4991  2021-01-03 16:39  STM32F407_CubeMX_DEMO\Core\Src\usart.c

     文件    1349439  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f407xx.h

     文件       9485  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f4xx.h

     文件       3796  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Device\ST\STM32F4xx\Include\system_stm32f4xx.h

     文件      28208  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\cmsis_armcc.h

     文件      56497  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\cmsis_armclang.h

     文件       9014  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\cmsis_compiler.h

     文件      62344  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\cmsis_gcc.h

     文件      28414  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\cmsis_iccarm.h

     文件       1716  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\cmsis_version.h

     文件      97995  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\core_armv8mbl.h

     文件     168914  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\core_armv8mml.h

     文件      42208  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\core_cm0.h

     文件      50464  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\core_cm0plus.h

     文件      43456  2020-12-14 17:06  STM32F407_CubeMX_DEMO\Drivers\CMSIS\Include\core_cm1.h

............此处省略188个文件信息

评论

共有 条评论