• diki5460
    了解作者
  • C/C++
    开发工具
  • 301KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 3
    下载次数
  • 2018-05-28 15:12
    上传日期
STM32F10单片机CAN底层驱动
STM32F10-CAN.zip
  • 创程logo标准色透明背景.png
    44.3KB
  • 创程logo标准色横版透明背景.png
    54.8KB
  • 创程车联logo-横版.JPG
    30.9KB
  • can_driver.h
    4.2KB
  • 创程纵版logo2.0(1).jpg
    221.5KB
  • can_driver.c
    25KB
内容介绍
#include "stm32f10x.h" #include "board.h" #include "can_driver.h" #include "stm32f10x_can.h" #include "can.h" #include "printf.h" /* CAN1_REMAP */ #define CAN1_GPIO_TX GPIO_Pin_9 #define CAN1_TX_PIN_SOURCE GPIO_PinSource12 #define CAN1_GPIO_RX GPIO_Pin_8 //#define CAN1_RX_PIN_SOURCE GPIO_PinSource11 #define CAN1_GPIO GPIOB #define CAN1_GPIO_RCC RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO #define RCC_APBPeriph_CAN1 RCC_APB1Periph_CAN1 /* CAN2_REMAP */ #define CAN2_GPIO_TX GPIO_Pin_13 #define CAN2_TX_PIN_SOURCE GPIO_PinSource13 #define CAN2_GPIO_RX GPIO_Pin_12 #define CAN2_RX_PIN_SOURCE GPIO_PinSource12 #define CAN2_GPIO GPIOB #define CAN2_GPIO_RCC RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO #define RCC_APBPeriph_CAN2 RCC_APB1Periph_CAN2 /* STM32 CAN driver */ struct stm32_can { CAN_TypeDef* can_device; IRQn_Type irq[4]; }; struct stm32_can can1_driver = { CAN1, {CAN1_TX_IRQn, CAN1_RX0_IRQn, CAN1_RX1_IRQn, CAN1_SCE_IRQn} }; struct rt_can_device can1_device; can_queue_t can1_rx_queue; struct stm32_can can2_driver = { CAN2, {CAN2_TX_IRQn, CAN2_RX0_IRQn, CAN2_RX1_IRQn, CAN2_SCE_IRQn} }; struct rt_can_device can2_device; can_queue_t can2_rx_queue; static void RCC_Configuration(void) { /* Enable CAN1 GPIO clocks */ RCC_APB2PeriphClockCmd(CAN1_GPIO_RCC, ENABLE); /* Enable CAN1 clock */ RCC_APB1PeriphClockCmd(RCC_APBPeriph_CAN1, ENABLE); /* Enable CAN2 GPIO clocks */ RCC_APB2PeriphClockCmd(CAN2_GPIO_RCC, ENABLE); /* Enable CAN2 clock */ RCC_APB1PeriphClockCmd(RCC_APBPeriph_CAN2, ENABLE); } static void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; //初始化CAN1 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Pin = CAN1_GPIO_RX; GPIO_Init(CAN1_GPIO, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = CAN1_GPIO_TX; GPIO_Init(CAN1_GPIO, &GPIO_InitStructure); GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE ); ////初始化CAN2 GPIO_PinRemapConfig(GPIO_Remap_CAN2, DISABLE ); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = CAN2_GPIO_TX; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Pin = CAN2_GPIO_RX; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(CAN2_GPIO, &GPIO_InitStructure); } static void Filter_Configuration(void) { CAN_FilterInitTypeDef CAN_FilterInitStructure; CAN_SlaveStartBank(14); CAN_FilterInitStructure.CAN_FilterNumber = 0; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterIdLow = 0x0004; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x000C; //ExtID EVEN CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0; //FIFO0 CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); CAN_FilterInitStructure.CAN_FilterNumber = 1; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterIdLow = 0x000C; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x000C; //ExtID ODD CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 1; //FIFO1 CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); CAN_FilterInitStructure.CAN_FilterNumber = 2; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0020; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0004; //StdID EVEN CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0; //FIFO0 CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); CAN_FilterInitStructure.CAN_FilterNumber = 3; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0020; CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0020; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0004; //StdID ODD CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 1; //FIFO1 CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); CAN_FilterInitStructure.CAN_FilterNumber = 14; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterIdLow = 0x0004; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x000C; //ExtID EVEN CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0; //FIFO0 CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); CAN_FilterInitStructure.CAN_FilterNumber = 15; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterIdLow = 0x000C; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x000C; //ExtID ODD CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 1; //FIFO1 CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); CAN_FilterInitStructure.CAN_FilterNumber = 16; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0020; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0004; //StdID EVEN CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0; //FIFO0 CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); CAN_FilterInitStructure.CAN_FilterNumber = 17; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0020; CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0020; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0004; //StdID ODD CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_Fil
评论
    相关推荐
    • STM32F10X 头文件
      MDK升级后,出现大量的 ..\SYSTEM\sys\sys.h(3): error: #5: cannot open source input file "stm32f10x_lib.h": No such file or directory 包含这个文件夹就可以解决该问题
    • STM32F10XXX DEMO
      STM32F10XXX DEMO LCD USB LED examp
    • STM32F10x官方例程
      STM32F10x官方例程
    • KEIL STM32F10X官方例程
      KEIL STM32F10X USB官方例程 Audio_Speaker Example description =================== The USB-FS-Device Audio Speaker demo gives examples of how to use the STM32F10xxx and STM32L15xxx USB-FS-Device ...
    • stm32f10x程序
      stm32f10x arm 程序,数据采集功能,SPI协议传输,毕业设计程序源代码。
    • STM32F10x_StdPeriph_Lib_V3.5.0.zip
      STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\CAN STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\CEC STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_...
    • STM32F10x固件库
      STM32F10xxx微控制器内核和外设应用文档及相关例程(英文原版)
    • STM32F10x库
      STM32F10x_StdPeriph_Driver STM32F10x_StdPeriph_Driver STM32F10x_StdPeriph_Driver
    • STM32F10X 1602LCD
      STM32F10X 4个LED数码管、1602LCD 用MDK4.53 ST固件库开发
    • STM32F10x中断例程
      摘要:STM32 F10x 中断例程,使用V3.5 .Lib,外接8MHz晶振,主频72Mhz, keilUv4 for STM32,ST—Link 引脚:LED:GPIOA12 EXTI:GPIOA3 文件: misc.c misc.h main.c ALL_Includes.h stm32f10x...