207KB

The following document contains information on Cypress products.
Colophon
The products described in this document are designed, developed and manufactured as contemplated for general use,
including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not
designed, developed and manufactured as contemplated (1) for any use that includes fatal risks or dangers that, unless
extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury,
severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control,
mass transport control, medical life support system, missile launch control in weapon system), or (2) for any use where
chance of failure is intolerable (i.e., submersible repeater and artificial satellite). Please note that Spansion will not be liable
to you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products.
Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such
failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and
prevention of over-current levels and other abnormal operating conditions. If any products described in this document
represent goods or technologies subject to certain restrictions on export under the Foreign Exchange and Foreign Trade Law
of Japan, the US Export Administration Regulations or the applicable laws of any other country, the prior authorization by the
respective government entity will be required for export of those products.
Trademarks and Notice
The contents of this document are subject to change without notice. This document may contain information on a Spansion
product under development by Spansion. Spansion reserves the right to change or discontinue work on any product without
notice. The information in this document is provided as is without warranty or guarantee of any kind as to its accuracy,
completeness, operability, fitness for particular purpose, merchantability, non-infringement of third-party rights, or any other
warranty, express, implied, or statutory. Spansion assumes no liability for any damages of any kind arising out of the use of
the information in this document.
®
®
®
TM
Copyright © 2013 Spansion Inc. All rights reserved. Spansion , the Spansion logo, MirrorBit , MirrorBit Eclipse ,
TM
ORNAND and combinations thereof, are trademarks and registered trademarks of Spansion LLC in the United States and
other countries. Other names used are for informational purposes only and may be trademarks of their respective owners.
Fujitsu Semiconductor (Shanghai) Co., Ltd.
Application Note
MCU-AN- 500026-E-10
F²MC-8FX FAMILY
8-BIT MICROCONTROLLER
MB95200 SERIES
LIN/UART API
APPLICATION NOTE
LIN/UART API V1.0
Revision History
Revision History
Date
2009-3-3
Author
Jane, Li
Change of Records
V1.0, First draft
This manual contains 24 pages.
1. The products described in this manual and the specifications thereof may be changed without prior notice.
To obtain up-to-date information and/or specifications, contact your Fujitsu sales representative or Fujitsu
authorized dealer.
2. Fujitsu will not be liable for infringement of copyright, industrial property right, or other rights of a third party
caused by the use of information or drawings described in this manual.
3. The contents of this manual may not be transferred or copied without the express permission of Fujitsu.
4. The products contained in this manual are not intended for use with equipments which require extremely
high reliability such as aerospace equipments, undersea repeaters, nuclear control systems or medical
equipments for life support.
5. Some of the products described in this manual may be strategic materials (or special technology) as defined
by the Foreign Exchange and Foreign Trade Control Law. In such cases, the products or portions thereof
must not be exported without permission as defined under the law.
© 2009 Fujitsu Semiconductor (Shanghai) Co., Ltd.
MCU-AN- 500026-E-10 – Page 2
LIN/UART API V1.0
Contents
CONTENTS
REVISION HISTORY .............................................................................................................. 2 CONTENTS ............................................................................................................................ 3 1 INTRODUCTION ................................................................................................................ 5 2 LIN-UART LIBRARY FUNCTION LIST ............................................................................. 6 3 LIN-UART FUNCTION DETAIL ......................................................................................... 7 3.1 LIN_UART_Restart Function .................................................................................... 7 3.2 LIN_UART_Mode Function ....................................................................................... 7 3.3 LIN_UART_Init Function ........................................................................................... 8 3.4 LIN_UART_Asyn_Mode0_Init Function .................................................................. 10 3.5 LIN_UART_Asyn_Mode1_Init Function .................................................................. 11 3.6 LIN_UART_LIN_Init Function.................................................................................. 11 3.7 LIN_UART_Syn_Init Function ................................................................................. 12 3.8 LIN_UART_Transmit_Control_Bit Function ............................................................ 13 3.9 LIN_UART_Receive_Control_Bit Function ............................................................. 13 3.10 LIN_UART_Error_Handle Function......................................................................... 14 3.11 Serial_IO_Direct_Access Function ......................................................................... 15 3.12 UART_Sendbyte Function ...................................................................................... 15 3.13 UART_Readbyte Function ...................................................................................... 16 3.14 LIN_UART_Write_Data Function ............................................................................ 16 3.15 LIN_UART_Read_Byte Function ............................................................................ 16 3.16 LIN_UART_Baudrate Function ............................................................................... 17 4 USAGE DEMO ................................................................................................................. 18 4.1 LIN UART Restart ................................................................................................... 18 4.2 LIN UART Operates in Mode 0 (Asynchronous Normal Mode ) ............................. 18 4.3 LIN UART Operates in Mode 1 (Asynchronous Multiprocessor Mode ) .................. 18 4.4 LIN UART Operates in Mode 2 (Synchronous Mode ) ............................................ 19 4.5 LIN UART Operates in Mode 3 (LIN Mode ) ........................................................... 19 4.6 LIN UART Receive Data ......................................................................................... 20 4.7 LIN UART Transmit Data ........................................................................................ 20 4.8 LIN UART Error Handle .......................................................................................... 21 4.9 LIN UART Serial Access ......................................................................................... 21 5 ADDITIONAL INFORMATION ......................................................................................... 22 6 APPENDIX ....................................................................................................................... 23 MCU-AN- 500026-E-10 – Page 3
LIN/UART API V1.0
Contents
6.1 Tables ..................................................................................................................... 23 MCU-AN- 500026-E-10 – Page 4
LIN/UART API V1.0
Chapter 1 Introduction
1 Introduction
This document introduces LIN/UART API.
We should consider some conditions, such as ‘reset’, ‘initial’, ‘mode set’, ‘transmit’, ‘receive’,
‘error handle’, ‘direction access’ and ‘baud rate set’ .The following chapters describe them in
details.
MCU-AN- 500026-E-10 – Page 5
LIN/UART API V1.0
Chapter 2 LIN-UART Library Function List
2 LIN-UART Library Function List
This chapter introduces all functions of LIN-UART.
Table 2-1 lists the LIN-UART library functions.
Table 2-1: LIN-UART Functions
Function name
Description
void LIN_UART_Restart (LIN_UART_Reload,
LIN_UART_Clear)
Restart the reload count and LIN UART software
reset
void LIN_UART_Mode (Mode)
Select LIN UART work mode
void LIN_UART_Init (Bit_Length, Stop_Bit, Direction,
Ex_Clk_Select, Ex_Clk_Input)
Initialize LIN_UART
void LIN_UART_Asyn_Mode0_Init (Parity_Status,
Parity_Select)
Setting the parity enable and select even or odd
parity
void LIN_UART_Asyn_Mode1_Init (Data_Type)
Initialize LIN_UART asynchronous mode
1(multiprocessor mode)
void LIN_UART_LIN_Init (Break_Bit, Break_Gerention)
Initialize LIN_UART LIN mode
void LIN_UART_Syn_Init (Sampling_Clock, Continue_Clk,
Ss_Status, Serial_Mode, Clk_Delay)
Initialize LIN_UART synchronous mode
void LIN_UART_Transmit_Control_Bit (Status)
Enable or disable transmit data
void LIN_UART_Receive_Control_Bit (Status)
Enable or disable receive data
uchar LIN_UART_Error_Handle (Status)
Description error type and clear error flag.
void Serial_IO_Direct_Access(Serial_Access_Status,
Serial_Direct_Access)
Serial I/O pin direct access
void UART_Sendbyte (Data)
Transmit a byte
uchar UART_Readbyte (void)
Receive a byte
void LIN_UART_Write_Data (Length, *Data)
Transmit the length of data
void LIN_UART_Read_Data (Length, *Data)
Receive the length of data
void LIN_UART_Baudrate (Sys_Clock, Baudrate)
Set communication baud rate
MCU-AN- 500026-E-10 – Page 6
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
3 LIN-UART Function Detail
This chapter introduces the details of LIN-UART every function.
3.1
LIN_UART_Restart Function
Table 3-1 describes LIN_UART_Restart function.
Function name
Table 3-1: LIN_UART_Restart Function
LIN_UART_Restart
Function prototype
void LIN_UART_Restart (uchar LIN_UART_Reload,uchar
LIN_UART_Clear)
Behavior description
reloads count restart and reset the LIN UART
Input parameter1
LIN_UART_Reload, Reload count restart
Input parameter2
LIN_UART_Clear, Reset the LIN UART
Return value
None
The function reloads count restart and reset the LIN UART. The parameter reloads count
restart bit and programmable clear bit (LIN-UART software reset).
Table 3-2 describes the LIN_UART_Reload parameter values.
Table 3-2: LIN_UART_Reload Definition
LIN_UART_Reload
Description
Dis_LIN_UART_Restart
No effect
En_LIN_UART_Restart
Reload count
Table 3-3 describes the LIN_UART_Clear parameter values.
LIN_UART_Clear
Table 3-3: LIN_UART_Clear Definition
Description
Dis_LIN_UART_Clear
No effect
En_LIN_UART_Clear
Clear bit
3.2
LIN_UART_Mode Function
Table 3-4 describes LIN_UART_Mode function.
Function name
Table 3-4: LIN_UART_Mode Function
LIN_UART_Mode
Function prototype
void LIN_UART_Mode (uchar Mode)
Behavior description
Set work mode
Input parameter
Mode
Return value
None
The function selects the LIN UART operating mode.
MCU-AN- 500026-E-10 – Page 7
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
Table 3-5 describes the Mode parameter values.
Table 3-5: Mode Definition
Description
Mode
Mode_0
Mode 0
Mode_1
Mode 1
Mode_2
Mode 2
Mode_3
Mode 3
3.3
LIN_UART_Init Function
Table 3-6 describes LIN_UART_Init function.
Function name
Function prototype
Table 3-6: LIN_UART_Init Function
LIN_UART_Init
void LIN_UART_Init (uchar Bit_Length,uchar Stop_Bit,uchar
Direction,uchar Ex_Clk_Select,uchar Ex_Clk_Input)
Behavior description
Input parameter1
Bit_Length, Data length bit
Input parameter2
Stop_Bit, Setting stop bit length
Input parameter3
Direction, LSB first or MSB first
Input parameter4
Ex_Clk_Select, Clock source select
Input parameter5
Ex_Clk_Input, Clock input enable
Return value
None
The function set the public parameter for the LIN UART works all modes. The parameters
include the communication data length bit, stop length bit, transfer direction select bit,
external serial clock source select bit and one-to-one external clock input enable bit.
Table 3-7 describes the Bit_Length parameter values.
Bit_Length
Table 3-7: Bit_Length Definition
Description
Length_7_Bit
7 bit length data
Length_8_Bit
8 bit length data
Table 3-8 describes the Stop_Bit parameter values.
Stop_Bit
Table 3-8: Stop_Bit Definition
Description
Stop_1_Bit
1 bit stop bit
Stop_2_Bit
2 bit stop bit
MCU-AN- 500026-E-10 – Page 8
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
Table 3-9 describes the Direction parameter values.
Direction
Table 3-9: Direction Definition
Description
LSB
LSB first
MSB
MSB first
Table 3-10 describes the Ex_Clk_Select parameter values.
Ex_Clk_Select
Table 3-10: Ex_Clk_Select Definition
Description
Internal_Clock
Select baud rate generator
External_Clock
Select external serial source clock
Table 3-11 describes the Ex_Clk_Input parameter values.
Ex_Clk_Input
Table 3-11: Ex_Clk_Input Definition
Description
Internal_Clk_Input
External clock input by the baud rate
External_Clk_Input
External clock input by external clock directly
Notes:
In all mode, when “SMR_EXT = 0”, OTO bit is fixed at “0”.
In mode 2, when “ESCR_MS = 1”, then “SMR_SCKE = 0, EXT = 1, OTO = 1”
MCU-AN- 500026-E-10 – Page 9
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
3.4
LIN_UART_Asyn_Mode0_Init Function
Table 3-12 describes LIN_UART_Asyn_Mode0_Init function.
Function name
Table 3-12: LIN_UART_Asyn_Mode0_Init Function
LIN_UART_Asyn_Mode0_Init
Function prototype
void LIN_UART_Asyn_Mode0_Init (uchar Parity_Status,uchar
Parity_Select)
Behavior description
set parity status bit and select even parity or odd parity for LIN UART
Input parameter1
Parity_Status, Parity enable bit
Input parameter2
Parity_Select, Parity select bit
Return value
None
The function sets parity status bit and selects even parity or odd parity for LIN UART.
Table 3-13 describes the Parity_Status parameter values.
Parity_Status
Table 3-13: Parity_Status Definition
Description
Parity_Disable
Disable parity
Parity_Enable
Enable parity
Table 3-14 describes the Parity_Select parameter values.
Table 3-14: Parity_Select Definition
Parity_Select
Description
Parity_Even
Even parity
Parity_Odd
Odd parity
MCU-AN- 500026-E-10 – Page 10
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
3.5
LIN_UART_Asyn_Mode1_Init Function
Table 3-15 describes LIN_UART_Asyn_Mode1_Init function.
Function name
Table 3-15: LIN_UART_Asyn_Mode1_Init Function
LIN_UART_Asyn_Mode1_Init
Function prototype
void LIN_UART_Asyn_Mode1_Init (uchar Data_Type)
Behavior description
set transfer data type in the asynchronous multiprocessor communication
mode
Input parameter
Data_Type, Setting transmit address or data
Return value
None
The function set transfer data type in the asynchronous multiprocessor communication mode.
Table 3-16 describes the Data_Type parameter values.
Data_Type
Table 3-16: Data_Type Definition
Description
Data_Format
Data frame
Address_Format
Address frame
3.6
LIN_UART_LIN_Init Function
Table 3-17 describes LIN_UART_LIN_Init function.
Function name
Table 3-17: LIN_UART_LIN_Init Function
LIN_UART_LIN_Init
Function prototype
void LIN_UART_LIN_Init (uchar Break_bit,uchar Break_Gerention)
Behavior description
set parameter about the LIN mode
Input parameter1
Break_bit, Synch break length bit
Input parameter2
Break_Gerention, Lin synch break generation bit
Return value
None
The function set parameter about the LIN mode. The parameter have the synch break length
selection bit, LIN synch break generation bit.
Table 3-18 describes the Break_bit parameter values.
Table 3-18: Break_bit Definition
Break_bit
Description
Break_13_Bit
13 bit synch break
Break_14_Bit
14 bit synch break
Break_15_Bit
15 bit synch break
Break_16_Bit
16 bit synch break
MCU-AN- 500026-E-10 – Page 11
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
Table 3-19 describes the Break_Gerention parameter values.
Table 3-19: Break_Gerention Definition
Break_Gerention
Description
Break_Close
No effect
Break_Open
LIN synch break generation
3.7
LIN_UART_Syn_Init Function
Table 3-20 describes LIN_UART_Syn_Init function.
Function name
Table 3-20: LIN_UART_Syn_Init Function
LIN_UART_Syn_Init
Function prototype
void LIN_UART_Syn_Init (uchar Sampling_Clock,uchar Continue_Clk,
uchar Ss_Status,uchar Serial_Mode,uchar Clk_Delay);
Behavior description
set parameter about the LIN UART operates on the synchronous mode
Input parameter1
Sampling_Clock, Synch break rising or falling sampling
Input parameter2
Continue_Clk, Clock output enable bit
Input parameter3
Ss_Status, Start/stop enable bit
Input parameter4
Serial_Mode, Serial clock select bit
Input parameter5
Clk_Delay, Delay serial clock
Return value
None
The function sets parameter about the LIN UART operates on the synchronous mode. The
parameter have sampling clock edge select bit, continue clock output enable bit, start stop
bit, serial clock transmit or receive side select bit, serial clock delay enable bit.
Table 3-21 describes the Sampling_Clock parameter values.
Sampling_Clock
Table 3-21: Sampling_Clock Definition
Description
Rising_Edge
Rising sampling
Falling_Edge
Falling sampling
Table 3-22 describes the Continue_Clk parameter values.
Continue_Clk
Table 3-22: Continue_Clk Definition
Description
Clk_Out_Disable
Disable continue clock out
Clk_Out_Enable
Enable continue clock out
Table 3-23 describes the Ss_Status parameter values.
Ss_Status
Table 3-23: Ss_Status Definition
Description
Ss_Close
No start/stop bit
Ss_Open
Start/stop bit available
MCU-AN- 500026-E-10 – Page 12
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
Table 3-24 describes the Serial_Mode parameter values.
Serial_Mode
Table 3-24: Serial_Mode Definition
Description
Transmit_Mode
Transmission side (serial clock generation)
Receive_Mode
Reception side (external serial clock reception)
Table 3-25 describes the Clk_Delay parameter values.
Clk_Delay
3.8
Table 3-25: Clk_Delay Definition
Description
Delay_Clk_Disable
Disable delay serial clock
Delay_Clk_Enable
Enable delay serial clock
LIN_UART_Transmit_Control_Bit Function
Table 3-26 describes LIN_UART_Transmit_Control_Bit function.
Function name
Table 3-26: LIN_UART_Transmit_Control_Bit Function
LIN_UART_Transmit_Control_Bit
Function prototype
void LIN_UART_Transmit_Control_Bit (uchar Status)
Behavior description
set transmit status
Input parameter
Status, Enable or disable transmit data
Return value
None
The function set transmit status. The parameter status enables or disable transmit data, SOT
pin set as serial data output pin or general-purpose I/O by parameter “Status, SCK pin as
general-purpose I/O in mode 0, 1, 3. SCK pin as LIN UART clock output pin or input pin by
SCR_MS state in mode 2.
Table 3-27 describes the Status parameter values.
Status
Table 3-27: Status Definition
Description
Transmit_Enable
Enable transmit
Transmit_Disable
Disable transmit
3.9
LIN_UART_Receive_Control_Bit Function
Table 3-28 describes LIN_UART_Receive_Control_Bit function.
Function name
Table 3-28: LIN_UART_Receive_Control_Bit Function
LIN_UART_Receive_Control_Bit
Function prototype
void LIN_UART_Receive_Control_Bit (uchar Status)
Behavior description
set receive status
Input parameter
Status, Enable or disable receive data
Return value
None
MCU-AN- 500026-E-10 – Page 13
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
The function set receive status. The parameter status enables or disable receive data, SOT
pin set as serial data input pin or general-purpose I/O by parameter “Status, SCK pin as
general-purpose I/O in mode 0, 1, 3. SCK pin as LIN UART clock output pin or input pin by
SCR_MS state in mode 2.
Table 3-29 describes the Status parameter values.
Status
Table 3-29: Status Definition
Description
Receive_Enable
Enable receive
Receive_Disable
Disable receive
3.10 LIN_UART_Error_Handle Function
Table 3-30 describes LIN_UART_Error_Handle function.
Function name
Table 3-30: LIN_UART_Error_Handle Function
LIN_UART_Error_Handle
Function prototype
uchar LIN_UART_Error_Handle (uchar Mode)
Behavior description
checks error in communication
Input parameter
Mode, Check error and clear error flag bit
Return value
Refer to table 3-32 for more details
The function checks error in communication. And validation the error comes from the parity,
overrun or format. It can set enable or disable the clear the error.
Table 3-31 describes the Mode parameter values.
Mode
Table 3-31: Mode Definition
Description
Check_Error
Check error
Clear_Error
Check and clear error flag bit
Table 3-32 describes the Return values.
Return value
Table 3-32: Return Value Definition
Description
0x00
No error, operate successful
0x20
Framing error
0x40
Overrun error
0x80
Parity error
0x60
Overrun and framing error
0xA0
Parity and framing error
0xC0
Parity and overrun error
0xE0
Parity, overrun and framing error
MCU-AN- 500026-E-10 – Page 14
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
3.11 Serial_IO_Direct_Access Function
Table 3-33 describes Serial_IO_Direct_Access function.
Table 3-33: Serial_IO_Direct_Access Function
Serial_IO_Direct_Access
Function name
Function prototype
void Serial_IO_Direct_Access(uchar Serial_Access_Status,uchar
Serial_Direct_Access)
Behavior description
checks error in communication
Input parameter1
Serial_Access_Status, Access enable bit
Input parameter2
Serial_Direct_Access, Direct access bit
Return value
None
The function set serial output pin direct access state and serial IO pin direct access.
Table 3-34 describes the Serial_Access_Status parameter values.
Serial_Access_Status
Table 3-34: Serial_Access_Status Definition
Description
Dis_Serial_Access
Disable direct access
En_Serial_Access
Enable direct access
Table 3-35 describes the Serial_Direct_Access parameter values.
Table 3-35: Serial_Direct_Access Definition
Description
Serial_Direct_Access
Direct_Access_0
Fix SOT at ”0”
Direct_Access_1
Fix SOT at “1”
Notes: Interaction between SOPE (Serial_Access_Status) and SIOP (Serial_Direct_Access)
SOPE
SIOP
Write to SIOP
Read from SIOP
0
R/W
No effect(however, the
write value is retained)
Return the SIN value
1
R/W
Write “0” or “1” to SOT
Return the SIN value
1
RMW
Read the SOT value, write “0” or “1”
3.12 UART_Sendbyte Function
Table 3-36 describes UART_Sendbyte function.
Function name
Table 3-36: UART_Sendbyte Function
UART_Sendbyte
Function prototype
void UART_Sendbyte (uchar Data)
Behavior description
transmits a byte data
Input parameter
Data, Send a byte data
Return value
None
The function transmits a byte data. The parameter data means transmit data.
MCU-AN- 500026-E-10 – Page 15
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
3.13 UART_Readbyte Function
Table 3-37 describes UART_Readbyte function.
Function name
Table 3-37: UART_Readbyte Function
UART_Readbyte
Function prototype
uchar UART_Readbyte (void)
Behavior description
reception a byte data and return this data
Input parameter
None
Return value
return reception a byte data
The function reception a byte data and return this data.
3.14 LIN_UART_Write_Data Function
Table 3-38 describes LIN_UART_Write_Data function.
Function name
Table 3-38: LIN_UART_Write_Data Function
LIN_UART_Write_Data
Function prototype
void LIN_UART_Write_Data (uchar Length,char *Data)
Behavior description
transmits length of the data
Input parameter1
Length, Communication data length, Transmit data length
Input parameter2
*Data, Transmit data, Transmit pointer type data
Return value
None
Note: the *Data is pointer type variable. The transmit data may be a byte, an array or a
section character.
The function transmits length of the data. The parameter length means length of transmit
data and parameter data means pointer variable of transmit data.
3.15 LIN_UART_Read_Byte Function
Table 3-39 describes LIN_UART_Read_Data function.
Function name
Table 3-39: LIN_UART_Read_Data Function
LIN_UART_Read_Data
Function prototype
void LIN_UART_Read_Data (uchar Length, char *Data)
Behavior description
read length of the data
Input parameter1
Length, Communication data length, Reception data length
Input parameter2
*Data, Transmit data, Reception pointer type data
For example, define *Data global variable array or pointer to receive data.
Return value
None
Note: Input parameter *Data, define *Data global variable array or pointer to receive data.
The function read length of the data. The parameter length means length of receive data and
parameter data means pointer variable of receive data.
MCU-AN- 500026-E-10 – Page 16
LIN/UART API V1.0
Chapter 3 LIN-UART Function Detail
3.16 LIN_UART_Baudrate Function
Table 3-40 describes LIN_UART_Baudrate function.
Function name
Table 3-40: LIN_UART_Baudrate Function
LIN_UART_Baudrate
Function prototype
void LIN_UART_Baudrate (long Sys_Clock,uint Baudrate)
Behavior description
set parameter to the Baud Rate Generator Register (BGR) of the LIN
UART
Input parameter1
Sys_Clock, System clock, System work clock(main clock)
Input parameter2
Baudrate, Communication baud rate
Return value
None
Note:
1 system clock should select external main clock, main-internal CR clock, external sub
clock and sub-internal CR clock. The all clock value bound please conference to in the
chapter 3.
2 baud rate set value. Any baud rate can calculate correct from 300bps to 65535bps.
And then it recommend customer to input typical value like the follow table.
Table 3-41 Typical Baud Rate.
Table 3-41: Typical Baud Rate
Typical Baud Rate (bps)
300
600
1200
2400
4800
7200
9600
10417
19200
28800
38400
57600
The function set parameter to the Baud Rate Generator Register (BGR) of the LIN UART.
MCU-AN- 500026-E-10 – Page 17
LIN/UART API V1.0
Chapter 4 Usage Demo
4 Usage Demo
This chapter introduces some sample when use.
4.1
LIN UART Restart
The LIN UART restart reload count and clear flag bit when consumer use the following
function.
LIN_UART_Restart ();
Sample code
void LIN_UART_REST (void)
{
LIN_UART_Restart (En_LIN_UART_Restart, En_LIN_UART_Clear);
}
4.2
LIN UART Operates in Mode 0 (Asynchronous Normal Mode )
User may be using the following functions when LIN UART operates in the mode 0
(asynchronous normal mode).
LIN_UART_Mode ();
LIN_UART_Init ();
LIN_UART_Baudrate ();
LIN_UART_Asyn_Mode0_Init ();
LIN_UART_Receive_Control_Bit ();
LIN_UART_Transmit_Control_Bit ();
Sample code
void LIN_UART_Initailize (void)
{
LIN_UART_Mode (Mode_0);
LIN_UART_Init (Length_8_Bit, Stop_1_Bit, LSB, Internal_Clock, Internal_Clk_Input);
LIN_UART_Asyn_Mode0_Init (Parity_Enable, Parity_Even);
LIN_UART_Baudrate (10000000, 9600);
//MCLK = 10M, Baud = 9600bps
LIN_UART_Transmit_Control_Bit (Transmit_Enable);
LIN_UART_Receive_Control_Bit (Receive_Enable);
}
4.3
LIN UART Operates in Mode 1 (Asynchronous Multiprocessor Mode)
The LIN UART operates in mode 1 may be using the following functions.
LIN_UART_Mode ();
LIN_UART_Init ();
LIN_UART_Baudrate ();
LIN_UART_Asyn_Mode1_Init ();
MCU-AN- 500026-E-10 – Page 18
LIN/UART API V1.0
Chapter 4 Usage Demo
LIN_UART_Receive_Control_Bit ();
LIN_UART_Transmit_Control_Bit ();
Sample code
void initialize (void)
{
LIN_UART_Mode (Mode_1);
LIN_UART_Init (Length_8_Bit, Stop_1_Bit, LSB, Internal_Clock, Internal_Clk_Input);
LIN_UART_Asyn_Mode1_Init (Data_Format);
LIN_UART_Baudrate (10000000, 9600);
//MCLK = 10M, Baud = 9600bps
LIN_UART_Transmit_Control_Bit (Transmit_Enable);
LIN_UART_Receive_Control_Bit (Receive_Enable);
}
4.4
LIN UART Operates in Mode 2 (Synchronous Mode )
The LIN UART operates in mode 2 may be using the following functions.
LIN_UART_Mode ();
LIN_UART_Init ();
LIN_UART_Baudrate ();
LIN_UART_Syn_Init ();
LIN_UART_Receive_Control_Bit ();
LIN_UART_Transmit_Control_Bit ();
Sample code
void initialize (void)
{
LIN_UART_Mode (Mode_2);
LIN_UART_Init (Length_8_Bit, Stop_1_Bit, LSB, External_Clock, External_Clk_Input);
LIN_UART_Syn_Init (Rising_Edge, Clk_Out_Enable,
Delay_Clk_Disable, Internal_Clock, Internal_Clk_Input);
LIN_UART_Baudrate (10000000, 9600);
Ss_Open,
//MCLK = 10M, Baud = 9600bps
LIN_UART_Transmit_Control_Bit (Transmit_Enable);
LIN_UART_Receive_Control_Bit (Receive_Enable);
}
4.5
Transmit_Mode,
LIN UART Operates in Mode 3 (LIN Mode )
The LIN UART operates in mode 3 may be using the following functions.
LIN_UART_Init ();
LIN_UART_Baudrate ();
LIN_UART_LIN_Init ();
LIN_UART_Receive_Control_Bit ();
LIN_UART_Transmit_Control_Bit ();
MCU-AN- 500026-E-10 – Page 19
LIN/UART API V1.0
Chapter 4 Usage Demo
Sample code
void initialize (void)
{
LIN_UART_Init (Length_8_Bit, Stop_1_Bit, LSB, Internal_Clock, Internal_Clk_Input);
LIN_UART_Baudrate (10000000, 9600);
// system clock 10MHZ, baud rate 9600
LIN_UART_Asyn_LIN_Init (Break_13_Bit, Break_Open);
LIN_UART_Transmit_Control_Bit (Transmit_Enable);
LIN_UART_Receive_Control_Bit (Receive_Enable);
}
4.6
LIN UART Receive Data
The LIN UART receives data use the following functions.
LIN_UART_Receive_Control_Bit ();
LIN_UART_Read_Data ();
Sample code
void receive_data (void)
{
uchar *read_data = 0;
LIN_UART_Receive_Control_Bit (Receive_Enable);
// enable receive data
LIN_UART_Read_Data (2, read_data);
// read 2 bytes
LIN_UART_Receive_Control_Bit (Receive_Disable);
// disable receive data
}
4.7
LIN UART Transmit Data
The LIN UART transmits data use the following functions.
LIN_UART_Transmit_Control_Bit ();
LIN_UART_Write_Data ();
Sample code
void receive_data (void)
{
uchar transmit [] = {0, 1, 2, 3, 4, 5};
LIN_UART_Transmit_Control_Bit (Transmit_Enable);
// enable transmit data
LIN_UART_Write_Data (6, transmit);
// transmit 6 bytes data
MCU-AN- 500026-E-10 – Page 20
LIN/UART API V1.0
Chapter 4 Usage Demo
LIN_UART_Transmit_Control_Bit (Transmit_Disable);
// disable transmit data
}
4.8
LIN UART Error Handle
The LIN UART checks error and reads the types of error when user uses the following
functions.
LIN_UART_Error_Handle ();
Sample code
void receive_data (void)
{
uchar error_value = 0;
error_value = LIN_UART_Error_Handle (Check_Error);
// check error and return error value,
keep the flag bit
error_value = LIN_UART_Error_Handle (Clear_Error);
// check error and return error value,
clear the flag bit
}
4.9
LIN UART Serial Access
The LIN UART enables or disables serial output pin direct access and serial IO pin direct
access when user uses the following function.
Serial_IO_Direct_Access ();
Sample code
void serial_access (void)
{
Serial_IO_Direct_Access (En_Serial_Access, Direct_Access_1);
}
MCU-AN- 500026-E-10 – Page 21
LIN/UART API V1.0
Chapter 5 Additional Information
5 Additional Information
For more information about how to use MB95200H EV-board, BGM Adaptor and SOFTUNE,
please refer to SKT MB2146-410-01-E User Manual, or visit websites:
English version:
http://www.fujitsu.com/cn/fsp/services/mcu/mb95/application_notes.html
Simplified Chinese Version:
http://www.fujitsu.com/cn/fss/services/mcu/mb95/application_notes.html
MCU-AN- 500026-E-10 – Page 22
LIN/UART API V1.0
Chapter 6 Appendix
6 Appendix
6.1
Tables
Table 2-1: LIN-UART Functions ............................................................................................... 6 Table 3-1: LIN_UART_Restart Function .................................................................................. 7 Table 3-2: LIN_UART_Reload Definition ................................................................................. 7 Table 3-3: LIN_UART_Clear Definition .................................................................................... 7 Table 3-4: LIN_UART_Mode Function ..................................................................................... 7 Table 3-5: Mode Definition ....................................................................................................... 8 Table 3-6: LIN_UART_Init Function ......................................................................................... 8 Table 3-7: Bit_Length Definition............................................................................................... 8 Table 3-8: Stop_Bit Definition .................................................................................................. 8 Table 3-9: Direction Definition.................................................................................................. 9 Table 3-10: Ex_Clk_Select Definition ...................................................................................... 9 Table 3-11: Ex_Clk_Input Definition ........................................................................................ 9 Table 3-12: LIN_UART_Asyn_Mode0_Init Function .............................................................. 10 Table 3-13: Parity_Status Definition ...................................................................................... 10 Table 3-14: Parity_Select Definition ....................................................................................... 10 Table 3-15: LIN_UART_Asyn_Mode1_Init Function .............................................................. 11 Table 3-16: Data_Type Definition .......................................................................................... 11 Table 3-17: LIN_UART_LIN_Init Function ............................................................................. 11 Table 3-18: Break_bit Definition ............................................................................................. 11 Table 3-19: Break_Gerention Definition ................................................................................. 12 Table 3-20: LIN_UART_Syn_Init Function ............................................................................. 12 Table 3-21: Sampling_Clock Definition .................................................................................. 12 Table 3-22: Continue_Clk Definition ...................................................................................... 12 Table 3-23: Ss_Status Definition ........................................................................................... 12 Table 3-24: Serial_Mode Definition ........................................................................................ 13 Table 3-25: Clk_Delay Definition ........................................................................................... 13 Table 3-26: LIN_UART_Transmit_Control_Bit Function ........................................................ 13 Table 3-27: Status Definition .................................................................................................. 13 Table 3-28: LIN_UART_Receive_Control_Bit Function ......................................................... 13 Table 3-29: Status Definition .................................................................................................. 14 Table 3-30: LIN_UART_Error_Handle Function .................................................................... 14 Table 3-31: Mode Definition ................................................................................................... 14 Table 3-32: Return Value Definition ....................................................................................... 14 Table 3-33: Serial_IO_Direct_Access Function ..................................................................... 15 MCU-AN- 500026-E-10 – Page 23
LIN/UART API V1.0
Chapter 6 Appendix
Table 3-34: Serial_Access_Status Definition ......................................................................... 15 Table 3-35: Serial_Direct_Access Definition .......................................................................... 15 Table 3-36: UART_Sendbyte Function .................................................................................. 15 Table 3-37: UART_Readbyte Function .................................................................................. 16 Table 3-38: LIN_UART_Write_Data Function ........................................................................ 16 Table 3-39: LIN_UART_Read_Data Function ....................................................................... 16 Table 3-40: LIN_UART_Baudrate Dunction ........................................................................... 17 Table 3-41: Typical Baud Rate .............................................................................................. 17 MCU-AN- 500026-E-10 – Page 24
Similar pages