You are on page 1of 7

1 /**

2 ********************************************************************************
3 * @file stm8s_uart2.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 UART2
peripheral.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; 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_UART2_H
30 #define __STM8S_UART2_H
31
32 /* Includes ------------------------------------------------------------------*/
33 #include "stm8s.h"
34
35 /** @addtogroup STM8S_StdPeriph_Driver
36 * @{
37 */
38
39 /* Exported types ------------------------------------------------------------*/
40
41 /** @addtogroup UART2_Exported_Types
42 * @{
43 */
44
45 /**
46 * @brief UART2 Irda Modes
47 */
48
49 typedef enum { UART2_IRDAMODE_NORMAL = (uint8_t)0x00, /**< 0x00 Irda Normal
Mode */
50 UART2_IRDAMODE_LOWPOWER = (uint8_t)0x01 /**< 0x01 Irda Low Power
Mode */
51
52 } UART2_IrDAMode_TypeDef;
53
54 /**
55 * @brief UART2 WakeUP Modes
56 */
57
58 typedef enum { UART2_WAKEUP_IDLELINE = (uint8_t)0x00, /**< 0x01 Idle Line wake
up */
59 UART2_WAKEUP_ADDRESSMARK = (uint8_t)0x08 /**< 0x02 Address Mark
wake up */
60 } UART2_WakeUp_TypeDef;
61
62
63 /**
64 * @brief UART2 LIN Break detection length possible values
65 */
66 typedef enum { UART2_LINBREAKDETECTIONLENGTH_10BITS = (uint8_t)0x00, /**< 0x01 10
bits Lin Break detection */
67 UART2_LINBREAKDETECTIONLENGTH_11BITS = (uint8_t)0x01 /**< 0x02 11
bits Lin Break detection */
68 } UART2_LINBreakDetectionLength_TypeDef;
69
70 /**
71 * @brief UART2 stop bits possible values
72 */
73
74 typedef enum { UART2_STOPBITS_1 = (uint8_t)0x00, /**< One stop bit is
transmitted at the end of frame*/
75 UART2_STOPBITS_0_5 = (uint8_t)0x10, /**< Half stop bits is
transmitted at the end of frame*/
76 UART2_STOPBITS_2 = (uint8_t)0x20, /**< Two stop bits are
transmitted at the end of frame*/
77 UART2_STOPBITS_1_5 = (uint8_t)0x30 /**< One and half stop bits*/
78 } UART2_StopBits_TypeDef;
79
80
81 /**
82 * @brief UART2 parity possible values
83 */
84 typedef enum { UART2_PARITY_NO = (uint8_t)0x00, /**< No Parity*/
85 UART2_PARITY_EVEN = (uint8_t)0x04, /**< Even Parity*/
86 UART2_PARITY_ODD = (uint8_t)0x06 /**< Odd Parity*/
87 } UART2_Parity_TypeDef;
88 /**
89 * @brief UART2 Mode possible values
90 */
91 typedef enum { UART2_LIN_MODE_MASTER = (uint8_t)0x00, /**< LIN Master Mode*/
92 UART2_LIN_MODE_SLAVE = (uint8_t)0x01 /**< LIN Slave Mode*/
93 } UART2_LinMode_TypeDef;
94 /**
95 * @brief UART2 automatic resynchronisation possible values
96 */
97 typedef enum { UART2_LIN_AUTOSYNC_DISABLE = (uint8_t)0x00, /**< LIN
Autosynchronization Disable*/
98 UART2_LIN_AUTOSYNC_ENABLE = (uint8_t)0x01 /**< LIN
Autosynchronization Enable*/
99 } UART2_LinAutosync_TypeDef;
100 /**
101 * @brief UART2 Divider Update Method possible values
102 */
103 typedef enum { UART2_LIN_DIVUP_LBRR1 = (uint8_t)0x00, /**< LIN LDIV is updated as
soon as LBRR1 is written*/
104 UART2_LIN_DIVUP_NEXTRXNE = (uint8_t)0x01 /**< LIN LDIV is updated at
the next received character*/
105 } UART2_LinDivUp_TypeDef;
106
107 /**
108 * @brief UART2 Synchrone modes
109 */
110 typedef enum { UART2_SYNCMODE_CLOCK_DISABLE = (uint8_t)0x80, /**< 0x80 Sync mode
Disable, SLK pin Disable */
111 UART2_SYNCMODE_CLOCK_ENABLE = (uint8_t)0x08, /**< 0x08 Sync mode
Enable, SLK pin Enable */
112 UART2_SYNCMODE_CPOL_LOW = (uint8_t)0x40, /**< 0x40 Steady low
value on SCLK pin outside transmission window */
113 UART2_SYNCMODE_CPOL_HIGH = (uint8_t)0x04, /**< 0x04 Steady high
value on SCLK pin outside transmission window */
114 UART2_SYNCMODE_CPHA_MIDDLE = (uint8_t)0x20, /**< 0x20 SCLK clock
line activated in middle of data bit */
115 UART2_SYNCMODE_CPHA_BEGINING = (uint8_t)0x02, /**< 0x02 SCLK clock
line activated at beginning of data bit */
116 UART2_SYNCMODE_LASTBIT_DISABLE = (uint8_t)0x10, /**< 0x10 The clock
pulse of the last data bit is not output to the SCLK pin */
117 UART2_SYNCMODE_LASTBIT_ENABLE = (uint8_t)0x01 /**< 0x01 The clock
pulse of the last data bit is output to the SCLK pin */
118 } UART2_SyncMode_TypeDef;
119
120 /**
121 * @brief UART2 Word length possible values
122 */
123 typedef enum { UART2_WORDLENGTH_8D = (uint8_t)0x00,/**< 0x00 8 bits Data */
124 UART2_WORDLENGTH_9D = (uint8_t)0x10 /**< 0x10 9 bits Data */
125 } UART2_WordLength_TypeDef;
126
127 /**
128 * @brief UART2 Mode possible values
129 */
130 typedef enum { UART2_MODE_RX_ENABLE = (uint8_t)0x08, /**< 0x08 Receive Enable */
131 UART2_MODE_TX_ENABLE = (uint8_t)0x04, /**< 0x04 Transmit Enable */
132 UART2_MODE_TX_DISABLE = (uint8_t)0x80, /**< 0x80 Transmit Disable
*/
133 UART2_MODE_RX_DISABLE = (uint8_t)0x40, /**< 0x40 Single-wire
Half-duplex mode */
134 UART2_MODE_TXRX_ENABLE = (uint8_t)0x0C /**< 0x0C Transmit Enable
and Receive Enable */
135 } UART2_Mode_TypeDef;
136 /**
137 * @brief UART2 Flag possible values
138 */
139 typedef enum
140 {
141 UART2_FLAG_TXE = (uint16_t)0x0080, /*!< Transmit Data Register Empty flag
*/
142 UART2_FLAG_TC = (uint16_t)0x0040, /*!< Transmission Complete flag */
143 UART2_FLAG_RXNE = (uint16_t)0x0020, /*!< Read Data Register Not Empty flag
*/
144 UART2_FLAG_IDLE = (uint16_t)0x0010, /*!< Idle line detected flag */
145 UART2_FLAG_OR_LHE = (uint16_t)0x0008, /*!< OverRun error flag */
146 UART2_FLAG_NF = (uint16_t)0x0004, /*!< Noise error flag */
147 UART2_FLAG_FE = (uint16_t)0x0002, /*!< Framing Error flag */
148 UART2_FLAG_PE = (uint16_t)0x0001, /*!< Parity Error flag */
149 UART2_FLAG_SBK = (uint16_t)0x0101, /**< Send Break Complete interrupt
flag */
150 UART2_FLAG_LBDF = (uint16_t)0x0210, /**< LIN Break Detection Flag
*/
151 UART2_FLAG_LHDF = (uint16_t)0x0302, /**< LIN Header Detection Flag*/
152 UART2_FLAG_LSF = (uint16_t)0x0301 /**< LIN Sync Field Flag*/
153 } UART2_Flag_TypeDef;
154
155 /**
156 * @brief UART2 Interrupt definition
157 * UART2_IT possible values
158 * Elements values convention: 0xZYX
159 * X: Position of the corresponding Interrupt
160 * - For the following values, X means the interrupt position in the CR2 register.
161 * UART2_IT_TXE
162 * UART2_IT_TC
163 * UART2_IT_RXNE
164 * UART2_IT_IDLE
165 * UART2_IT_OR
166 * - For the UART2_IT_PE value, X means the flag position in the CR1 register.
167 * - For the UART2_IT_LBDF value, X means the flag position in the CR4 register.
168 * - For the UART2_IT_LHDF value, X means the flag position in the CR6 register.
169 * Y: Flag position
170 * - For the following values, Y means the flag (pending bit) position in the SR
register.
171 * UART2_IT_TXE
172 * UART2_IT_TC
173 * UART2_IT_RXNE
174 * UART2_IT_IDLE
175 * UART2_IT_OR
176 * UART2_IT_PE
177 * - For the UART2_IT_LBDF value, Y means the flag position in the CR4 register.
178 * - For the UART2_IT_LHDF value, Y means the flag position in the CR6 register.
179 * Z: Register index: indicate in which register the dedicated interrupt source is:
180 * - 1==> CR1 register
181 * - 2==> CR2 register
182 * - 3==> CR4 register
183 * - 4==> CR6 register
184 */
185 typedef enum { UART2_IT_TXE = (uint16_t)0x0277, /**< Transmit interrupt */
186 UART2_IT_TC = (uint16_t)0x0266, /**< Transmission Complete
interrupt */
187 UART2_IT_RXNE = (uint16_t)0x0255, /**< Data Register Not Empty
interrupt */
188 UART2_IT_IDLE = (uint16_t)0x0244, /**< Idle line detected
interrupt */
189 UART2_IT_OR = (uint16_t)0x0235, /**< OverRun error interrupt */
190 UART2_IT_PE = (uint16_t)0x0100, /**< Parity Error interrupt */
191 UART2_IT_LBDF = (uint16_t)0x0346, /**< LIN Break Detection
interrupt */
192 UART2_IT_LHDF = (uint16_t)0x0412, /**< LIN Header Detection
interrupt*/
193 UART2_IT_RXNE_OR = (uint16_t)0x0205 /*!< Receive/Overrun interrupt
*/
194 } UART2_IT_TypeDef;
195
196 /**
197 * @}
198 */
199
200 /* Exported constants --------------------------------------------------------*/
201 /* Exported macros ------------------------------------------------------------*/
202
203 /* Private macros ------------------------------------------------------------*/
204
205 /** @addtogroup UART2_Private_Macros
206 * @{
207 */
208
209 /**
210 * @brief Macro used by the assert function to check the different functions
parameters.
211 */
212
213 /**
214 * @brief Macro used by the assert_param function in order to check the different
215 * sensitivity values for the MODEs possible combination should be one of
216 * the following.
217 */
218
219 #define IS_UART2_MODE_OK(Mode) \
220 (((Mode) == (uint8_t)UART2_MODE_RX_ENABLE) || \
221 ((Mode) == (uint8_t)UART2_MODE_RX_DISABLE) || \
222 ((Mode) == (uint8_t)UART2_MODE_TX_ENABLE) || \
223 ((Mode) == (uint8_t)UART2_MODE_TX_DISABLE) || \
224 ((Mode) == (uint8_t)UART2_MODE_TXRX_ENABLE) || \
225 ((Mode) == (uint8_t)((uint8_t)UART2_MODE_TX_ENABLE|(uint8_t)UART2_MODE_RX_ENABLE))
|| \
226 ((Mode) ==
(uint8_t)((uint8_t)UART2_MODE_TX_ENABLE|(uint8_t)UART2_MODE_RX_DISABLE)) || \
227 ((Mode) ==
(uint8_t)((uint8_t)UART2_MODE_TX_DISABLE|(uint8_t)UART2_MODE_RX_DISABLE)) || \
228 ((Mode) ==
(uint8_t)((uint8_t)UART2_MODE_TX_DISABLE|(uint8_t)UART2_MODE_RX_ENABLE)))
229
230 /**
231 * @brief Macro used by the assert_param function in order to check the different
232 * sensitivity values for the WordLengths
233 */
234 #define IS_UART2_WORDLENGTH_OK(WordLength) \
235 (((WordLength) == UART2_WORDLENGTH_8D) || \
236 ((WordLength) == UART2_WORDLENGTH_9D))
237
238 /**
239 * @brief Macro used by the assert_param function in order to check the different
240 * sensitivity values for the SyncModes; it should exclude values such
241 * as UART2_CLOCK_ENABLE|UART2_CLOCK_DISABLE
242 */
243 #define IS_UART2_SYNCMODE_OK(SyncMode) \
244
(!((((SyncMode)&(((uint8_t)UART2_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART2_SYNCMODE_CLO
CK_DISABLE))) ==
(((uint8_t)UART2_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART2_SYNCMODE_CLOCK_DISABLE)))
|| \
245 (((SyncMode)&(((uint8_t)UART2_SYNCMODE_CPOL_LOW
)|((uint8_t)UART2_SYNCMODE_CPOL_HIGH))) == (((uint8_t)UART2_SYNCMODE_CPOL_LOW
)|((uint8_t)UART2_SYNCMODE_CPOL_HIGH))) || \
246
(((SyncMode)&(((uint8_t)UART2_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART2_SYNCMODE_CPHA
_BEGINING))) ==
(((uint8_t)UART2_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART2_SYNCMODE_CPHA_BEGINING)))
|| \
247
(((SyncMode)&(((uint8_t)UART2_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART2_SYNCMODE_
LASTBIT_ENABLE))) ==
(((uint8_t)UART2_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART2_SYNCMODE_LASTBIT_ENABL
E)))))
248
249 /**
250 * @brief Macro used by the assert_param function in order to check the
251 * different sensitivity values for the FLAGs
252 */
253 #define IS_UART2_FLAG_OK(Flag) \
254 (((Flag) == UART2_FLAG_TXE) || \
255 ((Flag) == UART2_FLAG_TC) || \
256 ((Flag) == UART2_FLAG_RXNE) || \
257 ((Flag) == UART2_FLAG_IDLE) || \
258 ((Flag) == UART2_FLAG_OR_LHE) || \
259 ((Flag) == UART2_FLAG_NF) || \
260 ((Flag) == UART2_FLAG_FE) || \
261 ((Flag) == UART2_FLAG_PE) || \
262 ((Flag) == UART2_FLAG_SBK) || \
263 ((Flag) == UART2_FLAG_LSF) || \
264 ((Flag) == UART2_FLAG_LHDF) || \
265 ((Flag) == UART2_FLAG_LBDF))
266
267
268 /**
269 * @brief Macro used by the assert_param function in order to check the
270 * different sensitivity values for the FLAGs that can be cleared by writing
0
271 */
272 #define IS_UART2_CLEAR_FLAG_OK(Flag) \
273 (((Flag) == UART2_FLAG_RXNE) || \
274 ((Flag) == UART2_FLAG_LHDF) || \
275 ((Flag) == UART2_FLAG_LSF) || \
276 ((Flag) == UART2_FLAG_LBDF))
277
278 /**
279 * @brief Macro used by the assert_param function in order to check
280 * the different sensitivity values for the Interrupts
281 */
282
283 #define IS_UART2_CONFIG_IT_OK(Interrupt) \
284 (((Interrupt) == UART2_IT_PE) || \
285 ((Interrupt) == UART2_IT_TXE) || \
286 ((Interrupt) == UART2_IT_TC) || \
287 ((Interrupt) == UART2_IT_RXNE_OR ) || \
288 ((Interrupt) == UART2_IT_IDLE) || \
289 ((Interrupt) == UART2_IT_LHDF) || \
290 ((Interrupt) == UART2_IT_LBDF))
291
292 /**
293 * @brief Macro used by the assert function in order to check the different
294 * sensitivity values for the pending bit
295 */
296 #define IS_UART2_GET_IT_OK(ITPendingBit) \
297 (((ITPendingBit) == UART2_IT_TXE) || \
298 ((ITPendingBit) == UART2_IT_TC) || \
299 ((ITPendingBit) == UART2_IT_RXNE) || \
300 ((ITPendingBit) == UART2_IT_IDLE) || \
301 ((ITPendingBit) == UART2_IT_OR) || \
302 ((ITPendingBit) == UART2_IT_LBDF) || \
303 ((ITPendingBit) == UART2_IT_LHDF) || \
304 ((ITPendingBit) == UART2_IT_PE))
305
306 /**
307 * @brief Macro used by the assert function in order to check the different
308 * sensitivity values for the pending bit that can be cleared by writing 0
309 */
310 #define IS_UART2_CLEAR_IT_OK(ITPendingBit) \
311 (((ITPendingBit) == UART2_IT_RXNE) || \
312 ((ITPendingBit) == UART2_IT_LHDF) || \
313 ((ITPendingBit) == UART2_IT_LBDF))
314
315
316 /**
317 * @brief Macro used by the assert_param function in order to check the different
318 * sensitivity values for the IrDAModes
319 */
320 #define IS_UART2_IRDAMODE_OK(IrDAMode) \
321 (((IrDAMode) == UART2_IRDAMODE_LOWPOWER) || \
322 ((IrDAMode) == UART2_IRDAMODE_NORMAL))
323
324 /**
325 * @brief Macro used by the assert_param function in order to check the different
326 * sensitivity values for the WakeUps
327 */
328 #define IS_UART2_WAKEUP_OK(WakeUp) \
329 (((WakeUp) == UART2_WAKEUP_IDLELINE) || \
330 ((WakeUp) == UART2_WAKEUP_ADDRESSMARK))
331
332 /**
333 * @brief Macro used by the assert_param function in order to check the different
334 * sensitivity values for the LINBreakDetectionLengths
335 */
336 #define IS_UART2_LINBREAKDETECTIONLENGTH_OK(LINBreakDetectionLength) \
337 (((LINBreakDetectionLength) == UART2_LINBREAKDETECTIONLENGTH_10BITS) || \
338 ((LINBreakDetectionLength) == UART2_LINBREAKDETECTIONLENGTH_11BITS))
339
340 /**
341 * @brief Macro used by the assert_param function in order to check the different
342 * sensitivity values for the UART2_StopBits
343 */
344 #define IS_UART2_STOPBITS_OK(StopBit) (((StopBit) == UART2_STOPBITS_1) || \
345 ((StopBit) == UART2_STOPBITS_0_5) || \
346 ((StopBit) == UART2_STOPBITS_2) || \
347 ((StopBit) == UART2_STOPBITS_1_5 ))
348
349 /**
350 * @brief Macro used by the assert_param function in order to check the different
351 * sensitivity values for the Paritys
352 */
353 #define IS_UART2_PARITY_OK(Parity) (((Parity) == UART2_PARITY_NO) || \
354 ((Parity) == UART2_PARITY_EVEN) || \
355 ((Parity) == UART2_PARITY_ODD ))
356
357 /**
358 * @brief Macro used by the assert_param function in order to check the maximum
359 * baudrate value
360 */
361 #define IS_UART2_BAUDRATE_OK(NUM) ((NUM) <= (uint32_t)625000)
362
363
364 /**
365 * @brief Macro used by the assert_param function in order to check the address
366 * of the UART2 or UART node
367 */
368 #define UART2_ADDRESS_MAX ((uint8_t)16)
369 #define IS_UART2_ADDRESS_OK(node) ((node) < UART2_ADDRESS_MAX )
370
371 /**
372 * @brief Macro used by the assert_param function in order to check the LIN mode
373 */
374 #define IS_UART2_SLAVE_OK(Mode) \
375 (((Mode) == UART2_LIN_MODE_MASTER) || \
376 ((Mode) == UART2_LIN_MODE_SLAVE))
377
378 /**
379 * @brief Macro used by the assert_param function in order to check the LIN
380 * automatic resynchronization mode
381 */
382 #define IS_UART2_AUTOSYNC_OK(AutosyncMode) \
383 (((AutosyncMode) == UART2_LIN_AUTOSYNC_ENABLE) || \
384 ((AutosyncMode) == UART2_LIN_AUTOSYNC_DISABLE))
385
386 /**
387 * @brief Macro used by the assert_param function in order to check the LIN divider
update method
388 */
389 #define IS_UART2_DIVUP_OK(DivupMethod) \
390 (((DivupMethod) == UART2_LIN_DIVUP_LBRR1) || \
391 ((DivupMethod) == UART2_LIN_DIVUP_NEXTRXNE))
392
393
394 /**
395 * @}
396 */
397
398 /* Exported functions ------------------------------------------------------- */
399
400 /** @addtogroup UART2_Exported_Functions
401 * @{
402 */
403
404 void UART2_DeInit(void);
405 void UART2_Init(uint32_t BaudRate, UART2_WordLength_TypeDef WordLength,
406 UART2_StopBits_TypeDef StopBits, UART2_Parity_TypeDef Parity,
407 UART2_SyncMode_TypeDef SyncMode, UART2_Mode_TypeDef Mode);
408 void UART2_Cmd(FunctionalState NewState);
409 void UART2_ITConfig(UART2_IT_TypeDef UART2_IT, FunctionalState NewState);
410 void UART2_HalfDuplexCmd(FunctionalState NewState);
411 void UART2_IrDAConfig(UART2_IrDAMode_TypeDef UART2_IrDAMode);
412 void UART2_IrDACmd(FunctionalState NewState);
413 void UART2_LINBreakDetectionConfig(UART2_LINBreakDetectionLength_TypeDef
UART2_LINBreakDetectionLength);
414 void UART2_LINConfig(UART2_LinMode_TypeDef UART2_Mode,
415 UART2_LinAutosync_TypeDef UART2_Autosync,
416 UART2_LinDivUp_TypeDef UART2_DivUp);
417 void UART2_LINCmd(FunctionalState NewState);
418 void UART2_SmartCardCmd(FunctionalState NewState);
419 void UART2_SmartCardNACKCmd(FunctionalState NewState);
420 void UART2_WakeUpConfig(UART2_WakeUp_TypeDef UART2_WakeUp);
421 void UART2_ReceiverWakeUpCmd(FunctionalState NewState);
422 uint8_t UART2_ReceiveData8(void);
423 uint16_t UART2_ReceiveData9(void);
424 void UART2_SendData8(uint8_t Data);
425 void UART2_SendData9(uint16_t Data);
426 void UART2_SendBreak(void);
427 void UART2_SetAddress(uint8_t UART2_Address);
428 void UART2_SetGuardTime(uint8_t UART2_GuardTime);
429 void UART2_SetPrescaler(uint8_t UART2_Prescaler);
430 FlagStatus UART2_GetFlagStatus(UART2_Flag_TypeDef UART2_FLAG);
431 void UART2_ClearFlag(UART2_Flag_TypeDef UART2_FLAG);
432 ITStatus UART2_GetITStatus(UART2_IT_TypeDef UART2_IT);
433 void UART2_ClearITPendingBit(UART2_IT_TypeDef UART2_IT);
434
435
436 /**
437 * @}
438 */
439
440 #endif /* __STM8S_UART2_H */
441
442 /**
443 * @}
444 */
445
446
447 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
448

You might also like