📄 stm32f10x_i2c.lst
字号:
715 * - I2C_PECPosition_Next: PEC bit indicates that current
716 * byte is PEC
717 * - I2C_PECPosition_Current: PEC bit indicates that the
718 * next byte is PEC
719 * Output : None
720 * Return : None
721 *******************************************************************************/
722 void I2C_PECPositionConfig(I2C_TypeDef* I2Cx, u16 I2C_PECPosition)
723 {
724 /* Check the parameters */
725 assert(IS_I2C_PEC_POSITION(I2C_PECPosition));
726
727 if (I2C_PECPosition == I2C_PECPosition_Next)
728 {
729 /* PEC indicates that the next byte in shift register is PEC */
730 I2Cx->CR1 |= I2C_PECPosition_Next;
731 }
732 else
733 {
734 /* PEC indicates that the current byte in shift register is PEC */
735 I2Cx->CR1 &= I2C_PECPosition_Current;
736 }
737 }
738
739 /*******************************************************************************
740 * Function Name : I2C_CalculatePEC
741 * Description : Enables or disables the PEC value calculation of the
742 * transfered bytes.
743 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
744 * - NewState: new state of the I2Cx PEC value calculation.
745 * This parameter can be: ENABLE or DISABLE.
746 * Output : None
747 * Return : None
748 *******************************************************************************/
749 void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
750 {
751 /* Check the parameters */
752 assert(IS_FUNCTIONAL_STATE(NewState));
753
754 if (NewState != DISABLE)
755 {
756 /* Enable the selected I2C PEC calculation */
757 I2Cx->CR1 |= CR1_ENPEC_Set;
758 }
759 else
760 {
761 /* Disable the selected I2C PEC calculation */
762 I2Cx->CR1 &= CR1_ENPEC_Reset;
763 }
764 }
765
766 /*******************************************************************************
767 * Function Name : I2C_GetPEC
768 * Description : Returns the PEC value for the specified I2C.
769 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
770 * Output : None
771 * Return : The PEC value.
772 *******************************************************************************/
773 u8 I2C_GetPEC(I2C_TypeDef* I2Cx)
774 {
775 u8 pec;
776
777 /* Get the PEC value */
778 pec = (I2Cx->SR2) >> 8;
779 /* Return the selected I2C PEC register value */
780 return pec;
781 }
782
783 /*******************************************************************************
784 * Function Name : I2C_ARPCmd
785 * Description : Enables or disables the specified I2C ARP.
786 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
787 * - NewState: new state of the I2Cx ARP.
788 * This parameter can be: ENABLE or DISABLE.
789 * Output : None
790 * Return : None
791 *******************************************************************************/
792 void I2C_ARPCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
793 {
794 /* Check the parameters */
795 assert(IS_FUNCTIONAL_STATE(NewState));
796
797 if (NewState != DISABLE)
798 {
799 /* Enable the selected I2C ARP */
800 I2Cx->CR1 |= CR1_ENARP_Set;
801 }
802 else
803 {
804 /* Disable the selected I2C ARP */
805 I2Cx->CR1 &= CR1_ENARP_Reset;
806 }
807 }
808
809 /*******************************************************************************
810 * Function Name : I2C_StretchClockCmd
811 * Description : Enables or disables the specified I2C Clock stretching.
812 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
813 * - NewState: new state of the I2Cx Clock stretching.
814 * This parameter can be: ENABLE or DISABLE.
815 * Output : None
816 * Return : None
817 *******************************************************************************/
818 void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
819 {
820 /* Check the parameters */
821 assert(IS_FUNCTIONAL_STATE(NewState));
822
823 if (NewState == DISABLE)
824 {
825 /* Enable the selected I2C Clock stretching */
826 I2Cx->CR1 |= CR1_NOSTRETCH_Set;
827 }
828 else
829 {
830 /* Disable the selected I2C Clock stretching */
831 I2Cx->CR1 &= CR1_NOSTRETCH_Reset;
832 }
833 }
834
835 /*******************************************************************************
836 * Function Name : I2C_FastModeDutyCycleConfig
837 * Description : Selects the specified I2C fast mode duty cycle.
838 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
839 * - I2C_DutyCycle: specifies the fast mode duty cycle.
840 * This parameter can be one of the following values:
841 * - I2C_DutyCycle_2: I2C fast mode Tlow/Thigh = 2
842 * - I2C_DutyCycle_16_9: I2C fast mode Tlow/Thigh = 16/9
843 * Output : None
844 * Return : None
845 *******************************************************************************/
846 void I2C_FastModeDutyCycleConfig(I2C_TypeDef* I2Cx, u16 I2C_DutyCycle)
847 {
848 /* Check the parameters */
849 assert(IS_I2C_DUTY_CYCLE(I2C_DutyCycle));
850
851 if (I2C_DutyCycle != I2C_DutyCycle_16_9)
852 {
853 /* I2C fast mode Tlow/Thigh=2 */
854 I2Cx->CCR &= I2C_DutyCycle_2;
855 }
856 else
857 {
858 /* I2C fast mode Tlow/Thigh=16/9 */
859 I2Cx->CCR |= I2C_DutyCycle_16_9;
860 }
861 }
862
863 /*******************************************************************************
864 * Function Name : I2C_GetLastEvent
865 * Description : Returns the last I2Cx Event.
866 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
867 * Output : None
868 * Return : The last event
869 *******************************************************************************/
870 u32 I2C_GetLastEvent(I2C_TypeDef* I2Cx)
871 {
872 u32 LastEvent = 0;
873 u32 Flag1 = 0, Flag2 = 0;
874
875 Flag1 = I2Cx->SR1;
876 Flag2 = I2Cx->SR2;
877 Flag2 = Flag2 << 16;
878
879 /* Get the last event value from I2C status register */
880 LastEvent = (Flag1 | Flag2) & I2C_FLAG_Mask;
881
882 /* Return status */
883 return LastEvent;
884 }
885
886 /*******************************************************************************
887 * Function Name : I2C_CheckEvent
888 * Description : Checks whether the last I2Cx Event is equal to the one passed
889 * as parameter.
890 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
891 * - I2C_EVENT: specifies the event to be checked.
892 * This parameter can be one of the following values:
893 * - I2C_EVENT_SLAVE_ADDRESS_MATCHED : EV1
894 * - I2C_EVENT_SLAVE_BYTE_RECEIVED : EV2
895 * - I2C_EVENT_SLAVE_BYTE_TRANSMITTED : EV3
896 * - I2C_EVENT_SLAVE_ACK_FAILURE : EV3-1
897 * - I2C_EVENT_MASTER_MODE_SELECT : EV5
898 * - I2C_EVENT_MASTER_MODE_SELECTED : EV6
899 * - I2C_EVENT_MASTER_BYTE_RECEIVED : EV7
900 * - I2C_EVENT_MASTER_BYTE_TRANSMITTED : EV8
901 * - I2C_EVENT_MASTER_MODE_ADDRESS10 : EV9
902 * - I2C_EVENT_SLAVE_STOP_DETECTED : EV4
903 * Output : None
904 * Return : An ErrorStatus enumuration value:
905 * - SUCCESS: Last event is equal to the I2C_Event
906 * - ERROR: Last event is different from the I2C_Event
907 *******************************************************************************/
908 ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, u32 I2C_EVENT)
909 {
910 u32 LastEvent = 0;
911 u32 Flag1 = 0, Flag2 = 0;
912 ErrorStatus status = ERROR;
913
914 /* Check the parameters */
915 assert(IS_I2C_EVENT(I2C_EVENT));
916
917 Flag1 = I2Cx->SR1;
918 Flag2 = I2Cx->SR2;
919 Flag2 = Flag2 << 16;
920
921 /* Get the last event value from I2C status register */
922 LastEvent = (Flag1 | Flag2) & I2C_FLAG_Mask;
923
924 /* Check whether the last event is equal to I2C_EVENT */
925 if (LastEvent == I2C_EVENT )
926 {
927 /* SUCCESS: last event is equal to I2C_EVENT */
928 status = SUCCESS;
929 }
930 else
931 {
932 /* ERROR: last event is different from I2C_EVENT */
933 status = ERROR;
934 }
935
936 /* Return status */
937 return status;
938 }
939
940 /*******************************************************************************
941 * Function Name : I2C_GetFlagStatus
942 * Description : Checks whether the specified I2C flag is set or not.
943 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
944 * - I2C_FLAG: specifies the flag to check.
945 * This parameter can be one of the following values:
946 * - I2C_FLAG_DUALF: Dual flag (Slave mode)
947 * - I2C_FLAG_SMBHOST: SMBus host header (Slave mode)
948 * - I2C_FLAG_SMBDEFAULT: SMBus default header (Slave mode)
949 * - I2C_FLAG_GENCALL: General call header flag (Slave mode)
950 * - I2C_FLAG_TRA: Transmitter/Receiver flag
951 * - I2C_FLAG_BUSY: Bus busy flag
952 * - I2C_FLAG_MSL: Master/Slave flag
953 * - I2C_FLAG_SMBALERT: SMBus Alert flag
954 * - I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
955 * - I2C_FLAG_PECERR: PEC error in reception flag
956 * - I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
957 * - I2C_FLAG_AF: Acknowledge failure flag
958 * - I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
959 * - I2C_FLAG_BERR: Bus error flag
960 * - I2C_FLAG_TXE: Data register empty flag (Transmitter)
961 * - I2C_FLAG_RXNE: Data register not empty (Receiver) flag
962 * - I2C_FLAG_STOPF: Stop detection flag (Slave mode)
963 * - I2C_FLAG_ADD10: 10-bit header sent flag (Master mode)
964 * - I2C_FLAG_BTF: Byte transfer finished flag
965 * - I2C_FLAG_ADDR: Address sent flag (Master mode) 揂DSL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -