📄 stm32f10x_usart.lst
字号:
454 * Function Name : USART_LINCmd
455 * Description : Enables or disables the USART抯 LIN mode.
456 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
457 * peripheral.
458 * - NewState: new state of the USART LIN mode.
459 * This parameter can be: ENABLE or DISABLE.
460 * Output : None
461 * Return : None
462 *******************************************************************************/
463 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
464 {
465 /* Check the parameters */
466 assert(IS_FUNCTIONAL_STATE(NewState));
467
468 if (NewState != DISABLE)
469 {
470 /* Enable the LIN mode by setting the LINE bit in the CR2 register */
471 USARTx->CR2 |= CR2_LINE_Set;
472 }
473 else
474 {
475 /* Disable the LIN mode by clearing the LINE bit in the CR2 register */
476 USARTx->CR2 &= CR2_LINE_Reset;
477 }
478 }
479
480 /*******************************************************************************
481 * Function Name : USART_SendData
482 * Description : Transmits signle data through the USARTx peripheral.
483 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
484 * peripheral.
485 * - Data: the data to transmit.
486 * Output : None
487 * Return : None
488 *******************************************************************************/
489 void USART_SendData(USART_TypeDef* USARTx, u16 Data)
490 {
491 /* Check the parameters */
492 assert(IS_USART_DATA(Data));
493
494 /* Transmit Data */
495 USARTx->DR = (Data & (u16)0x01FF);
496 }
497
498 /*******************************************************************************
499 * Function Name : USART_ReceiveData
500 * Description : Returns the most recent received data by the USARTx peripheral.
501 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
502 * peripheral.
503 * Output : None
504 * Return : The received data.
505 *******************************************************************************/
506 u16 USART_ReceiveData(USART_TypeDef* USARTx)
507 {
508 /* Receive Data */
509 return (u16)(USARTx->DR & (u16)0x01FF);
510 }
511
512 /*******************************************************************************
513 * Function Name : USART_SendBreak
514 * Description : Transmits break characters.
515 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
516 * peripheral.
517 * Output : None
518 * Return : None
519 *******************************************************************************/
520 void USART_SendBreak(USART_TypeDef* USARTx)
521 {
522 /* Send break characters */
523 USARTx->CR1 |= CR1_SBK_Set;
524 }
525
526 /*******************************************************************************
527 * Function Name : USART_SetGuardTime
528 * Description : Sets the specified USART guard time.
529 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
530 * peripheral.
531 * - USART_GuardTime: specifies the guard time.
532 * Output : None
533 * Return : None
534 *******************************************************************************/
535 void USART_SetGuardTime(USART_TypeDef* USARTx, u8 USART_GuardTime)
536 {
537 /* Clear the USART Guard time */
538 USARTx->GTPR &= GTPR_LSB_Mask;
539 /* Set the USART guard time */
540 USARTx->GTPR |= (u16)((u16)USART_GuardTime << 0x08);
541 }
542
543 /*******************************************************************************
544 * Function Name : USART_SetPrescaler
545 * Description : Sets the system clock prescaler.
546 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
547 * peripheral.
548 * - USART_Prescaler: specifies the prescaler clock.
549 * Output : None
550 * Return : None
551 *******************************************************************************/
552 void USART_SetPrescaler(USART_TypeDef* USARTx, u8 USART_Prescaler)
553 {
554 /* Clear the USART prescaler */
555 USARTx->GTPR &= GTPR_MSB_Mask;
556 /* Set the USART prescaler */
557 USARTx->GTPR |= USART_Prescaler;
558 }
559
560 /*******************************************************************************
561 * Function Name : USART_SmartCardCmd
562 * Description : Enables or disables the USART抯 Smart Card mode.
563 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
564 * peripheral.
565 * - NewState: new state of the Smart Card mode.
566 * This parameter can be: ENABLE or DISABLE.
567 * Output : None
568 * Return : None
569 *******************************************************************************/
570 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
571 {
572 /* Check the parameters */
573 assert(IS_FUNCTIONAL_STATE(NewState));
574
575 if (NewState != DISABLE)
576 {
577 /* Enable the SC mode by setting the SCEN bit in the CR3 register */
578 USARTx->CR3 |= CR3_SCEN_Set;
579 }
580 else
581 {
582 /* Disable the SC mode by clearing the SCEN bit in the CR3 register */
583 USARTx->CR3 &= CR3_SCEN_Reset;
584 }
585 }
586
587 /*******************************************************************************
588 * Function Name : USART_SmartCardNACKCmd
589 * Description : Enables or disables NACK transmission.
590 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
591 * peripheral.
592 * - NewState: new state of the NACK transmission.
593 * This parameter can be: ENABLE or DISABLE.
594 * Output : None
595 * Return : None
596 *******************************************************************************/
597 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
598 {
599 /* Check the parameters */
600 assert(IS_FUNCTIONAL_STATE(NewState));
601
602 if (NewState != DISABLE)
603 {
604 /* Enable the NACK transmission by setting the NACK bit in the CR3 register */
605 USARTx->CR3 |= CR3_NACK_Set;
606 }
607 else
608 {
609 /* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
610 USARTx->CR3 &= CR3_NACK_Reset;
611 }
612
613 }
614
615 /*******************************************************************************
616 * Function Name : USART_HalfDuplexCmd
617 * Description : Enables or disables the USART抯 Half Duplex communication.
618 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
619 * peripheral.
620 * - NewState: new state of the USART Communication.
621 * This parameter can be: ENABLE or DISABLE.
622 * Output : None
623 * Return : None
624 *******************************************************************************/
625 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
626 {
627 /* Check the parameters */
628 assert(IS_FUNCTIONAL_STATE(NewState));
629
630 if (NewState != DISABLE)
631 {
632 /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
633 USARTx->CR3 |= CR3_HDSEL_Set;
634 }
635 else
636 {
637 /* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
638 USARTx->CR3 &= CR3_HDSEL_Reset;
639 }
640 }
641
642 /*******************************************************************************
643 * Function Name : USART_IrDAConfig
644 * Description : Configures the USART抯 IrDA interface.
645 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
646 * peripheral.
647 * - USART_IrDAMode: specifies the IrDA mode.
648 * This parameter can be one of the following values:
649 * - USART_IrDAMode_LowPower
650 * - USART_IrDAMode_Normal
651 * Output : None
652 * Return : None
653 *******************************************************************************/
654 void USART_IrDAConfig(USART_TypeDef* USARTx, u16 USART_IrDAMode)
655 {
656 /* Check the parameters */
657 assert(IS_USART_IRDA_MODE(USART_IrDAMode));
658
659 USARTx->CR3 &= CR3_IRLP_Mask;
660 USARTx->CR3 |= USART_IrDAMode;
661 }
662
663 /*******************************************************************************
664 * Function Name : USART_IrDACmd
665 * Description : Enables or disables the USART抯 IrDA interface.
666 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
667 * peripheral.
668 * - NewState: new state of the IrDA mode.
669 * This parameter can be: ENABLE or DISABLE.
670 * Output : None
671 * Return : None
672 *******************************************************************************/
673 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
674 {
675 /* Check the parameters */
676 assert(IS_FUNCTIONAL_STATE(NewState));
677
678 if (NewState != DISABLE)
679 {
680 /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
681 USARTx->CR3 |= CR3_IREN_Set;
682 }
683 else
684 {
685 /* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
686 USARTx->CR3 &= CR3_IREN_Reset;
687 }
688 }
689
690 /*******************************************************************************
691 * Function Name : USART_GetFlagStatus
692 * Description : Checks whether the specified USART flag is set or not.
693 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
694 * peripheral.
695 * - USART_FLAG: specifies the flag to check.
696 * This parameter can be one of the following values:
697 * - USART_FLAG_CTS
698 * - USART_FLAG_LBD
699 * - USART_FLAG_TXE
700 * - USART_FLAG_TC
701 * - USART_FLAG_RXNE
702 * - USART_FLAG_IDLE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -