📄 stm32f10x_usart.lst
字号:
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
703 * - USART_FLAG_ORE
704 * - USART_FLAG_NE
705 * - USART_FLAG_FE
706 * - USART_FLAG_PE
707 * Output : None
708 * Return : The new state of USART_FLAG (SET or RESET).
709 *******************************************************************************/
710 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, u16 USART_FLAG)
711 {
712 FlagStatus bitstatus = RESET;
713
714 /* Check the parameters */
715 assert(IS_USART_FLAG(USART_FLAG));
716
717 if ((USARTx->SR & USART_FLAG) != (u16)RESET)
718 {
719 bitstatus = SET;
720 }
721 else
722 {
723 bitstatus = RESET;
724 }
725 return bitstatus;
726 }
727
728 /*******************************************************************************
729 * Function Name : USART_ClearFlag
730 * Description : Clears the USARTx's pending flags.
731 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
732 * peripheral.
733 * - USART_FLAG: specifies the flag to clear.
734 * This parameter can be any combination of the following values:
735 * - USART_FLAG_CTS
736 * - USART_FLAG_LBD
737 * - USART_FLAG_TXE
738 * - USART_FLAG_TC
739 * - USART_FLAG_RXNE
740 * - USART_FLAG_IDLE
741 * - USART_FLAG_ORE
742 * - USART_FLAG_NE
743 * - USART_FLAG_FE
744 * - USART_FLAG_PE
745 * Output : None
746 * Return : None
747 *******************************************************************************/
748 void USART_ClearFlag(USART_TypeDef* USARTx, u16 USART_FLAG)
749 {
750 /* Check the parameters */
751 assert(IS_USART_CLEAR_FLAG(USART_FLAG));
752
753 USARTx->SR &= (u16)~USART_FLAG;
754 }
755
756 /*******************************************************************************
757 * Function Name : USART_GetITStatus
758 * Description : Checks whether the specified USART interrupt has occurred or not.
759 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
760 * peripheral.
761 * - USART_IT: specifies the USART interrupt source to check.
762 * This parameter can be one of the following values:
763 * - USART_IT_PE
764 * - USART_IT_TXE
765 * - USART_IT_TC
766 * - USART_IT_RXNE
767 * - USART_IT_IDLE
768 * - USART_IT_LBD
769 * - USART_IT_CTS
770 * - USART_IT_ORE
771 * - USART_IT_NE
772 * - USART_IT_FE
773 * Output : None
774 * Return : The new state of USART_IT (SET or RESET).
775 *******************************************************************************/
776 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, u16 USART_IT)
777 {
778 u32 bitpos = 0x00, itmask = 0x00, usartreg = 0;
779 ITStatus bitstatus = RESET;
780
781 /* Check the parameters */
782 assert(IS_USART_IT(USART_IT));
783
784 /* Get the USART register index */
785 usartreg = (((u8)USART_IT) >> 0x05);
786
787 /* Get the interrupt position */
788 itmask = USART_IT & USART_IT_Mask;
789
790 itmask = (u32)0x01 << itmask;
791
792 if (usartreg == 0x01) /* The IT is in CR1 register */
793 {
794 itmask &= USARTx->CR1;
795 }
796 else if (usartreg == 0x02) /* The IT is in CR2 register */
797 {
798 itmask &= USARTx->CR2;
799 }
800 else /* The IT is in CR3 register */
801 {
802 itmask &= USARTx->CR3;
803 }
804
805 bitpos = USART_IT >> 0x08;
806
807 bitpos = (u32)0x01 << bitpos;
808 bitpos &= USARTx->SR;
809
810 if ((itmask != (u16)RESET)&&(bitpos != (u16)RESET))
811 {
812 bitstatus = SET;
813 }
814 else
815 {
816 bitstatus = RESET;
817 }
818 return bitstatus;
819 }
820
821 /*******************************************************************************
822 * Function Name : USART_ClearITPendingBit
823 * Description : Clears the USARTx抯 interrupt pending bits.
824 * Input : - USARTx: where x can be 1, 2 or 3 to select the USART
825 * peripheral.
826 * - USART_IT: specifies the interrupt pending bit to clear.
827 * This parameter can be one of the following values:
828 * - USART_IT_PE
829 * - USART_IT_TXE
830 * - USART_IT_TC
831 * - USART_IT_RXNE
832 * - USART_IT_IDLE
833 * - USART_IT_LBD
834 * - USART_IT_CTS
835 * - USART_IT_ORE
836 * - USART_IT_NE
837 * - USART_IT_FE
838 * Output : None
839 * Return : None
840 *******************************************************************************/
841 void USART_ClearITPendingBit(USART_TypeDef* USARTx, u16 USART_IT)
842 {
843 u32 bitpos = 0x00, itmask = 0x00;
844
845 /* Check the parameters */
846 assert(IS_USART_IT(USART_IT));
847
848 bitpos = USART_IT >> 0x08;
849
850 itmask = (u32)0x01 << bitpos;
851 USARTx->SR &= ~itmask;
852 }
853
854 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
Errors: 1
Warnings: none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -