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