Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
cubexHal.pdf
Скачиваний:
110
Добавлен:
10.02.2016
Размер:
16.16 Mб
Скачать

UM1725

 

HAL CAN Generic Driver

 

 

__IO HAL_CAN_StateTypeDef CAN_HandleTypeDef::State

 

 

CAN communication state

 

 

HAL_LockTypeDef CAN_HandleTypeDef::Lock

CAN locking object

__IO uint32_t CAN_HandleTypeDef::ErrorCode

CAN Error code

6.2CAN Firmware driver API description

6.2.1How to use this driver

1.Enable the CAN controller interface clock using __HAL_RCC_CAN1_CLK_ENABLE() for CAN1 and __HAL_RCC_CAN2_CLK_ENABLE() for CAN2 In case you are using CAN2 only, you have to enable the CAN1 clock.

2.CAN pins configuration

Enable the clock for the CAN GPIOs using the following function: __GPIOx_CLK_ENABLE()

Connect and configure the involved CAN pins to AF9 using the following function HAL_GPIO_Init()

3.Initialize and configure the CAN using CAN_Init() function.

4.Transmit the desired CAN frame using HAL_CAN_Transmit() function.

5.Receive a CAN frame using HAL_CAN_Receive() function.

Polling mode IO operation

Start the CAN peripheral transmission and wait the end of this operation using

HAL_CAN_Transmit(), at this stage user can specify the value of timeout according to his end application

Start the CAN peripheral reception and wait the end of this operation using

HAL_CAN_Receive(), at this stage user can specify the value of timeout according to his end application

Interrupt mode IO operation

Start the CAN peripheral transmission using HAL_CAN_Transmit_IT()

Start the CAN peripheral reception using HAL_CAN_Receive_IT()

Use HAL_CAN_IRQHandler() called under the used CAN Interrupt subroutine

At CAN end of transmission HAL_CAN_TxCpltCallback() function is executed and user can add his own code by customization of function pointer HAL_CAN_TxCpltCallback

In case of CAN Error, HAL_CAN_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_CAN_ErrorCallback

CAN HAL driver macros list

Below the list of most used macros in CAN HAL driver.

__HAL_CAN_ENABLE_IT: Enable the specified CAN interrupts

__HAL_CAN_DISABLE_IT: Disable the specified CAN interrupts

DOCID025834 Rev 2

133/900

HAL CAN Generic Driver

UM1725

__HAL_CAN_GET_IT_SOURCE: Check if the specified CAN interrupt source is enabled or disabled

__HAL_CAN_CLEAR_FLAG: Clear the CAN's pending flags

__HAL_CAN_GET_FLAG: Get the selected CAN's flag status

You can refer to the CAN HAL driver header file for more useful macros

6.2.2Initialization and de-initialization functions

This section provides functions allowing to:

Initialize and configure the CAN.

De-initialize the CAN.

This section contains the following APIs:

HAL_CAN_Init()

HAL_CAN_ConfigFilter()

HAL_CAN_DeInit()

HAL_CAN_MspInit()

HAL_CAN_MspDeInit()

6.2.3IO operation functions

This section provides functions allowing to:

Transmit a CAN frame message.

Receive a CAN frame message.

Enter CAN peripheral in sleep mode.

Wake up the CAN peripheral from sleep mode.

This section contains the following APIs:

HAL_CAN_Transmit()

HAL_CAN_Transmit_IT()

HAL_CAN_Receive()

HAL_CAN_Receive_IT()

HAL_CAN_Sleep()

HAL_CAN_WakeUp()

HAL_CAN_IRQHandler()

HAL_CAN_TxCpltCallback()

HAL_CAN_RxCpltCallback()

HAL_CAN_ErrorCallback()

6.2.4Peripheral State and Error functions

This subsection provides functions allowing to :

Check the CAN state.

Check CAN Errors detected during interrupt process

This section contains the following APIs:

HAL_CAN_GetState()

HAL_CAN_GetError()

134/900

DOCID025834 Rev 2

UM1725

HAL CAN Generic Driver

6.2.5HAL_CAN_Init

Function Name

HAL_StatusTypeDef HAL_CAN_Init (CAN_HandleTypeDef *

 

hcan)

Function Description

Initializes the CAN peripheral according to the specified

 

parameters in the CAN_InitStruct.

Parameters

 

hcan: pointer to a CAN_HandleTypeDef structure that

 

 

contains the configuration information for the specified CAN.

Return values

 

HAL status

6.2.6HAL_CAN_ConfigFilter

Function Name

HAL_StatusTypeDef HAL_CAN_ConfigFilter

 

(CAN_HandleTypeDef * hcan, CAN_FilterConfTypeDef *

 

sFilterConfig)

Function Description

Configures the CAN reception filter according to the specified

 

parameters in the CAN_FilterInitStruct.

Parameters

 

hcan: pointer to a CAN_HandleTypeDef structure that

 

 

contains the configuration information for the specified CAN.

 

 

sFilterConfig: pointer to a CAN_FilterConfTypeDef structure

 

 

that contains the filter configuration information.

Return values

 

None

6.2.7HAL_CAN_DeInit

Function Name

HAL_StatusTypeDef HAL_CAN_DeInit (CAN_HandleTypeDef *

 

hcan)

Function Description

Deinitializes the CANx peripheral registers to their default reset

 

values.

Parameters

 

hcan: pointer to a CAN_HandleTypeDef structure that

 

 

contains the configuration information for the specified CAN.

Return values

 

HAL status

6.2.8HAL_CAN_MspInit

Function Name

void HAL_CAN_MspInit (CAN_HandleTypeDef * hcan)

Function Description

Initializes the CAN MSP.

Parameters

 

hcan: pointer to a CAN_HandleTypeDef structure that

 

 

contains the configuration information for the specified CAN.

Return values

 

None

6.2.9HAL_CAN_MspDeInit

Function Name

void HAL_CAN_MspDeInit (CAN_HandleTypeDef * hcan)

Function Description

DeInitializes the CAN MSP.

 

Parameters

hcan: pointer to a CAN_HandleTypeDef structure that

 

contains the configuration information for the specified CAN.

 

DOCID025834 Rev 2

135/900

HAL CAN Generic Driver

UM1725

Return values

None

6.2.10HAL_CAN_Transmit

Function Name

HAL_StatusTypeDef HAL_CAN_Transmit

 

(CAN_HandleTypeDef * hcan, uint32_t Timeout)

Function Description

Initiates and transmits a CAN frame message.

Parameters

 

hcan: pointer to a CAN_HandleTypeDef structure that

 

 

contains the configuration information for the specified CAN.

 

Timeout: Specify Timeout value

Return values

 

HAL status

6.2.11HAL_CAN_Transmit_IT

Function Name

HAL_StatusTypeDef HAL_CAN_Transmit_IT

 

(CAN_HandleTypeDef * hcan)

Function Description

Initiates and transmits a CAN frame message.

Parameters

 

hcan: pointer to a CAN_HandleTypeDef structure that

 

 

contains the configuration information for the specified CAN.

Return values

 

HAL status

6.2.12HAL_CAN_Receive

Function Name

HAL_StatusTypeDef HAL_CAN_Receive (CAN_HandleTypeDef

 

* hcan, uint8_t FIFONumber, uint32_t Timeout)

Function Description

Receives a correct CAN frame.

Parameters

 

hcan: pointer to a CAN_HandleTypeDef structure that

 

 

contains the configuration information for the specified CAN.

 

FIFONumber: FIFO Number value

 

Timeout: Specify Timeout value

Return values

 

HAL status

6.2.13HAL_CAN_Receive_IT

Function Name

HAL_StatusTypeDef HAL_CAN_Receive_IT

 

(CAN_HandleTypeDef * hcan, uint8_t FIFONumber)

Function Description

Receives a correct CAN frame.

Parameters

 

hcan: Pointer to a CAN_HandleTypeDef structure that

 

 

contains the configuration information for the specified CAN.

 

FIFONumber: Specify the FIFO number

Return values

 

HAL status

6.2.14HAL_CAN_Sleep

Function Name

HAL_StatusTypeDef HAL_CAN_Sleep (CAN_HandleTypeDef *

 

hcan)

Function Description

Enters the Sleep (low power) mode.

136/900

DOCID025834 Rev 2

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]