📄 stm32f10x_usart.lst
字号:
212
213 /*******************************************************************************
214 * Function Name : USART_StructInit
215 * Description : Fills each USART_InitStruct member with its default value.
216 * Input : - USART_InitStruct: pointer to a USART_InitTypeDef structure
217 * which will be initialized.
218 * Output : None
219 * Return : None
220 *******************************************************************************/
221 void USART_StructInit(USART_InitTypeDef* USART_InitStruct)
222 {
223 /* USART_InitStruct members default value */
224 USART_InitStruct->USART_BaudRate = 0x2580; /* 9600 Baud */
225 USART_InitStruct->USART_WordLength = USART_WordLength_8b;
226 USART_InitStruct->USART_StopBits = USART_StopBits_1;
227 USART_InitStruct->USART_Parity = USART_Parity_No ;
228 USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
229 USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
230 USART_InitStruct->USART_Clock = USART_Clock_Disable;
231 USART_InitStruct->USART_CPOL = USART_CPOL_Low;
232 USART_InitStruct->USART_CPHA = USART_CPHA_1Edge;
233 USART_InitStruct->USART_LastBit = USART_LastBit_Disable;
234 }
235
236 /*******************************************************************************
237 * Function Name : USART_Cmd
238 * Description : Enables or disables the specified USART peripheral.
239 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
240 * peripheral.
241 * : - NewState: new state of the USARTx peripheral.
242 * This parameter can be: ENABLE or DISABLE.
243 * Output : None
244 * Return : None
245 *******************************************************************************/
246 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
247 {
248 /* Check the parameters */
249 assert_param(IS_FUNCTIONAL_STATE(NewState));
250
251 if (NewState != DISABLE)
252 {
253 /* Enable the selected USART by setting the RUN bit in the CR1 register */
254 USARTx->CR1 |= CR1_RUN_Set;
255 }
256 else
257 {
258 /* Disable the selected USART by clearing the RUN bit in the CR1 register */
259 USARTx->CR1 &= CR1_RUN_Reset;
260 }
261 }
262
263 /*******************************************************************************
264 * Function Name : USART_ITConfig
265 * Description : Enables or disables the specified USART interrupts.
266 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
267 * peripheral.
268 * - USART_IT: specifies the USART interrupt sources to be
269 * enabled or disabled.
270 * This parameter can be one of the following values:
271 * - USART_IT_PE
272 * - USART_IT_TXE
273 * - USART_IT_TC
274 * - USART_IT_RXNE
275 * - USART_IT_IDLE
276 * - USART_IT_LBD
277 * - USART_IT_CTS
278 * - USART_IT_ERR
279 * - NewState: new state of the specified USARTx interrupts.
280 * This parameter can be: ENABLE or DISABLE.
281 * Output : None
282 * Return : None
283 *******************************************************************************/
284 void USART_ITConfig(USART_TypeDef* USARTx, u16 USART_IT, FunctionalState NewState)
285 {
286 u32 usartreg = 0x00, itpos = 0x00, itmask = 0x00;
287 u32 address = 0x00;
288
289 /* Check the parameters */
290 assert_param(IS_USART_CONFIG_IT(USART_IT));
291 assert_param(IS_FUNCTIONAL_STATE(NewState));
292
293 /* Get the USART register index */
294 usartreg = (((u8)USART_IT) >> 0x05);
295
296 /* Get the interrupt position */
297 itpos = USART_IT & USART_IT_Mask;
298
299 itmask = (((u32)0x01) << itpos);
300 address = *(u32*)&(USARTx);
301
302 if (usartreg == 0x01) /* The IT is in CR1 register */
303 {
304 address += 0x0C;
305 }
306 else if (usartreg == 0x02) /* The IT is in CR2 register */
307 {
308 address += 0x10;
309 }
310 else /* The IT is in CR3 register */
311 {
312 address += 0x14;
313 }
314 if (NewState != DISABLE)
315 {
316 *(u32*)address |= itmask;
317 }
318 else
319 {
320 *(u32*)address &= ~itmask;
321 }
322 }
323
324 /*******************************************************************************
325 * Function Name : USART_DMACmd
326 * Description : Enables or disables the USART抯 DMA interface.
327 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
328 * peripheral.
329 * - USART_DMAReq: specifies the DMA request.
330 * This parameter can be any combination of the following values:
331 * - USART_DMAReq_Tx
332 * - USART_DMAReq_Rx
333 * - NewState: new state of the DMA Request sources.
334 * This parameter can be: ENABLE or DISABLE.
335 * Output : None
336 * Return : None
337 *******************************************************************************/
338 void USART_DMACmd(USART_TypeDef* USARTx, u16 USART_DMAReq, FunctionalState NewState)
339 {
340 /* Check the parameters */
341 assert_param(IS_USART_DMAREQ(USART_DMAReq));
342 assert_param(IS_FUNCTIONAL_STATE(NewState));
343
344 if (NewState != DISABLE)
345 {
346 /* Enable the DMA transfer for selected requests by setting the DMAT and/or
347 DMAR bits in the USART CR3 register */
348 USARTx->CR3 |= USART_DMAReq;
349 }
350 else
351 {
352 /* Disable the DMA transfer for selected requests by clearing the DMAT and/or
353 DMAR bits in the USART CR3 register */
354 USARTx->CR3 &= (u16)~USART_DMAReq;
355 }
356 }
357
358 /*******************************************************************************
359 * Function Name : USART_SetAddress
360 * Description : Sets the address of the USART node.
361 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
362 * peripheral.
363 * - USART_Address: Indicates the address of the USART node.
364 * Output : None
365 * Return : None
366 *******************************************************************************/
367 void USART_SetAddress(USART_TypeDef* USARTx, u8 USART_Address)
368 {
369 /* Check the parameters */
370 assert_param(IS_USART_ADDRESS(USART_Address));
371
372 /* Clear the USART address */
373 USARTx->CR2 &= CR2_Address_Mask;
374 /* Set the USART address node */
375 USARTx->CR2 |= USART_Address;
376 }
377
378 /*******************************************************************************
379 * Function Name : USART_WakeUpConfig
380 * Description : Selects the USART WakeUp method.
381 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
382 * peripheral.
383 * - USART_WakeUp: specifies the USART wakeup method.
384 * This parameter can be one of the following values:
385 * - USART_WakeUp_IdleLine
386 * - USART_WakeUp_AddressMark
387 * Output : None
388 * Return : None
389 *******************************************************************************/
390 void USART_WakeUpConfig(USART_TypeDef* USARTx, u16 USART_WakeUp)
391 {
392 /* Check the parameters */
393 assert_param(IS_USART_WAKEUP(USART_WakeUp));
394
395 USARTx->CR1 &= CR3_WAKE_Mask;
396 USARTx->CR1 |= USART_WakeUp;
397 }
398
399 /*******************************************************************************
400 * Function Name : USART_ReceiverWakeUpCmd
401 * Description : Determines if the USART is in mute mode or not.
402 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
403 * peripheral.
404 * - NewState: new state of the USART mode.
405 * This parameter can be: ENABLE or DISABLE.
406 * Output : None
407 * Return : None
408 *******************************************************************************/
409 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
410 {
411 /* Check the parameters */
412 assert_param(IS_FUNCTIONAL_STATE(NewState));
413
414 if (NewState != DISABLE)
415 {
416 /* Enable the mute mode USART by setting the RWU bit in the CR1 register */
417 USARTx->CR1 |= CR1_RWU_Set;
418 }
419 else
420 {
421 /* Disable the mute mode USART by clearing the RWU bit in the CR1 register */
422 USARTx->CR1 &= CR1_RWU_Reset;
423 }
424 }
425
426 /*******************************************************************************
427 * Function Name : USART_LINBreakDetectLengthConfig
428 * Description : Sets the USART LIN Break detection length.
429 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
430 * peripheral.
431 * - USART_LINBreakDetectLength: specifies the LIN break
432 * detection length.
433 * This parameter can be one of the following values:
434 * - USART_LINBreakDetectLength_10b
435 * - USART_LINBreakDetectLength_11b
436 * Output : None
437 * Return : None
438 *******************************************************************************/
439 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, u16 USART_LINBreakDetectLength)
440 {
441 /* Check the parameters */
442 assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
443
444 USARTx->CR2 &= CR3_LBDL_Mask;
445 USARTx->CR2 |= USART_LINBreakDetectLength;
446 }
447
448 /*******************************************************************************
449 * Function Name : USART_LINCmd
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -