stm8s_uart1.h 16 KB

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