an2781
所属分类:嵌入式/单片机/硬件编程
开发工具:C/C++
文件大小:898KB
下载次数:41
上传日期:2010-03-09 03:57:46
上 传 者:
hocem
说明: STM8 Software UART Documentation
文件列表:
AN2781\FWLib (0, 2009-11-16)
AN2781\FWLib\inc (0, 2009-11-19)
AN2781\FWLib\inc\stm8s.h (97455, 2009-06-01)
AN2781\FWLib\inc\stm8s_clk.h (17808, 2009-06-01)
AN2781\FWLib\inc\stm8s_gpio.h (6218, 2009-06-01)
AN2781\FWLib\inc\stm8s_tim3.h (12478, 2009-06-01)
AN2781\FWLib\inc\stm8s_type.h (3451, 2009-06-01)
AN2781\FWLib\src (0, 2009-11-19)
AN2781\FWLib\src\stm8s_clk.c (22396, 2009-10-19)
AN2781\FWLib\src\stm8s_gpio.c (8649, 2009-06-01)
AN2781\FWLib\src\stm8s_tim3.c (36517, 2009-06-01)
AN2781\Swuart_AN (0, 2009-11-19)
AN2781\Swuart_AN\include (0, 2009-11-19)
AN2781\Swuart_AN\include\stm8s_conf.h (7785, 2009-11-16)
AN2781\Swuart_AN\include\stm8s_it.h (3666, 2009-11-18)
AN2781\Swuart_AN\include\swuart.h (7893, 2009-11-19)
AN2781\Swuart_AN\Project (0, 2009-11-16)
AN2781\Swuart_AN\Project\STVD&Cosmic (0, 2009-11-19)
AN2781\Swuart_AN\Project\STVD&Cosmic\stm8_interrupt_vector.c (4266, 2008-10-22)
AN2781\Swuart_AN\Project\STVD&Cosmic\swuart.stp (15413, 2009-11-19)
AN2781\Swuart_AN\Project\STVD&Cosmic\swuart.stw (201, 2009-11-19)
AN2781\Swuart_AN\Project\STVD&Raisonance (0, 2009-11-19)
AN2781\Swuart_AN\Project\STVD&Raisonance\swuart.stp (18735, 2009-11-19)
AN2781\Swuart_AN\Project\STVD&Raisonance\swuart.stw (201, 2009-11-19)
AN2781\Swuart_AN\Source (0, 2009-11-19)
AN2781\Swuart_AN\Source\main.c (4459, 2009-11-19)
AN2781\Swuart_AN\Source\stm8s_it.c (3148, 2009-11-18)
AN2781\Swuart_AN\Source\swuart.c (9406, 2009-11-19)
AN2781\User_Manual.chm (876619, 2009-11-19)
/** @page SW_UART SW UART: Application of SW UART control
@par Application description
SW SIMULATION OF UART CHANNEL
This software implementation for low speed duplex UART channel is suitable
for speed up to 57600 Bd (at 24 Mhz fcpu) or 19200 Bd (at 16 Mhz fcpu). The
standard data frame formats are supported including the options like parity,
9th data bit and double stop bit. Doubled data registers, noise, frame and
overflow logic are performed with minimal claims of used cpu hardware.
User data exchange interface is based on routines for sending a receiving a byte
uart_send() and uart_read(). Initialization is provided by routine uart_init().
See more detail descriptions in heads of their definitions.
The number of data bits can vary from 1 to 9, MSB bit could be used as a parity
bit. In case of nine bits data format macros set_Tx_bit9 and clr_Tx_bit9 are
defined for control 9th data bit. Calling this macros should precede just before
calling uart_send() routine, reading received 9th data bit is performed while
calling uart_read() routine (see below). Configuration of data format is defined
on pre-compile level due to minimize the code execution time.
Transmission is based on equidistant calling routine uart_Tx_timing() in period
of half of an one bit baud rate. This calling must be ensured by user. Here is
used timer TIM3 overflow interrupt with proper setting of prescaler and autoreload
registers in according with baud rate. The pair calling of the function performs
edge logic on dedicated Tx pin. Odd calling do no action and is dismissed. The
reason to do so is that one common timer used for transmission and receive process.
Transmission latency then should not be greater than half of a bit rate.
For receive process capture compare interrupts on channel #2 of the same timer
is used. User must ensure calling routine uart_Rx_timing() at the moment capture
compare interrupt rises at dedicated input pin. The monitoring of the receive
channel is enabled after calling macro uart_receive_enable by user. This macro
enables input capture interrupt for start bit leading edge detection. When the
capture event comes the value captured in capture register is then used for control
of sequence of compare interrupts enabled at the same channel at this time. Compare
interrupts perform sampling of all received bits. Three samples of each bit are
tested for noise logic in every odd compare period (the middle of every received
bit duration) till the stop bits is detected. Then the receive process restarts.
The uart_read() routine saves received byte to an address passed as parameter and
returns a copy of low nibble bits of internal status register. The meaning of raised
bits is following:
LSB bit 0 ... next data byte is received in receive buffer
bit 1 ... noise at some bit(s) is detected
bit 2 ... frame (stop bit(s)) or parity error is detected
bit 3 ... receive buffer overflow (received byte overwrite by next one)
If nine data bit format is used the value of 9th bit is given at bit 5 too else
this bit is forced to zero:
bit 5 ... 9th data bit received (if it is used, else 0)
This means the return value "1" represents at 8 bit data format correct byte
receive. By calling uart_read() routine all internal flags are resets to zero.
The uart_send() routine returns TRUE or FALSE value according if the transmission
of the value passed as parameter was send successfully or not.
User can check the value of any internal flag by calling "test_status()" macro
with parameter of the predefined mask of tested bit (see swuart.h header file).
This checking doesn't change the value of internal flags.
In main() section is an example of using the interface.
User must take care about proper HW configuration in user setting section
in swuart.h header file. Rx pin should have capture capacity in the best case,
any other pin with interrupt capacity could be used for lower speed (user then
must ensure to copy content of timer registers to compare ones at falling edge
of incoming start bit). Tx pin is independent on output compare system and any
output pin can be used for it.
@par Test environment description
Example in main.c file provides a short description of how to use SWUART application.
Transmitted byte is due to short connection received simultaneously and tested
for correct receive after every transmission-receive cycle. Transmission speed
is 57600 Bd (see init_UART_timing macro definition in swuart.h file), after a byte
transmission/receive cycle is inserted about 45 ms delay. In correct state LEDs
should shine permanently with no visible blinking. HSI at maximum speed (16 Mhz)
is switched after initialization (to switch HSE see TO_HSE parameter definition
in swuart.h file). For testing purpose user can rise test pin service by define
switch TEST_PIN_USED and select output pin for it in swuart.h file. This pin
signals sampling moment of receive service routine.
Note: In case when the number of data bits is different from 8 (e.g. DATA_LENGTH
is set to 8 and parity is enabled => 7 bits care data) user have to modify
checking procedure which compares currently transmitted a received byte in main loop
at line 101 of mainc.c (modify comparing buff and tx_byte variables - check 7 LSB
bits only at this case).
@par Directory contents
+ include
- stm8s_conf.h Library Configuration file
- stm8s_it.h Interrupt handlers header file
- swuart.h Header with hardware configuration and software control macros
+ source
- main.c Main file containing the "main" function for application testing
- swuart.c File containing all functions needed for swuart control
- stm8_interrupt_vector.c Interrupt vectors table
+ project
- swuart.stw Contains the Stvd7 workspace
- swuart.stp Contains the Stvd7 project
@par Hardware environment
Testing the project on STM8-EVAL evaluation board:
Pin PD.0 is used as Rx pin (TIM3_CC2)
Pin PD.2 is used as Tx pin
Pin PD.4 is used as a test pin (marking a bit sampling on Rx)
Pin PD.0 and PD.2 (Rx and Tx) pins are connected together for testing
@par How to use it ?
- Open the STVD7 workspace
- Check the swuart.h header settings
- Rebuild all files: Project->Rebuild all
- Load project image: Debug->Start/Stop Debug Session
- Run program: Debug->Run (F5)
Go to main file: SWUART\main.c
*/
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
近期下载者:
相关文件:
收藏者: