ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

STM32F103的CAN结构体学习

2020-12-26 12:04:31  阅读:217  来源: 互联网

标签:STM32F103 Specifies uint8 学习 time quantum 结构 parameter define


使用STM32F103的CAN通信就是用这4个结构体函数,把他们理解透了,CAN就好用了

 

CAN的结构体定义在stm32f10x_can.h里面

 

/*********************************************************************************************************************************************************

 //CAN初始化结构定义

*************************************************************************************************************************************************************/

typedef struct
{
uint16_t CAN_Prescaler; /*!< Specifies the length of a time quantum. It ranges from 1 to 1024. */预分频器<指定时间量的长度。范围从1到1024>

uint8_t CAN_Mode; /*!< Specifies the CAN operating mode.This parameter can be a value of @ref CAN_operating_mode */指定CAN操作模式

/*************

有四种模式可选

相关宏

#define CAN_Mode_Normal ((uint8_t)0x00) /*!< normal mode */正常模式
#define CAN_Mode_LoopBack ((uint8_t)0x01) /*!< loopback mode */回环模式
#define CAN_Mode_Silent ((uint8_t)0x02) /*!< silent mode */静音模式
#define CAN_Mode_Silent_LoopBack ((uint8_t)0x03) /*!< loopback combined with silent mode */环回与静音模式相结合

****************/

uint8_t CAN_SJW; /*!< Specifies the maximum number of time quanta the CAN hardware is allowed to lengthen or shorten a bit to perform resynchronization.This parameter can be a value of @ref CAN_synchronisation_jump_width */

/**********************************

硬件同步,再同步

指定时间量的最大数量,允许CAN硬件加长或,缩短一点以执行重新同步。此参数的值可以是@参考CAN\U同步\U跳跃\U宽度*

重新同步跳跃宽度间单位

相关宏

#define CAN_SJW_1tq ((uint8_t)0x00) /*!< 1 time quantum */1个tq
#define CAN_SJW_2tq ((uint8_t)0x01) /*!< 2 time quantum */2个tq
#define CAN_SJW_3tq ((uint8_t)0x02) /*!< 3 time quantum */3个tq
#define CAN_SJW_4tq ((uint8_t)0x03) /*!< 4 time quantum */4个tq

***********************************************/

uint8_t CAN_BS1; /*!< Specifies the number of time quanta in Bit Segment 1. This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */指定时间量(以位为单位)

/*****************************************************

硬件同步,再同步

设置采样点时间段第一段

相关宏

#define CAN_BS1_1tq ((uint8_t)0x00) /*!< 1 time quantum */
#define CAN_BS1_2tq ((uint8_t)0x01) /*!< 2 time quantum */
#define CAN_BS1_3tq ((uint8_t)0x02) /*!< 3 time quantum */
#define CAN_BS1_4tq ((uint8_t)0x03) /*!< 4 time quantum */
#define CAN_BS1_5tq ((uint8_t)0x04) /*!< 5 time quantum */
#define CAN_BS1_6tq ((uint8_t)0x05) /*!< 6 time quantum */
#define CAN_BS1_7tq ((uint8_t)0x06) /*!< 7 time quantum */
#define CAN_BS1_8tq ((uint8_t)0x07) /*!< 8 time quantum */
#define CAN_BS1_9tq ((uint8_t)0x08) /*!< 9 time quantum */
#define CAN_BS1_10tq ((uint8_t)0x09) /*!< 10 time quantum */
#define CAN_BS1_11tq ((uint8_t)0x0A) /*!< 11 time quantum */
#define CAN_BS1_12tq ((uint8_t)0x0B) /*!< 12 time quantum */
#define CAN_BS1_13tq ((uint8_t)0x0C) /*!< 13 time quantum */
#define CAN_BS1_14tq ((uint8_t)0x0D) /*!< 14 time quantum */
#define CAN_BS1_15tq ((uint8_t)0x0E) /*!< 15 time quantum */
#define CAN_BS1_16tq ((uint8_t)0x0F) /*!< 16 time quantum */

********************************************************/

uint8_t CAN_BS2; /*!< Specifies the number of time quanta in Bit Segment 2.his parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */指定时间量(以位为单位)

/*****************************************************

硬件同步,再同步

设置采样点时间段第二段

相关宏

#define CAN_BS2_1tq ((uint8_t)0x00) /*!< 1 time quantum */
#define CAN_BS2_2tq ((uint8_t)0x01) /*!< 2 time quantum */
#define CAN_BS2_3tq ((uint8_t)0x02) /*!< 3 time quantum */
#define CAN_BS2_4tq ((uint8_t)0x03) /*!< 4 time quantum */
#define CAN_BS2_5tq ((uint8_t)0x04) /*!< 5 time quantum */
#define CAN_BS2_6tq ((uint8_t)0x05) /*!< 6 time quantum */
#define CAN_BS2_7tq ((uint8_t)0x06) /*!< 7 time quantum */
#define CAN_BS2_8tq ((uint8_t)0x07) /*!< 8 time quantum */

********************************************************/

unctionalState CAN_TTCM; /*!< Enable or disable the time triggered communication mode. This parameter can be set either to ENABLE or DISABLE. 

/************************************************************************

!<启用或禁用时间触发模式。可以设置此参数启用或禁用。*/

ENABLE or DISABLE

*************************************************************************/

FunctionalState CAN_ABOM; /*!< Enable or disable the automatic bus-off management. This parameter can be set either to ENABLE or DISABLE. */

/***********************************************************************

启用或禁用自动离线管理。此参数可以设置为启用或禁用。*

ENABLE or DISABLE

************************************************************************/

FunctionalState CAN_AWUM; /*!< Enable or disable the automatic wake-up mode. This parameter can be set either to ENABLE or DISABLE. */

/***********************************************************************

<启用或禁用自动唤醒模式。此参数可以设置为启用或禁用。*/

ENABLE or DISABLE

**************************************************************************/

FunctionalState CAN_NART; /*!< Enable or disable the no-automatic retransmission mode. This parameter can be set either to ENABLE or DISABLE. */

/*******************************************************************************

<启用或禁用no自动

重传模式。此参数可以是

设置为启用或禁用。*/

ENABLE or DISABLE

********************************************************************************/

FunctionalState CAN_RFLM; /*!< Enable or disable the Receive FIFO Locked mode.This parameter can be set either to ENABLE or DISABLE. */

/*******************************************************************************

<启用或禁用接收FIFO锁定模式。此参数可以设置为启用或禁用。*/

ENABLE or DISABLE

********************************************************************************/

FunctionalState CAN_TXFP; /*!< Enable or disable the transmit FIFO priority.his parameter can be set either to ENABLE or DISABLE. */

/*******************************************************************************

<启用或禁用传输FIFO优先级。此参数可以设置为启用或禁用。*/

ENABLE or DISABLE

********************************************************************************/

} CAN_InitTypeDe

/*********************************************************************************************************************************************************

过滤设置 初始化结构定义

*************************************************************************************************************************************************************/

typedef struct
{
uint16_t CAN_FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bitconfiguration, first one for a 16-bit configuration).This parameter can be a value between 0x0000 and 0xFFFF */

/*******************************************************************************

/*!<指定32位的过滤器标识符的高16位值,此参数可以是介于0x0000和0xFFFF之间的值*/

********************************************************************************/

uint16_t CAN_FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bitconfiguration, second one for a 16-bit configuration).This parameter can be a value between 0x0000 and 0xFFFF */

/*******************************************************************************

/*!<指定32位的 过滤器标识符的低16位值,此参数可以是介于0x0000和0xFFFF之间的值*/

********************************************************************************/

uint16_t CAN_FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number,according to the mode (MSBs for a 32-bit configuration,first one for a 16-bit configuration).This parameter can be a value between 0x0000 and 0xFFFF */

/*******************************************************************************

/*!<指定32位的 过滤器屏蔽标识符的高16位值,此参数可以是介于0x0000和0xFFFF之间的值*/

********************************************************************************/

uint16_t CAN_FilterMaskIdLow; /*!< Specifies the filter mask number or identification number,according to the mode (LSBs for a 32-bit configuration,second one for a 16-bit configuration).This parameter can be a value between 0x0000 and 0xFFFF */

/*******************************************************************************

/*!<指定32位的  过滤器屏蔽标识符的低16位值,此参数可以是介于0x0000和0xFFFF之间的值*/

********************************************************************************/

uint16_t CAN_FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.This parameter can be a value of @ref CAN_filter_FIFO */

/******************************************************************************* 

指定将分配给过滤器的FIFO(0或1)。此参数可以是@ref can_filter_FIFO的值*/

#define CAN_Filter_FIFO0 ((uint8_t)0x00) /*!< Filter FIFO 0 assignment for filter x */
#define CAN_Filter_FIFO1 ((uint8_t)0x01) /*!< Filter FIFO 1 assignment for filter x */

********************************************************************************/

uint8_t CAN_FilterNumber; /*!< Specifies the filter which will be initialized. It ranges from 0 to 13. */

/*******************************************************************************

 指定要初始化的过滤器。范围从0到13

********************************************************************************/

uint8_t CAN_FilterMode; /*!< Specifies the filter mode to be initialized.This parameter can be a value of @ref CAN_filter_mode */

/*******************************************************************************

 指定要初始化的过滤器模式

相关宏

#define CAN_FilterMode_IdMask ((uint8_t)0x00) /*!< identifier/mask mode */标识符/   掩码模式
#define CAN_FilterMode_IdList ((uint8_t)0x01) /*!< identifier list mode */标识符  列表模式

********************************************************************************/

uint8_t CAN_FilterScale; /*!< Specifies the filter scale.This parameter can be a value of @ref CAN_filter_scale */

/*******************************************************************************

 指定过滤器过滤器位宽。

#define CAN_FilterScale_16bit ((uint8_t)0x00) /*!< Two 16-bit filters */
#define CAN_FilterScale_32bit ((uint8_t)0x01) /*!< One 32-bit filter */

********************************************************************************/

FunctionalState CAN_FilterActivation; /*!< Enable or disable the filter.This parameter can be set either to ENABLE or DISABLE. */

/******************************************************************************* 

<启用或禁用过滤器。此参数可以设置为启用或禁用。

ENABLE or DISABLE

********************************************************************************/


} CAN_FilterInitTypeDef;

/*********************************************************************************************************************************************************

CAN发送消息初始化结构定义

*************************************************************************************************************************************************************/

typedef struct
{
uint32_t StdId; /*!< Specifies the standard identifier.This parameter can be a value between 0 to 0x7FF. */

/******************************************************************************* 

/*!<指定标准标识符。此参数可以是0到0x7FF之间的值。*/

********************************************************************************/

uint32_t ExtId; /*!< Specifies the extended identifier.This parameter can be a value between 0 to 0x1FFFFFFF. */

/******************************************************************************* 

!<指定扩展标识符。此参数可以是0到0x1FFFFFF之间的值。*/

********************************************************************************/

uint8_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted. This parameter can be a value of @ref CAN_identifier_type */

/******************************************************************************* 

指定消息的标识符类型将被发送

 

#define CAN_Id_Standard ((uint32_t)0x00000000) /*!< Standard Id */标准Id
#define CAN_Id_Extended ((uint32_t)0x00000004) /*!< Extended Id */扩展Id

********************************************************************************/

uint8_t RTR; /*!< Specifies the type of frame for the message that will be transmitted. This parameter can be a value of @ref CAN_remote_transmission_request */

/******************************************************************************* 

 指定将要传输的消息的帧类型

#define CAN_RTR_Data ((uint32_t)0x00000000) /*!< Data frame */数据帧
#define CAN_RTR_Remote ((uint32_t)0x00000002) /*!< Remote frame */远程帧

********************************************************************************/

uint8_t DLC; /*!< Specifies the length of the frame that will be transmitted. This parameter can be a value between 0 to 8 */

/******************************************************************************* 

!<指定将要传输的帧的长度。此参数可以是介于0到8*/

********************************************************************************/

uint8_t Data[8]; /*!< Contains the data to be transmitted. It ranges from 0 to 0xFF. */

/******************************************************************************* 

 <包含要传输的数据。范围从0到0xFF。*/

将要发送的数据存放到这个数组里面

for(i = 0;i < 8;i++)
{
TxMessage.Data[i] = *(ptr + i);
}

********************************************************************************/


} CanTxMsg;

/*********************************************************************************************************************************************************

CAN接收消息初始化结构定义

*************************************************************************************************************************************************************/

typedef struct
{
uint32_t StdId; /*!< Specifies the standard identifier.This parameter can be a value between 0 to 0x7FF. */

/******************************************************************************* 

<指定标准标识符。此参数可以是0到0x7FF之间的值。*/

********************************************************************************/

uint32_t ExtId; /*!< Specifies the extended identifier.This parameter can be a value between 0 to 0x1FFFFFFF. */

/******************************************************************************* 

 *!<指定扩展标识符。此参数可以是0到0x1FFFFFF之间的值。*/

********************************************************************************/

uint8_t IDE; /*!< Specifies the type of identifier for the message that will be received. This parameter can be a value of @ref CAN_identifier_type */

/******************************************************************************* 

/*!<指定将接收的消息的标识符类型。此参数可以是@ref can\u identifier\u type的值*/ 

#define CAN_Id_Standard ((uint32_t)0x00000000) /*!< Standard Id */标准Id
#define CAN_Id_Extended ((uint32_t)0x00000004) /*!< Extended Id */扩展Id

********************************************************************************/

uint8_t RTR; /*!< Specifies the type of frame for the received message.This parameter can be a value of @ref CAN_remote_transmission_request */

/******************************************************************************* 

 <指定接收消息的帧类型。此参数可以是@ref can\u remote\u transmission\u request的值*/

#define CAN_RTR_Data ((uint32_t)0x00000000) /*!< Data frame *//数据帧
#define CAN_RTR_Remote ((uint32_t)0x00000002) /*!< Remote frame */远程帧

********************************************************************************/

uint8_t DLC; /*!< Specifies the length of the frame that will be received.This parameter can be a value between 0 to 8 */

/******************************************************************************* 

 <指定将接收的帧的长度。此参数可以是0到8之间的值*/

********************************************************************************/

uint8_t Data[8]; /*!< Contains the data to be received. It ranges from 0 to 0xFF. */

/******************************************************************************* 

 <包含要接收的数据。范围从0到0xFF。*/

接收到的数据存放在这个数组里面

********************************************************************************/

uint8_t FMI; /*!< Specifies the index of the filter the message stored in the mailbox passes through. This parameter can be a value between 0 to 0xFF */

/******************************************************************************* 

 指定邮箱中存储的邮件通过的筛选器的索引。此参数可以是0到0xFF之间的值*/

********************************************************************************/


} CanRxMsg;

标签:STM32F103,Specifies,uint8,学习,time,quantum,结构,parameter,define
来源: https://www.cnblogs.com/zhupeili/p/14192004.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有