UM0459
User manual
ST10F27xZx CAN library
Introduction
The ST10F27xZx product family provides two C-CAN cells with enhanced features
compared to the B-CAN cell implemented in the ST10F269 family.
This ST10F27xZx software CAN library user manual gives guidelines for using the C-CAN
cell and, describes the different routines and data structures implemented in the CAN
library.
The library is compatible with both Tasking and Keil.
March 2008
Rev 1
1/29
www.st.com
Contents
UM0459
Contents
1
Using the ST10F27xZx CAN Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1
1.2
1.3
Library content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
How to install the ST10F27xZx CAN Library . . . . . . . . . . . . . . . . . . . . . . . 5
Getting started with the library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2
Controller area network (CAN) routines . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1
2.2
CAN register structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Software library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.1
2.2.2
2.2.3
2.2.4
2.2.5
2.2.6
2.2.7
2.2.8
2.2.9
2.2.10
2.2.11
2.2.12
2.2.13
2.2.14
2.2.15
2.2.16
2.2.17
2.2.18
2.2.19
2.2.20
2.2.21
2.2.22
2.2.23
2.2.24
2.2.25
2.2.26
CAN_Init function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
CAN_EnterInitMode function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
CAN_LeaveInitMode function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
CAN_EnterTestMode function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
CAN_LeaveTestMode function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
CAN_SetBitrate function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
CAN_SetTiming function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
CAN_SetUnusedMsgObj function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
CAN_SetUnusedAllMsgObj function . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
CAN_SetTxMsgObj function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
CAN_SetRxMsgObj function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
CAN_ReleaseMessage function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CAN_SendMessage function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CAN_UpdateMsgObj function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
CAN_TransmitRequest function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
CAN_ReceiveMessage function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
CAN_BasicSendMessage function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
CAN_BasicReceiveMessage function . . . . . . . . . . . . . . . . . . . . . . . . . . 23
CAN_WaitEndOfTx function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
CAN_GetMsgReceiveStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
CAN_GetMsgTransmiRequestStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CAN_GetMsgInterruptStatus function . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CAN_GetMsgValidStatus function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
CAN_GetFlagStatus function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
CAN_GetTransmitErrorCounter function . . . . . . . . . . . . . . . . . . . . . . . . 27
CAN_GetReceiveErrorCounter function . . . . . . . . . . . . . . . . . . . . . . . . 27
2/29
UM0459
Contents
3
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3/29
List of tables
UM0459
List of tables
Table 1.
Table 2.
Table 3.
Table 4.
Table 5.
Table 6.
Table 7.
Table 8.
Table 9.
Table 10.
Table 11.
Table 12.
Table 13.
Table 14.
Table 15.
Table 16.
Table 17.
Table 18.
Table 19.
Table 20.
Table 21.
Table 22.
Table 23.
Table 24.
Table 25.
Table 26.
Table 27.
Table 28.
Table 29.
Table 30.
Table 31.
CAN registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
CAN functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
CAN_Init function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
CAN_Bitrate values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
CAN_EnterInitMode function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
CAN_LeaveInitMode function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
CAN_EnterTestMode function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
TestMask values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
CAN_LeaveTestMode function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
CAN_SetBitrate function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
CAN_SetTiming function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
CAN_SetUnusedMsgObj function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
CAN_SetUnusedAllMsgObj function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
CAN_SetTxMsgObj function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
CAN_SetRxMsgObj function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
CAN_ReleaseMessage function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CAN_SendMessage function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CAN_UpdateMsgObj function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
CAN_TransmitRequest function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
CAN_ReceiveMessage function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
CAN_BasicSendMessage function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
CAN_BasicReceiveMessage function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
CAN_WaitEndOfTx function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
CAN_GetMsgReceiveStatus function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
CAN_GetMsgTransmitRequestStatus function description . . . . . . . . . . . . . . . . . . . . . . . . 25
CAN_GetMsgInterruptStatus function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CAN_GetMsgValidStatus function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
CAN_GetFlagStatus function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
CAN_GetTransmitErrorCounter function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
CAN_GetReceiveErrorCounter function description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4/29
UM0459
Using the ST10F27xZx CAN Library
1
1.1
Using the ST10F27xZx CAN Library
Library content
The ST10F27xZx CAN library is a software package consisting of a zip file containing the
following folders:
●
Library containing the C source and header files.
–
–
–
st10f27x_can.c C source file containing the C source of the library functions
st10f27_can.h: header file containing the function prototypes and the CAN
interface definitions
st10F27x_types.h: header files containing the definition of data types used by the
library.
●
Example folder with two examples on how to use the CAN library functions. Polling and
interrupt examples are provided.
CAN cell access is made using pointers to the CAN cell addresses. This makes the library
compatible with both Keil and Tasking. The provided examples are compiled and tested
under Tasking toolchain. Applications can be ported easily to the Keil toolchain.
1.2
How to install the ST10F27xZx CAN Library
The ST10F27xZx CAN library is delivered as an archive file with .zip extension. To install the
CAN library, the user needs to unzip the file in the directory where the library has to be
copied.
1.3
Getting started with the library
To use the CAN library, the user should include the st10f27x_can.h header file.
The two CAN interfaces are accessed using the structure pointing to their addresses. CAN
and IF interface definitions are located in st10f27x_can.h. When calling the CAN library
functions, the user should use the CAN1 or CAN2 parameter.
The user should pay attention to the bitrate configuration: if the application environment is
different from the library conditions, the user should recalculate the seg1, seg2,brp and sjw
CAN bit timing parameters. This is the case when ST10 frequency = 40 MHz and the CAN
clock input is derived from the clock generator divided by 2 (see XMISC register).
For more details, please refer to the CAN bit timing configuration in the ST10F27xZx user
manual.
The CAN input/output pins must be configured by the user before using the CAN library.
5/29