stm8s_uart3.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /**
  2. ********************************************************************************
  3. * @file stm8s_uart3.h
  4. * @author MCD Application Team
  5. * @version V2.2.0
  6. * @date 30-September-2014
  7. * @brief This file contains all functions prototypes and macros for the UART3 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. /* Define to prevent recursive inclusion -------------------------------------*/
  28. #ifndef __STM8S_UART3_H
  29. #define __STM8S_UART3_H
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "stm8s.h"
  32. /** @addtogroup STM8S_StdPeriph_Driver
  33. * @{
  34. */
  35. /* Exported types ------------------------------------------------------------*/
  36. /** @addtogroup UART3_Exported_Types
  37. * @{
  38. */
  39. /**
  40. * @brief UART3 WakeUP Modes
  41. */
  42. typedef enum { UART3_WAKEUP_IDLELINE = (uint8_t)0x00, /**< 0x01 Idle Line wake up*/
  43. UART3_WAKEUP_ADDRESSMARK = (uint8_t)0x08 /**< 0x02 Address Mark wake up*/
  44. } UART3_WakeUp_TypeDef;
  45. /**
  46. * @brief UART3 LIN Break detection length possible values
  47. */
  48. typedef enum { UART3_LINBREAKDETECTIONLENGTH_10BITS = (uint8_t)0x00, /**< 10 bits Lin Break detection */
  49. UART3_LINBREAKDETECTIONLENGTH_11BITS = (uint8_t)0x01 /**< 11 bits Lin Break detection */
  50. } UART3_LINBreakDetectionLength_TypeDef;
  51. /**
  52. * @brief UART3 stop bits possible values
  53. */
  54. typedef enum { UART3_STOPBITS_1 = (uint8_t)0x00, /**< One stop bit is transmitted at the end of frame*/
  55. UART3_STOPBITS_2 = (uint8_t)0x20 /**< Two stop bits are transmitted at the end of frame*/
  56. } UART3_StopBits_TypeDef;
  57. /**
  58. * @brief UART3 parity possible values
  59. */
  60. typedef enum { UART3_PARITY_NO = (uint8_t)0x00, /**< No Parity*/
  61. UART3_PARITY_EVEN = (uint8_t)0x04, /**< Even Parity*/
  62. UART3_PARITY_ODD = (uint8_t)0x06 /**< Odd Parity*/
  63. } UART3_Parity_TypeDef;
  64. /**
  65. * @brief UART3 Word length possible values
  66. */
  67. typedef enum { UART3_WORDLENGTH_8D = (uint8_t)0x00, /**< 0x00 8 bits Data*/
  68. UART3_WORDLENGTH_9D = (uint8_t)0x10 /**< 0x10 9 bits Data*/
  69. } UART3_WordLength_TypeDef;
  70. /**
  71. * @brief UART3 Mode Transmit/Receive possible values
  72. */
  73. typedef enum { UART3_MODE_RX_ENABLE = (uint8_t)0x08, /**< 0x08 Receive Enable*/
  74. UART3_MODE_TX_ENABLE = (uint8_t)0x04, /**< 0x04 Transmit Enable*/
  75. UART3_MODE_TX_DISABLE = (uint8_t)0x80, /**< 0x80 Receive Enable*/
  76. UART3_MODE_RX_DISABLE = (uint8_t)0x40, /**< 0x40 Single-wire Half-duplex mode*/
  77. UART3_MODE_TXRX_ENABLE = (uint8_t)0x0C /**< 0x0C Receive Enable and Transmit enable*/
  78. } UART3_Mode_TypeDef;
  79. /**
  80. * @brief UART3 Mode possible values
  81. */
  82. typedef enum { UART3_LIN_MODE_MASTER = (uint8_t)0x00, /**< LIN Master Mode*/
  83. UART3_LIN_MODE_SLAVE = (uint8_t)0x01 /**< LIN Slave Mode*/
  84. } UART3_LinMode_TypeDef;
  85. /**
  86. * @brief UART3 automatic resynchronisation possible values
  87. */
  88. typedef enum { UART3_LIN_AUTOSYNC_DISABLE = (uint8_t)0x00, /**< LIN Autosynchronization Disable*/
  89. UART3_LIN_AUTOSYNC_ENABLE = (uint8_t)0x01 /**< LIN Autosynchronization Enable*/
  90. } UART3_LinAutosync_TypeDef;
  91. /**
  92. * @brief UART3 Divider Update Method possible values
  93. */
  94. typedef enum { UART3_LIN_DIVUP_LBRR1 = (uint8_t)0x00, /**< LIN LDIV is updated as soon as LBRR1 is written*/
  95. UART3_LIN_DIVUP_NEXTRXNE = (uint8_t)0x01 /**< LIN LDIV is updated at the next received character*/
  96. } UART3_LinDivUp_TypeDef;
  97. /**
  98. * @brief UART3 Flag possible values
  99. */
  100. typedef enum
  101. {
  102. UART3_FLAG_TXE = (uint16_t)0x0080, /*!< Transmit Data Register Empty flag */
  103. UART3_FLAG_TC = (uint16_t)0x0040, /*!< Transmission Complete flag */
  104. UART3_FLAG_RXNE = (uint16_t)0x0020, /*!< Read Data Register Not Empty flag */
  105. UART3_FLAG_IDLE = (uint16_t)0x0010, /*!< Idle line detected flag */
  106. UART3_FLAG_OR_LHE = (uint16_t)0x0008, /*!< OverRun error flag */
  107. UART3_FLAG_NF = (uint16_t)0x0004, /*!< Noise error flag */
  108. UART3_FLAG_FE = (uint16_t)0x0002, /*!< Framing Error flag */
  109. UART3_FLAG_PE = (uint16_t)0x0001, /*!< Parity Error flag */
  110. UART3_FLAG_SBK = (uint16_t)0x0101, /**< Send Break Complete interrupt flag */
  111. UART3_FLAG_LBDF = (uint16_t)0x0210, /**< LIN Break Detection Flag */
  112. UART3_FLAG_LHDF = (uint16_t)0x0302, /**< LIN Header Detection Flag*/
  113. UART3_FLAG_LSF = (uint16_t)0x0301 /**< LIN Sync Field Flag*/
  114. } UART3_Flag_TypeDef;
  115. /**
  116. * @brief UART3 Interrupt definition
  117. * UART3_IT possible values
  118. * Elements values convention: 0xZYX
  119. * X: Position of the corresponding Interrupt
  120. * - For the following values, X means the interrupt position in the CR2 register.
  121. * UART3_IT_TXE
  122. * UART3_IT_TC
  123. * UART3_IT_RXNE
  124. * UART3_IT_IDLE
  125. * UART3_IT_OR
  126. * - For the UART3_IT_PE value, X means the flag position in the CR1 register.
  127. * - For the UART3_IT_LBDF value, X means the flag position in the CR4 register.
  128. * - For the UART3_IT_LHDF value, X means the flag position in the CR6 register.
  129. * Y: Flag position
  130. * - For the following values, Y means the flag (pending bit) position in the SR register.
  131. * UART3_IT_TXE
  132. * UART3_IT_TC
  133. * UART3_IT_RXNE
  134. * UART3_IT_IDLE
  135. * UART3_IT_OR
  136. * UART3_IT_PE
  137. * - For the UART3_IT_LBDF value, Y means the flag position in the CR4 register.
  138. * - For the UART3_IT_LHDF value, Y means the flag position in the CR6 register.
  139. * Z: Register index: indicate in which register the dedicated interrupt source is:
  140. * - 1==> CR1 register
  141. * - 2==> CR2 register
  142. * - 3==> CR4 register
  143. * - 4==> CR6 register
  144. */
  145. typedef enum { UART3_IT_TXE = (uint16_t)0x0277, /**< Transmit interrupt */
  146. UART3_IT_TC = (uint16_t)0x0266, /**< Transmission Complete interrupt */
  147. UART3_IT_RXNE = (uint16_t)0x0255, /**< Data Register Not Empty interrupt */
  148. UART3_IT_IDLE = (uint16_t)0x0244, /**< Idle line detected interrupt */
  149. UART3_IT_OR = (uint16_t)0x0235, /**< OverRun error interrupt */
  150. UART3_IT_PE = (uint16_t)0x0100, /**< Parity Error interrupt */
  151. UART3_IT_LBDF = (uint16_t)0x0346, /**< LIN Break Detection interrupt */
  152. UART3_IT_LHDF = (uint16_t)0x0412, /**< LIN Header Detection interrupt*/
  153. UART3_IT_RXNE_OR = (uint16_t)0x0205 /*!< Receive/Overrun interrupt */
  154. } UART3_IT_TypeDef;
  155. /**
  156. * @}
  157. */
  158. /* Exported constants --------------------------------------------------------*/
  159. /* Exported macros ------------------------------------------------------------*/
  160. /* Private macros ------------------------------------------------------------*/
  161. /** @addtogroup UART3_Private_Macros
  162. * @{
  163. */
  164. /**
  165. * @brief Macro used by the assert_param function in order to check the
  166. * different sensitivity values for the FLAGs
  167. */
  168. #define IS_UART3_FLAG_OK(Flag) \
  169. (((Flag) == UART3_FLAG_TXE) || \
  170. ((Flag) == UART3_FLAG_TC) || \
  171. ((Flag) == UART3_FLAG_RXNE) || \
  172. ((Flag) == UART3_FLAG_IDLE) || \
  173. ((Flag) == UART3_FLAG_OR_LHE) || \
  174. ((Flag) == UART3_FLAG_NF) || \
  175. ((Flag) == UART3_FLAG_FE) || \
  176. ((Flag) == UART3_FLAG_PE) || \
  177. ((Flag) == UART3_FLAG_SBK) || \
  178. ((Flag) == UART3_FLAG_LSF) || \
  179. ((Flag) == UART3_FLAG_LHDF) || \
  180. ((Flag) == UART3_FLAG_LBDF))
  181. /**
  182. * @brief Macro used by the assert_param function in order to check the
  183. * different sensitivity values for the FLAGs that can be cleared by writing 0
  184. */
  185. #define IS_UART3_CLEAR_FLAG_OK(Flag) \
  186. (((Flag) == UART3_FLAG_RXNE) || \
  187. ((Flag) == UART3_FLAG_LHDF) || \
  188. ((Flag) == UART3_FLAG_LSF) || \
  189. ((Flag) == UART3_FLAG_LBDF))
  190. /**
  191. * @brief Macro used by the assert_param function in order to check the
  192. * different sensitivity values for the Interrupts
  193. */
  194. #define IS_UART3_CONFIG_IT_OK(Interrupt) \
  195. (((Interrupt) == UART3_IT_PE) || \
  196. ((Interrupt) == UART3_IT_TXE) || \
  197. ((Interrupt) == UART3_IT_TC) || \
  198. ((Interrupt) == UART3_IT_RXNE_OR ) || \
  199. ((Interrupt) == UART3_IT_IDLE) || \
  200. ((Interrupt) == UART3_IT_LHDF) || \
  201. ((Interrupt) == UART3_IT_LBDF))
  202. /**
  203. * @brief Macro used by the assert function in order to check the different
  204. * sensitivity values for the pending bit
  205. */
  206. #define IS_UART3_GET_IT_OK(ITPendingBit) \
  207. (((ITPendingBit) == UART3_IT_TXE) || \
  208. ((ITPendingBit) == UART3_IT_TC) || \
  209. ((ITPendingBit) == UART3_IT_RXNE) || \
  210. ((ITPendingBit) == UART3_IT_IDLE) || \
  211. ((ITPendingBit) == UART3_IT_OR) || \
  212. ((ITPendingBit) == UART3_IT_LBDF) || \
  213. ((ITPendingBit) == UART3_IT_LHDF) || \
  214. ((ITPendingBit) == UART3_IT_PE))
  215. /**
  216. * @brief Macro used by the assert function in order to check the different
  217. * sensitivity values for the pending bit that can be cleared by writing 0
  218. */
  219. #define IS_UART3_CLEAR_IT_OK(ITPendingBit) \
  220. (((ITPendingBit) == UART3_IT_RXNE) || \
  221. ((ITPendingBit) == UART3_IT_LHDF) || \
  222. ((ITPendingBit) == UART3_IT_LBDF))
  223. /**
  224. * @brief Macro used by the assert_param function in order to check the different
  225. * sensitivity values for the MODEs
  226. */
  227. #define IS_UART3_MODE_OK(Mode) \
  228. (((Mode) == (uint8_t)UART3_MODE_RX_ENABLE) || \
  229. ((Mode) == (uint8_t)UART3_MODE_RX_DISABLE) || \
  230. ((Mode) == (uint8_t)UART3_MODE_TX_ENABLE) || \
  231. ((Mode) == (uint8_t)UART3_MODE_TX_DISABLE) || \
  232. ((Mode) == (uint8_t)UART3_MODE_TXRX_ENABLE) || \
  233. ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_ENABLE|(uint8_t)UART3_MODE_RX_ENABLE)) || \
  234. ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_ENABLE|(uint8_t)UART3_MODE_RX_DISABLE)) || \
  235. ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_DISABLE|(uint8_t)UART3_MODE_RX_DISABLE)) || \
  236. ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_DISABLE|(uint8_t)UART3_MODE_RX_ENABLE)))
  237. /**
  238. * @brief Macro used by the assert_param function in order to check the different
  239. * sensitivity values for the WordLengths
  240. */
  241. #define IS_UART3_WORDLENGTH_OK(WordLength) \
  242. (((WordLength) == UART3_WORDLENGTH_8D) || \
  243. ((WordLength) == UART3_WORDLENGTH_9D))
  244. /**
  245. * @brief Macro used by the assert_param function in order to check the different
  246. * sensitivity values for the WakeUps
  247. */
  248. #define IS_UART3_WAKEUP_OK(WakeUpMode) \
  249. (((WakeUpMode) == UART3_WAKEUP_IDLELINE) || \
  250. ((WakeUpMode) == UART3_WAKEUP_ADDRESSMARK))
  251. /**
  252. * @brief Macro used by the assert_param function in order to check the different
  253. * sensitivity values for the LINBreakDetectionLengths
  254. */
  255. #define IS_UART3_LINBREAKDETECTIONLENGTH_OK(LINBreakDetectionLengths) \
  256. (((LINBreakDetectionLengths) == UART3_LINBREAKDETECTIONLENGTH_10BITS) || \
  257. ((LINBreakDetectionLengths) == UART3_LINBREAKDETECTIONLENGTH_11BITS))
  258. /**
  259. * @brief Macro used by the assert_param function in order to check the different
  260. * sensitivity values for the UART3_StopBits
  261. */
  262. #define IS_UART3_STOPBITS_OK(StopBit) \
  263. (((StopBit) == UART3_STOPBITS_1) || \
  264. ((StopBit) == UART3_STOPBITS_2))
  265. /**
  266. * @brief Macro used by the assert_param function in order to check the different
  267. * sensitivity values for the Parity
  268. */
  269. #define IS_UART3_PARITY_OK(Parity) \
  270. (((Parity) == UART3_PARITY_NO) || \
  271. ((Parity) == UART3_PARITY_EVEN) || \
  272. ((Parity) == UART3_PARITY_ODD ))
  273. /**
  274. * @brief Macro used by the assert_param function in order to check the maximum
  275. * baudrate value
  276. */
  277. #define IS_UART3_BAUDRATE_OK(NUM) ((NUM) <= (uint32_t)625000)
  278. /**
  279. * @brief Macro used by the assert_param function in order to check the address
  280. * of the UART3 or UART node
  281. */
  282. #define UART3_ADDRESS_MAX ((uint8_t)16)
  283. #define IS_UART3_ADDRESS_OK(Node) ((Node) < UART3_ADDRESS_MAX)
  284. /**
  285. * @brief Macro used by the assert_param function in order to check the LIN mode
  286. */
  287. #define IS_UART3_SLAVE_OK(Mode) \
  288. (((Mode) == UART3_LIN_MODE_MASTER) || \
  289. ((Mode) == UART3_LIN_MODE_SLAVE))
  290. /**
  291. * @brief Macro used by the assert_param function in order to check the LIN
  292. * automatic resynchronization mode
  293. */
  294. #define IS_UART3_AUTOSYNC_OK(AutosyncMode) \
  295. (((AutosyncMode) == UART3_LIN_AUTOSYNC_ENABLE) || \
  296. ((AutosyncMode) == UART3_LIN_AUTOSYNC_DISABLE))
  297. /**
  298. * @brief Macro used by the assert_param function in order to check the LIN
  299. * divider update method
  300. */
  301. #define IS_UART3_DIVUP_OK(DivupMethod) \
  302. (((DivupMethod) == UART3_LIN_DIVUP_LBRR1) || \
  303. ((DivupMethod) == UART3_LIN_DIVUP_NEXTRXNE))
  304. /**
  305. * @}
  306. */
  307. /* Exported functions ------------------------------------------------------- */
  308. /** @addtogroup UART3_Exported_Functions
  309. * @{
  310. */
  311. void UART3_DeInit(void);
  312. void UART3_Init(uint32_t BaudRate, UART3_WordLength_TypeDef WordLength,
  313. UART3_StopBits_TypeDef StopBits, UART3_Parity_TypeDef Parity,
  314. UART3_Mode_TypeDef Mode);
  315. void UART3_Cmd(FunctionalState NewState);
  316. void UART3_ITConfig(UART3_IT_TypeDef UART3_IT, FunctionalState NewState);
  317. void UART3_LINBreakDetectionConfig(UART3_LINBreakDetectionLength_TypeDef UART3_LINBreakDetectionLength);
  318. void UART3_LINConfig(UART3_LinMode_TypeDef UART3_Mode,
  319. UART3_LinAutosync_TypeDef UART3_Autosync,
  320. UART3_LinDivUp_TypeDef UART3_DivUp);
  321. void UART3_LINCmd(FunctionalState NewState);
  322. void UART3_ReceiverWakeUpCmd(FunctionalState NewState);
  323. void UART3_WakeUpConfig( UART3_WakeUp_TypeDef UART3_WakeUp);
  324. uint8_t UART3_ReceiveData8(void);
  325. uint16_t UART3_ReceiveData9(void);
  326. void UART3_SendData8(uint8_t Data);
  327. void UART3_SendData9(uint16_t Data);
  328. void UART3_SendBreak(void);
  329. void UART3_SetAddress(uint8_t UART3_Address);
  330. FlagStatus UART3_GetFlagStatus(UART3_Flag_TypeDef UART3_FLAG);
  331. void UART3_ClearFlag(UART3_Flag_TypeDef UART3_FLAG);
  332. ITStatus UART3_GetITStatus(UART3_IT_TypeDef UART3_IT);
  333. void UART3_ClearITPendingBit(UART3_IT_TypeDef UART3_IT);
  334. /**
  335. * @}
  336. */
  337. #endif /* __STM8S_UART3_H */
  338. /**
  339. * @}
  340. */
  341. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/