📄 stm32f10x_i2c.lst
字号:
462 * - NewState: new state of the I2C dual addressing mode.
463 * This parameter can be: ENABLE or DISABLE.
464 * Output : None
465 * Return : None
466 *******************************************************************************/
467 void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
468 {
469 /* Check the parameters */
470 assert(IS_FUNCTIONAL_STATE(NewState));
471
472 if (NewState != DISABLE)
473 {
474 /* Enable dual addressing mode */
475 I2Cx->OAR2 |= OAR2_ENDUAL_Set;
476 }
477 else
478 {
479 /* Disable dual addressing mode */
480 I2Cx->OAR2 &= OAR2_ENDUAL_Reset;
481 }
482 }
483
484 /*******************************************************************************
485 * Function Name : I2C_GeneralCallCmd
486 * Description : Enables or disables the specified I2C general call feature.
487 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
488 * - NewState: new state of the I2C General call.
489 * This parameter can be: ENABLE or DISABLE.
490 * Output : None
491 * Return : None
492 *******************************************************************************/
493 void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
494 {
495 /* Check the parameters */
496 assert(IS_FUNCTIONAL_STATE(NewState));
497
498 if (NewState != DISABLE)
499 {
500 /* Enable generall call */
501 I2Cx->CR1 |= CR1_ENGC_Set;
502 }
503 else
504 {
505 /* Disable generall call */
506 I2Cx->CR1 &= CR1_ENGC_Reset;
507 }
508 }
509
510 /*******************************************************************************
511 * Function Name : I2C_ITConfig
512 * Description : Enables or disables the specified I2C interrupts.
513 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
514 * - I2C_IT: specifies the I2C interrupts sources to be enabled
515 * or disabled.
516 * This parameter can be any combination of the following values:
517 * - I2C_IT_BUF: Buffer interrupt mask
518 * - I2C_IT_EVT: Event interrupt mask
519 * - I2C_IT_ERR: Error interrupt mask
520 * - NewState: new state of the specified I2C interrupts.
521 * This parameter can be: ENABLE or DISABLE.
522 * Output : None
523 * Return : None
524 *******************************************************************************/
525 void I2C_ITConfig(I2C_TypeDef* I2Cx, u16 I2C_IT, FunctionalState NewState)
526 {
527 /* Check the parameters */
528 assert(IS_FUNCTIONAL_STATE(NewState));
529 assert(IS_I2C_CONFIG_IT(I2C_IT));
530
531 if (NewState != DISABLE)
532 {
533 /* Enable the selected I2C interrupts */
534 I2Cx->CR2 |= I2C_IT;
535 }
536 else
537 {
538 /* Disable the selected I2C interrupts */
539 I2Cx->CR2 &= (u16)~I2C_IT;
540 }
541 }
542
543 /*******************************************************************************
544 * Function Name : I2C_SendData
545 * Description : Sends a data byte through the I2Cx peripheral.
546 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
547 * - Data: Byte to be transmitted..
548 * Output : None
549 * Return : None
550 *******************************************************************************/
551 void I2C_SendData(I2C_TypeDef* I2Cx, u8 Data)
552 {
553 /* Write in the DR register the data to be sent */
554 I2Cx->DR = Data;
555 }
556
557 /*******************************************************************************
558 * Function Name : I2C_ReceiveData
559 * Description : Returns the most recent received data by the I2Cx peripheral.
560 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
561 * Output : None
562 * Return : The value of the received data.
563 *******************************************************************************/
564 u8 I2C_ReceiveData(I2C_TypeDef* I2Cx)
565 {
566 /* Return the data in the DR register */
567 return (u8)I2Cx->DR;
568 }
569
570 /*******************************************************************************
571 * Function Name : I2C_Send7bitAddress
572 * Description : Transmits the address byte to select the slave device.
573 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
574 * - Address: specifies the slave address which will be transmitted
575 * - I2C_Direction: specifies whether the I2C device will be a
576 * Transmitter or a Receiver.
577 * This parameter can be one of the following values
578 * - I2C_Direction_Transmitter: Transmitter mode
579 * - I2C_Direction_Receiver: Receiver mode
580 * Output : None
581 * Return : None.
582 *******************************************************************************/
583 void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, u8 Address, u8 I2C_Direction)
584 {
585 /* Check the parameters */
586 assert(IS_I2C_DIRECTION(I2C_Direction));
587
588 /* Test on the direction to set/reset the read/write bit */
589 if (I2C_Direction != I2C_Direction_Transmitter)
590 {
591 /* Set the address ADD0 bit0 for read */
592 Address |= OAR1_ADD0_Set;
593 }
594 else
595 {
596 /* Reset the address bit0 for write */
597 Address &= OAR1_ADD0_Reset;
598 }
599 /* Send the address */
600 I2Cx->DR = Address;
601 }
602
603 /*******************************************************************************
604 * Function Name : I2C_ReadRegister
605 * Description : Reads the specified I2C register and returns its value.
606 * Input1 : - I2C_Register: specifies the register to read.
607 * This parameter can be one of the following values:
608 * - I2C_Register_CR1: CR1 register.
609 * - I2C_Register_CR2: CR2 register.
610 * - I2C_Register_OAR1: OAR1 register.
611 * - I2C_Register_OAR2: OAR2 register.
612 * - I2C_Register_DR: DR register.
613 * - I2C_Register_SR1: SR1 register.
614 * - I2C_Register_SR2: SR2 register.
615 * - I2C_Register_CCR: CCR register.
616 * - I2C_Register_TRISE: TRISE register.
617 * Output : None
618 * Return : The value of the read register.
619 *******************************************************************************/
620 u16 I2C_ReadRegister(I2C_TypeDef* I2Cx, u8 I2C_Register)
621 {
622 /* Check the parameters */
623 assert(IS_I2C_REGISTER(I2C_Register));
624
625 /* Return the selected register value */
626 return (*(u16 *)(*((u32 *)&I2Cx) + I2C_Register));
627 }
628
629 /*******************************************************************************
630 * Function Name : I2C_SoftwareResetCmd
631 * Description : Enables or disables the specified I2C software reset.
632 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
633 * - NewState: new state of the I2C software reset.
634 * This parameter can be: ENABLE or DISABLE.
635 * Output : None
636 * Return : None
637 *******************************************************************************/
638 void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
639 {
640 /* Check the parameters */
641 assert(IS_FUNCTIONAL_STATE(NewState));
642
643 if (NewState != DISABLE)
644 {
645 /* Peripheral under reset */
646 I2Cx->CR1 |= CR1_SWRST_Set;
647 }
648 else
649 {
650 /* Peripheral not under reset */
651 I2Cx->CR1 &= CR1_SWRST_Reset;
652 }
653 }
654
655 /*******************************************************************************
656 * Function Name : I2C_SMBusAlertConfig
657 * Description : Drives the SMBusAlert pin high or low for the specified I2C.
658 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
659 * - I2C_SMBusAlert: specifies SMBAlert pin level.
660 * This parameter can be one of the following values:
661 * - I2C_SMBusAlert_Low: SMBAlert pin driven low
662 * - I2C_SMBusAlert_High: SMBAlert pin driven high
663 * Output : None
664 * Return : None
665 *******************************************************************************/
666 void I2C_SMBusAlertConfig(I2C_TypeDef* I2Cx, u16 I2C_SMBusAlert)
667 {
668 /* Check the parameters */
669 assert(IS_I2C_SMBUS_ALERT(I2C_SMBusAlert));
670
671 if (I2C_SMBusAlert == I2C_SMBusAlert_Low)
672 {
673 /* Drive the SMBusAlert pin Low */
674 I2Cx->CR1 |= I2C_SMBusAlert_Low;
675 }
676 else
677 {
678 /* Drive the SMBusAlert pin High */
679 I2Cx->CR1 &= I2C_SMBusAlert_High;
680 }
681 }
682
683 /*******************************************************************************
684 * Function Name : I2C_TransmitPEC
685 * Description : Enables or disables the specified I2C PEC transfer.
686 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
687 * - NewState: new state of the I2C PEC transmission.
688 * This parameter can be: ENABLE or DISABLE.
689 * Output : None
690 * Return : None
691 *******************************************************************************/
692 void I2C_TransmitPEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
693 {
694 /* Check the parameters */
695 assert(IS_FUNCTIONAL_STATE(NewState));
696
697 if (NewState != DISABLE)
698 {
699 /* Enable the selected I2C PEC transmission */
700 I2Cx->CR1 |= CR1_PEC_Set;
701 }
702 else
703 {
704 /* Disable the selected I2C PEC transmission */
705 I2Cx->CR1 &= CR1_PEC_Reset;
706 }
707 }
708
709 /*******************************************************************************
710 * Function Name : I2C_PECPositionConfig
711 * Description : Selects the specified I2C PEC position.
712 * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
713 * - I2C_PECPosition: specifies the PEC position.
714 * This parameter can be one of the following values:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -