STM32F37 Standard Peripheral bibliotheek  1.0
ST Microelectronics bibliotheek documentatie voor de STM32F37 Standard Peripheral Library
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
stm32f37x_can.c File Reference

This file provides firmware functions to manage the following functionalities of the Controller area network (CAN) peripheral: More...

#include "stm32f37x_can.h"
#include "stm32f37x_rcc.h"

Macros

#define MCR_DBF   ((uint32_t)0x00010000) /* software master reset */
 
#define TMIDxR_TXRQ   ((uint32_t)0x00000001) /* Transmit mailbox request */
 
#define FMR_FINIT   ((uint32_t)0x00000001) /* Filter init mode */
 
#define INAK_TIMEOUT   ((uint32_t)0x0000FFFF)
 
#define SLAK_TIMEOUT   ((uint32_t)0x0000FFFF)
 
#define CAN_FLAGS_TSR   ((uint32_t)0x08000000)
 
#define CAN_FLAGS_RF1R   ((uint32_t)0x04000000)
 
#define CAN_FLAGS_RF0R   ((uint32_t)0x02000000)
 
#define CAN_FLAGS_MSR   ((uint32_t)0x01000000)
 
#define CAN_FLAGS_ESR   ((uint32_t)0x00F00000)
 
#define CAN_TXMAILBOX_0   ((uint8_t)0x00)
 
#define CAN_TXMAILBOX_1   ((uint8_t)0x01)
 
#define CAN_TXMAILBOX_2   ((uint8_t)0x02)
 
#define CAN_MODE_MASK   ((uint32_t) 0x00000003)
 

Functions

void CAN_DeInit (CAN_TypeDef *CANx)
 Deinitializes the CAN peripheral registers to their default reset values. More...
 
uint8_t CAN_Init (CAN_TypeDef *CANx, CAN_InitTypeDef *CAN_InitStruct)
 Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct. More...
 
void CAN_FilterInit (CAN_FilterInitTypeDef *CAN_FilterInitStruct)
 Configures the CAN reception filter according to the specified parameters in the CAN_FilterInitStruct. More...
 
void CAN_StructInit (CAN_InitTypeDef *CAN_InitStruct)
 Fills each CAN_InitStruct member with its default value. More...
 
void CAN_SlaveStartBank (uint8_t CAN_BankNumber)
 Select the start bank filter for slave CAN. More...
 
void CAN_DBGFreeze (CAN_TypeDef *CANx, FunctionalState NewState)
 Enables or disables the DBG Freeze for CAN. More...
 
void CAN_TTComModeCmd (CAN_TypeDef *CANx, FunctionalState NewState)
 Enables or disables the CAN Time TriggerOperation communication mode. More...
 
uint8_t CAN_Transmit (CAN_TypeDef *CANx, CanTxMsg *TxMessage)
 Initiates and transmits a CAN frame message. More...
 
uint8_t CAN_TransmitStatus (CAN_TypeDef *CANx, uint8_t TransmitMailbox)
 Checks the transmission status of a CAN Frame. More...
 
void CAN_CancelTransmit (CAN_TypeDef *CANx, uint8_t Mailbox)
 Cancels a transmit request. More...
 
void CAN_Receive (CAN_TypeDef *CANx, uint8_t FIFONumber, CanRxMsg *RxMessage)
 Receives a correct CAN frame. More...
 
void CAN_FIFORelease (CAN_TypeDef *CANx, uint8_t FIFONumber)
 Releases the specified receive FIFO. More...
 
uint8_t CAN_MessagePending (CAN_TypeDef *CANx, uint8_t FIFONumber)
 Returns the number of pending received messages. More...
 
uint8_t CAN_OperatingModeRequest (CAN_TypeDef *CANx, uint8_t CAN_OperatingMode)
 Selects the CAN Operation mode. More...
 
uint8_t CAN_Sleep (CAN_TypeDef *CANx)
 Enters the Sleep (low power) mode. More...
 
uint8_t CAN_WakeUp (CAN_TypeDef *CANx)
 Wakes up the CAN peripheral from sleep mode . More...
 
uint8_t CAN_GetLastErrorCode (CAN_TypeDef *CANx)
 Returns the CANx's last error code (LEC). More...
 
uint8_t CAN_GetReceiveErrorCounter (CAN_TypeDef *CANx)
 Returns the CANx Receive Error Counter (REC). More...
 
uint8_t CAN_GetLSBTransmitErrorCounter (CAN_TypeDef *CANx)
 Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC). More...
 
void CAN_ITConfig (CAN_TypeDef *CANx, uint32_t CAN_IT, FunctionalState NewState)
 Enables or disables the specified CANx interrupts. More...
 
FlagStatus CAN_GetFlagStatus (CAN_TypeDef *CANx, uint32_t CAN_FLAG)
 Checks whether the specified CAN flag is set or not. More...
 
void CAN_ClearFlag (CAN_TypeDef *CANx, uint32_t CAN_FLAG)
 Clears the CAN's pending flags. More...
 
ITStatus CAN_GetITStatus (CAN_TypeDef *CANx, uint32_t CAN_IT)
 Checks whether the specified CANx interrupt has occurred or not. More...
 
void CAN_ClearITPendingBit (CAN_TypeDef *CANx, uint32_t CAN_IT)
 Clears the CANx's interrupt pending bits. More...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the Controller area network (CAN) peripheral:

Author
MCD Application Team
Version
V1.0.0
Date
20-September-2012
  • Initialization and Configuration
  • CAN Frames Transmission
  • CAN Frames Reception
  • Operation modes switch
  • Error management
  • Interrupts and flags
================================================================================
                      ##### How to use this driver #####
================================================================================
    [..]
    (#) Enable the CAN controller interface clock using 
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); for CAN1 

    (#) CAN pins configuration
       (++) Enable the clock for the CAN GPIOs using the following function:
            RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);   
       (++) Connect the involved CAN pins to AF9 using the following function 
            GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_CANx); 
       (++) Configure these CAN pins in alternate function mode by calling
            the function  GPIO_Init();   
    (#) Initialise and configure the CAN using CAN_Init() and 
        CAN_FilterInit() functions.   

    (#) Transmit the desired CAN frame using CAN_Transmit() function.

    (#) Check the transmission of a CAN frame using CAN_TransmitStatus()
        function.

    (#) Cancel the transmission of a CAN frame using CAN_CancelTransmit()
        function.  

    (#) Receive a CAN frame using CAN_Recieve() function.

    (#) Release the receive FIFOs using CAN_FIFORelease() function.

    (#) Return the number of pending received frames using 
        CAN_MessagePending() function.            

    (#) To control CAN events you can use one of the following two methods:
       (++) Check on CAN flags using the CAN_GetFlagStatus() function.  
       (++) Use CAN interrupts through the function CAN_ITConfig() at 
            initialization phase and CAN_GetITStatus() function into 
            interrupt routines to check if the event has occurred or not.
            After checking on a flag you should clear it using CAN_ClearFlag()
            function. And after checking on an interrupt event you should 
            clear it using CAN_ClearITPendingBit() function.            

  *  
Attention
<h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at:

       http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.