欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

STM32F103固件库编程(8)—CAN通讯

程序员文章站 2024-02-26 18:10:28
...

CAN寄存器

STM32F103固件库编程(8)—CAN通讯

工作模式

正常模式:可向总线发送和接收
静默模式:不能向总线发送,但可接收
STM32F103固件库编程(8)—CAN通讯
回环模式:能向总线发送,接收的是发送端的数据(收不到总线的数据)
STM32F103固件库编程(8)—CAN通讯
回环静默模式:不能向总线发送和接收
STM32F103固件库编程(8)—CAN通讯

位序

STM32F103固件库编程(8)—CAN通讯

接收筛选器

STM32F103固件库编程(8)—CAN通讯

STM32F103固件库编程(8)—CAN通讯

CAN的初始化结构体

typedef struct
{
  uint16_t CAN_Prescaler;   
  uint8_t CAN_Mode;         
  uint8_t CAN_SJW;        
  uint8_t CAN_BS1;        
  uint8_t CAN_BS2;         
  FunctionalState CAN_TTCM; 
  FunctionalState CAN_ABOM;
  FunctionalState CAN_AWUM;  
  FunctionalState CAN_NART;  
  FunctionalState CAN_RFLM;  
  FunctionalState CAN_TXFP;  
} CAN_InitTypeDef;


typedef struct
{
  uint16_t CAN_FilterIdHigh;        
  uint16_t CAN_FilterIdLow;        
  uint16_t CAN_FilterMaskIdHigh;   
  uint16_t CAN_FilterMaskIdLow;     
  uint16_t CAN_FilterFIFOAssignment; 
  uint8_t CAN_FilterNumber;         
  uint8_t CAN_FilterMode;          
  uint8_t CAN_FilterScale;         
  FunctionalState CAN_FilterActivation; 
} CAN_FilterInitTypeDef;


typedef struct
{
  uint32_t StdId; 
  uint32_t ExtId;  
  uint8_t IDE;  
  uint8_t RTR;    
  uint8_t DLC;    
  uint8_t Data[8];
} CanTxMsg;



typedef struct
{
  uint32_t StdId; 
  uint32_t ExtId; 
  uint8_t IDE;    
  uint8_t RTR;   
  uint8_t DLC;  
  uint8_t Data[8]; 
  uint8_t FMI;    
} CanRxMsg;