Uart1 H
Uart1 H
2 ********************************************************************************
3 * @file stm8s_uart1.h
4 * @author MCD Application Team
5 * @version V2.3.0
6 * @date 16-June-2017
7 * @brief This file contains all functions prototypes and macros for the UART1
peripheral.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
12 *
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
16 *
17 * http://www.st.com/software_license_agreement_liberty_v2
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 ******************************************************************************
26 */
27
28 /* Define to prevent recursive inclusion -------------------------------------*/
29 #ifndef __STM8S_UART1_H
30 #define __STM8S_UART1_H
31
32 /* Includes ------------------------------------------------------------------*/
33 #include "stm8s.h"
34
35 /** @addtogroup STM8S_StdPeriph_Driver
36 * @{
37 */
38
39 /* Exported types ------------------------------------------------------------*/
40
41 /** @addtogroup UART1_Exported_Types
42 * @{
43 */
44
45
46 /**
47 * @brief UART1 Irda Modes
48 */
49
50 typedef enum { UART1_IRDAMODE_NORMAL = (uint8_t)0x00, /**< 0x00 Irda Normal Mode
*/
51 UART1_IRDAMODE_LOWPOWER = (uint8_t)0x01 /**< 0x01 Irda Low Power
Mode */
52 } UART1_IrDAMode_TypeDef;
53
54 /**
55 * @brief UART1 WakeUP Modes
56 */
57 typedef enum { UART1_WAKEUP_IDLELINE = (uint8_t)0x00, /**< 0x01 Idle Line wake
up */
58 UART1_WAKEUP_ADDRESSMARK = (uint8_t)0x08 /**< 0x02 Address Mark
wake up */
59 } UART1_WakeUp_TypeDef;
60
61 /**
62 * @brief UART1 LIN Break detection length possible values
63 */
64 typedef enum { UART1_LINBREAKDETECTIONLENGTH_10BITS = (uint8_t)0x00, /**< 0x01 10
bits Lin Break detection */
65 UART1_LINBREAKDETECTIONLENGTH_11BITS = (uint8_t)0x01 /**< 0x02 11
bits Lin Break detection */
66 } UART1_LINBreakDetectionLength_TypeDef;
67
68 /**
69 * @brief UART1 stop bits possible values
70 */
71
72 typedef enum { UART1_STOPBITS_1 = (uint8_t)0x00, /**< One stop bit is
transmitted at the end of frame*/
73 UART1_STOPBITS_0_5 = (uint8_t)0x10, /**< Half stop bits is
transmitted at the end of frame*/
74 UART1_STOPBITS_2 = (uint8_t)0x20, /**< Two stop bits are
transmitted at the end of frame*/
75 UART1_STOPBITS_1_5 = (uint8_t)0x30 /**< One and half stop bits*/
76 } UART1_StopBits_TypeDef;
77
78 /**
79 * @brief UART1 parity possible values
80 */
81 typedef enum { UART1_PARITY_NO = (uint8_t)0x00, /**< No Parity*/
82 UART1_PARITY_EVEN = (uint8_t)0x04, /**< Even Parity*/
83 UART1_PARITY_ODD = (uint8_t)0x06 /**< Odd Parity*/
84 } UART1_Parity_TypeDef;
85
86 /**
87 * @brief UART1 Synchrone modes
88 */
89 typedef enum { UART1_SYNCMODE_CLOCK_DISABLE = (uint8_t)0x80, /**< 0x80 Sync mode
Disable, SLK pin Disable */
90 UART1_SYNCMODE_CLOCK_ENABLE = (uint8_t)0x08, /**< 0x08 Sync mode
Enable, SLK pin Enable */
91 UART1_SYNCMODE_CPOL_LOW = (uint8_t)0x40, /**< 0x40 Steady low
value on SCLK pin outside transmission window */
92 UART1_SYNCMODE_CPOL_HIGH = (uint8_t)0x04, /**< 0x04 Steady high
value on SCLK pin outside transmission window */
93 UART1_SYNCMODE_CPHA_MIDDLE = (uint8_t)0x20, /**< 0x20 SCLK clock
line activated in middle of data bit */
94 UART1_SYNCMODE_CPHA_BEGINING = (uint8_t)0x02, /**< 0x02 SCLK clock
line activated at beginning of data bit */
95 UART1_SYNCMODE_LASTBIT_DISABLE = (uint8_t)0x10, /**< 0x10 The clock
pulse of the last data bit is not output to the SCLK pin */
96 UART1_SYNCMODE_LASTBIT_ENABLE = (uint8_t)0x01 /**< 0x01 The clock
pulse of the last data bit is output to the SCLK pin */
97 } UART1_SyncMode_TypeDef;
98
99 /**
100 * @brief UART1 Word length possible values
101 */
102 typedef enum { UART1_WORDLENGTH_8D = (uint8_t)0x00,/**< 0x00 8 bits Data */
103 UART1_WORDLENGTH_9D = (uint8_t)0x10 /**< 0x10 9 bits Data */
104 } UART1_WordLength_TypeDef;
105
106 /**
107 * @brief UART1 Mode possible values
108 */
109 typedef enum { UART1_MODE_RX_ENABLE = (uint8_t)0x08, /**< 0x08 Receive Enable */
110 UART1_MODE_TX_ENABLE = (uint8_t)0x04, /**< 0x04 Transmit Enable */
111 UART1_MODE_TX_DISABLE = (uint8_t)0x80, /**< 0x80 Transmit Disable
*/
112 UART1_MODE_RX_DISABLE = (uint8_t)0x40, /**< 0x40 Single-wire
Half-duplex mode */
113 UART1_MODE_TXRX_ENABLE = (uint8_t)0x0C /**< 0x0C Transmit Enable
and Receive Enable */
114 } UART1_Mode_TypeDef;
115
116 /**
117 * @brief UART1 Flag possible values
118 */
119 typedef enum { UART1_FLAG_TXE = (uint16_t)0x0080, /*!< Transmit Data Register Empty
flag */
120 UART1_FLAG_TC = (uint16_t)0x0040, /*!< Transmission Complete flag */
121 UART1_FLAG_RXNE = (uint16_t)0x0020, /*!< Read Data Register Not Empty
flag */
122 UART1_FLAG_IDLE = (uint16_t)0x0010, /*!< Idle line detected flag */
123 UART1_FLAG_OR = (uint16_t)0x0008, /*!< OverRun error flag */
124 UART1_FLAG_NF = (uint16_t)0x0004, /*!< Noise error flag */
125 UART1_FLAG_FE = (uint16_t)0x0002, /*!< Framing Error flag */
126 UART1_FLAG_PE = (uint16_t)0x0001, /*!< Parity Error flag */
127 UART1_FLAG_LBDF = (uint16_t)0x0210, /*!< Line Break Detection Flag */
128 UART1_FLAG_SBK = (uint16_t)0x0101 /*!< Send Break characters Flag */
129 } UART1_Flag_TypeDef;
130
131 /**
132 * @brief UART1 Interrupt definition
133 * UART1_IT possible values
134 * Elements values convention: 0xZYX
135 * X: Position of the corresponding Interrupt
136 * - For the following values, X means the interrupt position in the CR2 register.
137 * UART1_IT_TXE
138 * UART1_IT_TC
139 * UART1_IT_RXNE
140 * UART1_IT_IDLE
141 * UART1_IT_OR
142 * - For the UART1_IT_PE value, X means the flag position in the CR1 register.
143 * - For the UART1_IT_LBDF value, X means the flag position in the CR4 register.
144 * Y: Flag position
145 * - For the following values, Y means the flag (pending bit) position in the SR
register.
146 * UART1_IT_TXE
147 * UART1_IT_TC
148 * UART1_IT_RXNE
149 * UART1_IT_IDLE
150 * UART1_IT_OR
151 * UART1_IT_PE
152 * - For the UART1_IT_LBDF value, Y means the flag position in the CR4 register.
153 * Z: Register index: indicate in which register the dedicated interrupt source is:
154 * - 1==> CR1 register
155 * - 2==> CR2 register
156 * - 3==> CR4 register
157 */
158 typedef enum { UART1_IT_TXE = (uint16_t)0x0277, /*!< Transmit interrupt */
159 UART1_IT_TC = (uint16_t)0x0266, /*!< Transmission Complete
interrupt */
160 UART1_IT_RXNE = (uint16_t)0x0255, /*!< Receive interrupt */
161 UART1_IT_IDLE = (uint16_t)0x0244, /*!< IDLE line interrupt */
162 UART1_IT_OR = (uint16_t)0x0235, /*!< Overrun Error interrupt */
163 UART1_IT_PE = (uint16_t)0x0100, /*!< Parity Error interrupt */
164 UART1_IT_LBDF = (uint16_t)0x0346, /**< LIN break detection
interrupt */
165 UART1_IT_RXNE_OR = (uint16_t)0x0205 /*!< Receive/Overrun interrupt
*/
166 } UART1_IT_TypeDef;
167
168 /**
169 * @}
170 */
171
172 /* Exported constants --------------------------------------------------------*/
173 /* Exported macros ------------------------------------------------------------*/
174
175 /* Private macros ------------------------------------------------------------*/
176
177 /** @addtogroup UART1_Private_Macros
178 * @{
179 */
180
181 /**
182 * @brief Macro used by the assert function to check the different functions
parameters.
183 */
184
185 /**
186 * @brief Macro used by the assert_param function in order to check the different
187 * sensitivity values for the MODEs possible combination should be one of
188 * the following
189 */
190 #define IS_UART1_MODE_OK(Mode) \
191 (((Mode) == (uint8_t)UART1_MODE_RX_ENABLE) || \
192 ((Mode) == (uint8_t)UART1_MODE_RX_DISABLE) || \
193 ((Mode) == (uint8_t)UART1_MODE_TX_ENABLE) || \
194 ((Mode) == (uint8_t)UART1_MODE_TX_DISABLE) || \
195 ((Mode) == (uint8_t)UART1_MODE_TXRX_ENABLE) || \
196 ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_ENABLE|(uint8_t)UART1_MODE_RX_ENABLE))
|| \
197 ((Mode) ==
(uint8_t)((uint8_t)UART1_MODE_TX_ENABLE|(uint8_t)UART1_MODE_RX_DISABLE)) || \
198 ((Mode) ==
(uint8_t)((uint8_t)UART1_MODE_TX_DISABLE|(uint8_t)UART1_MODE_RX_DISABLE)) || \
199 ((Mode) ==
(uint8_t)((uint8_t)UART1_MODE_TX_DISABLE|(uint8_t)UART1_MODE_RX_ENABLE)))
200
201 /**
202 * @brief Macro used by the assert_param function in order to check the different
203 * sensitivity values for the WordLengths
204 */
205 #define IS_UART1_WORDLENGTH_OK(WordLength) \
206 (((WordLength) == UART1_WORDLENGTH_8D) || \
207 ((WordLength) == UART1_WORDLENGTH_9D))
208
209 /**
210 * @brief Macro used by the assert_param function in order to check the different
211 * sensitivity values for the SyncModes; it should exclude values such
212 * as UART1_CLOCK_ENABLE|UART1_CLOCK_DISABLE
213 */
214 #define IS_UART1_SYNCMODE_OK(SyncMode) \
215
(!((((SyncMode)&(((uint8_t)UART1_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART1_SYNCMODE_CLO
CK_DISABLE))) ==
(((uint8_t)UART1_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART1_SYNCMODE_CLOCK_DISABLE))) \
216 || (((SyncMode)&(((uint8_t)UART1_SYNCMODE_CPOL_LOW
)|((uint8_t)UART1_SYNCMODE_CPOL_HIGH))) == (((uint8_t)UART1_SYNCMODE_CPOL_LOW
)|((uint8_t)UART1_SYNCMODE_CPOL_HIGH))) \
217
||(((SyncMode)&(((uint8_t)UART1_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART1_SYNCMODE_CPH
A_BEGINING))) ==
(((uint8_t)UART1_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART1_SYNCMODE_CPHA_BEGINING))) \
218 ||
(((SyncMode)&(((uint8_t)UART1_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART1_SYNCMODE_L
ASTBIT_ENABLE))) ==
(((uint8_t)UART1_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART1_SYNCMODE_LASTBIT_ENABLE
)))))
219
220 /**
221 * @brief Macro used by the assert_param function in order to check the different
222 * sensitivity values for the FLAGs
223 */
224 #define IS_UART1_FLAG_OK(Flag) \
225 (((Flag) == UART1_FLAG_TXE) || \
226 ((Flag) == UART1_FLAG_TC) || \
227 ((Flag) == UART1_FLAG_RXNE) || \
228 ((Flag) == UART1_FLAG_IDLE) || \
229 ((Flag) == UART1_FLAG_OR) || \
230 ((Flag) == UART1_FLAG_NF) || \
231 ((Flag) == UART1_FLAG_FE) || \
232 ((Flag) == UART1_FLAG_PE) || \
233 ((Flag) == UART1_FLAG_SBK) || \
234 ((Flag) == UART1_FLAG_LBDF))
235 /**
236 * @brief Macro used by the assert_param function in order to check the different
237 * sensitivity values for the FLAGs that can be cleared by writing 0
238 */
239 #define IS_UART1_CLEAR_FLAG_OK(Flag) \
240 (((Flag) == UART1_FLAG_RXNE) || \
241 ((Flag) == UART1_FLAG_LBDF))
242
243
244
245 /**
246 * @brief Macro used by the assert_param function in order to check the different
247 * sensitivity values for the Interrupts
248 */
249
250 #define IS_UART1_CONFIG_IT_OK(Interrupt) \
251 (((Interrupt) == UART1_IT_PE) || \
252 ((Interrupt) == UART1_IT_TXE) || \
253 ((Interrupt) == UART1_IT_TC) || \
254 ((Interrupt) == UART1_IT_RXNE_OR ) || \
255 ((Interrupt) == UART1_IT_IDLE) || \
256 ((Interrupt) == UART1_IT_LBDF))
257
258 /**
259 * @brief Macro used by the assert function in order to check the different
260 * sensitivity values for the pending bit
261 */
262 #define IS_UART1_GET_IT_OK(ITPendingBit) \
263 (((ITPendingBit) == UART1_IT_TXE) || \
264 ((ITPendingBit) == UART1_IT_TC) || \
265 ((ITPendingBit) == UART1_IT_RXNE) || \
266 ((ITPendingBit) == UART1_IT_IDLE) || \
267 ((ITPendingBit) == UART1_IT_OR) || \
268 ((ITPendingBit) == UART1_IT_LBDF) || \
269 ((ITPendingBit) == UART1_IT_PE))
270
271 /**
272 * @brief Macro used by the assert function in order to check the different
273 * sensitivity values for the pending bit that can be cleared by writing 0
274 */
275 #define IS_UART1_CLEAR_IT_OK(ITPendingBit) \
276 (((ITPendingBit) == UART1_IT_RXNE) || \
277 ((ITPendingBit) == UART1_IT_LBDF))
278
279
280 /**
281 * @brief Macro used by the assert_param function in order to check the different
282 * sensitivity values for the IrDAModes
283 */
284 #define IS_UART1_IRDAMODE_OK(IrDAMode) \
285 (((IrDAMode) == UART1_IRDAMODE_LOWPOWER) || \
286 ((IrDAMode) == UART1_IRDAMODE_NORMAL))
287
288 /**
289 * @brief Macro used by the assert_param function in order to check the different
290 * sensitivity values for the WakeUps
291 */
292 #define IS_UART1_WAKEUP_OK(WakeUp) \
293 (((WakeUp) == UART1_WAKEUP_IDLELINE) || \
294 ((WakeUp) == UART1_WAKEUP_ADDRESSMARK))
295
296 /**
297 * @brief Macro used by the assert_param function in order to check the different
298 * sensitivity values for the LINBreakDetectionLengths
299 */
300 #define IS_UART1_LINBREAKDETECTIONLENGTH_OK(LINBreakDetectionLength) \
301 (((LINBreakDetectionLength) == UART1_LINBREAKDETECTIONLENGTH_10BITS) || \
302 ((LINBreakDetectionLength) == UART1_LINBREAKDETECTIONLENGTH_11BITS))
303
304 /**
305 * @brief Macro used by the assert_param function in order to check the different
306 * sensitivity values for the UART1_StopBits
307 */
308 #define IS_UART1_STOPBITS_OK(StopBit) (((StopBit) == UART1_STOPBITS_1) || \
309 ((StopBit) == UART1_STOPBITS_0_5) || \
310 ((StopBit) == UART1_STOPBITS_2) || \
311 ((StopBit) == UART1_STOPBITS_1_5 ))
312
313 /**
314 * @brief Macro used by the assert_param function in order to check the different
315 * sensitivity values for the Parity
316 */
317 #define IS_UART1_PARITY_OK(Parity) (((Parity) == UART1_PARITY_NO) || \
318 ((Parity) == UART1_PARITY_EVEN) || \
319 ((Parity) == UART1_PARITY_ODD ))
320
321 /**
322 * @brief Macro used by the assert_param function in order to check the maximum
323 * baudrate value
324 */
325 #define IS_UART1_BAUDRATE_OK(NUM) ((NUM) <= (uint32_t)625000)
326
327
328 /**
329 * @brief Macro used by the assert_param function in order to check the address
330 * of the UART1 or UART node
331 */
332 #define UART1_ADDRESS_MAX ((uint8_t)16)
333 #define IS_UART1_ADDRESS_OK(node) ((node) < UART1_ADDRESS_MAX )
334
335 /**
336 * @}
337 */
338
339 /* Exported functions ------------------------------------------------------- */
340
341 /** @addtogroup UART1_Exported_Functions
342 * @{
343 */
344
345 void UART1_DeInit(void);
346 void UART1_Init(uint32_t BaudRate, UART1_WordLength_TypeDef WordLength,
347 UART1_StopBits_TypeDef StopBits, UART1_Parity_TypeDef Parity,
348 UART1_SyncMode_TypeDef SyncMode, UART1_Mode_TypeDef Mode);
349 void UART1_Cmd(FunctionalState NewState);
350 void UART1_ITConfig(UART1_IT_TypeDef UART1_IT, FunctionalState NewState);
351 void UART1_HalfDuplexCmd(FunctionalState NewState);
352 void UART1_IrDAConfig(UART1_IrDAMode_TypeDef UART1_IrDAMode);
353 void UART1_IrDACmd(FunctionalState NewState);
354 void UART1_LINBreakDetectionConfig(UART1_LINBreakDetectionLength_TypeDef
UART1_LINBreakDetectionLength);
355 void UART1_LINCmd(FunctionalState NewState);
356 void UART1_SmartCardCmd(FunctionalState NewState);
357 void UART1_SmartCardNACKCmd(FunctionalState NewState);
358 void UART1_WakeUpConfig(UART1_WakeUp_TypeDef UART1_WakeUp);
359 void UART1_ReceiverWakeUpCmd(FunctionalState NewState);
360 uint8_t UART1_ReceiveData8(void);
361 uint16_t UART1_ReceiveData9(void);
362 void UART1_SendData8(uint8_t Data);
363 void UART1_SendData9(uint16_t Data);
364 void UART1_SendBreak(void);
365 void UART1_SetAddress(uint8_t UART1_Address);
366 void UART1_SetGuardTime(uint8_t UART1_GuardTime);
367 void UART1_SetPrescaler(uint8_t UART1_Prescaler);
368 FlagStatus UART1_GetFlagStatus(UART1_Flag_TypeDef UART1_FLAG);
369 void UART1_ClearFlag(UART1_Flag_TypeDef UART1_FLAG);
370 ITStatus UART1_GetITStatus(UART1_IT_TypeDef UART1_IT);
371 void UART1_ClearITPendingBit(UART1_IT_TypeDef UART1_IT);
372
373 /**
374 * @}
375 */
376
377 #endif /* __STM8S_UART1_H */
378
379 /**
380 * @}
381 */
382
383 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
384