⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_i2c.lst

📁 针对STM32F103的UCOS移植
💻 LST
📖 第 1 页 / 共 5 页
字号:
    146          * Return         : None
    147          ******************************************************************************/

   \                                 In segment CODE, align 4, keep-with-next
    148          void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct)
    149          {
   \                     I2C_Init:
   \   00000000   2DE9F041           PUSH     {R4-R8,LR}
   \   00000004   85B0               SUB      SP,SP,#+20
   \   00000006   0400               MOVS     R4,R0
   \   00000008   0D00               MOVS     R5,R1
    150            u16 tmpreg = 0, freqrange = 0;
    151            u16 result = 0x04;
    152            u32 pclk1clock = 12000000;
    153            RCC_ClocksTypeDef  RCC_Clocks;
    154          
    155            /* Check the parameters */
    156            assert(IS_I2C_MODE(I2C_InitStruct->I2C_Mode));
    157            assert(IS_I2C_DUTY_CYCLE(I2C_InitStruct->I2C_DutyCycle));
    158            assert(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1));
    159            assert(IS_I2C_ACK_STATE(I2C_InitStruct->I2C_Ack));
    160            assert(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress));
    161            assert(IS_I2C_CLOCK_SPEED(I2C_InitStruct->I2C_ClockSpeed));
    162          
    163          /*---------------------------- I2Cx CR2 Configuration ------------------------*/
    164            /* Get the I2Cx CR2 value */
    165            tmpreg = I2Cx->CR2;
   \   0000000A   A088               LDRH     R0,[R4, #+4]
   \   0000000C   8046               MOV      R8,R0
    166            /* Clear frequency FREQ[5:0] bits */
    167            tmpreg &= CR2_FREQ_Reset;
    168            /* Get PCLK1Clock frequency value */
    169            RCC_GetClocksFreq(&RCC_Clocks);
   \   0000000E   6846               MOV      R0,SP
   \   00000010   ........           _BLF     RCC_GetClocksFreq,??RCC_GetClocksFreq??rT
    170            pclk1clock = RCC_Clocks.PCLK1_Frequency;
   \   00000014   029F               LDR      R7,[SP, #+8]
    171            /* Set frequency bits depending on PCLK1Clock value */
    172            freqrange = (u16)(pclk1clock / 1000000);
   \   00000016   2748               LDR.N    R0,??I2C_Init_0  ;; 0xf4240
   \   00000018   B7FBF0F6           UDIV     R6,R7,R0
   \   0000001C   B6B2               UXTH     R6,R6
    173            tmpreg |= freqrange;
    174            /* Write to I2Cx CR2 */
    175            I2Cx->CR2 = tmpreg;
   \   0000001E   2648               LDR.N    R0,??I2C_Init_0+0x4  ;; 0xffc0
   \   00000020   10EA0800           ANDS     R0,R0,R8
   \   00000024   3100               MOVS     R1,R6
   \   00000026   0143               ORRS     R1,R1,R0
   \   00000028   A180               STRH     R1,[R4, #+4]
    176          
    177          /*---------------------------- I2Cx CCR Configuration ------------------------*/
    178            /* Disable I2Cx to configure TRISE */
    179            I2C_Cmd(I2Cx, DISABLE);
   \   0000002A   0021               MOVS     R1,#+0
   \   0000002C   2000               MOVS     R0,R4
   \   0000002E   ........           BL       I2C_Cmd
    180          
    181            /* Reset tmpreg value */
    182            /* Clear F/S, DUTY and CCR[11:0] bits */
    183            tmpreg = 0;
    184          
    185            /* Configure speed in standard mode */
    186            if (I2C_InitStruct->I2C_ClockSpeed <= 100000)
   \   00000032   E868               LDR      R0,[R5, #+12]
   \   00000034   2149               LDR.N    R1,??I2C_Init_0+0x8  ;; 0x186a1
   \   00000036   8842               CMP      R0,R1
   \   00000038   09D2               BCS.N    ??I2C_Init_1
    187            {
    188              /* Standard mode speed calculate */
    189              result = (u16)(pclk1clock / (I2C_InitStruct->I2C_ClockSpeed << 1));
   \   0000003A   4000               LSLS     R0,R0,#+1
   \   0000003C   B7FBF0F0           UDIV     R0,R7,R0
    190              /* Test if CCR value is under 0x4*/
    191              if (result < 0x04)
   \   00000040   80B2               UXTH     R0,R0
   \   00000042   0428               CMP      R0,#+4
   \   00000044   00D2               BCS.N    ??I2C_Init_2
    192              {
    193                /* Set minimum allowed value */
    194                result = 0x04;  
   \   00000046   0420               MOVS     R0,#+4
    195              }
    196              /* Set speed value for standard mode */
    197              tmpreg |= result;	  
    198              /* Set Maximum Rise Time: ((1000/(1000000000/pclk1clock))+1 */
    199              I2Cx->TRISE = freqrange + 1; 
   \                     ??I2C_Init_2:
   \   00000048   761C               ADDS     R6,R6,#+1
   \   0000004A   2684               STRH     R6,[R4, #+32]
   \   0000004C   1EE0               B.N      ??I2C_Init_3
    200            }
    201            /* Configure speed in fast mode */
    202            else /*(I2C_InitStruct->I2C_ClockSpeed <= 400000)*/
    203            {
    204              if (I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_2)
   \                     ??I2C_Init_1:
   \   0000004E   6888               LDRH     R0,[R5, #+2]
   \   00000050   ....               LDR.N    R1,??DataTable8  ;; 0xbfff
   \   00000052   8842               CMP      R0,R1
   \   00000054   E868               LDR      R0,[R5, #+12]
   \   00000056   04D1               BNE.N    ??I2C_Init_4
    205              {
    206                /* Fast mode speed calculate: Tlow/Thigh = 2 */
    207                result = (u16)(pclk1clock / (I2C_InitStruct->I2C_ClockSpeed * 3));
   \   00000058   0321               MOVS     R1,#+3
   \   0000005A   4843               MULS     R0,R1,R0
   \   0000005C   B7FBF0F0           UDIV     R0,R7,R0
   \   00000060   05E0               B.N      ??I2C_Init_5
    208              }
    209              else /*I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_16_9*/
    210              {
    211                /* Fast mode speed calculate: Tlow/Thigh = 16/9 */
    212                result = (u16)(pclk1clock / (I2C_InitStruct->I2C_ClockSpeed * 25));
    213                /* Set DUTY bit */
    214                result |= I2C_DutyCycle_16_9;
   \                     ??I2C_Init_4:
   \   00000062   1921               MOVS     R1,#+25
   \   00000064   4843               MULS     R0,R1,R0
   \   00000066   B7FBF0F0           UDIV     R0,R7,R0
   \   0000006A   50F48040           ORRS     R0,R0,#0x4000
    215              }
    216              /* Test if CCR value is under 0x1*/
    217              if ((result & CCR_CCR_Set) == 0)
   \                     ??I2C_Init_5:
   \   0000006E   0105               LSLS     R1,R0,#+20
   \   00000070   01D1               BNE.N    ??I2C_Init_6
    218              {
    219                /* Set minimum allowed value */
    220                result |= (u16)0x0001;  
   \   00000072   50F00100           ORRS     R0,R0,#0x1
    221              }
    222              /* Set speed value and set F/S bit for fast mode */
    223              tmpreg |= result | CCR_FS_Set;
   \                     ??I2C_Init_6:
   \   00000076   50F40040           ORRS     R0,R0,#0x8000
    224              /* Set Maximum Rise Time: ((300/(1000000000/pclk1clock))+1 */
    225              I2Cx->TRISE = (u16)(((freqrange * 300) / 1000) + 1);  
   \   0000007A   5FF49671           MOVS     R1,#+300
   \   0000007E   4E43               MULS     R6,R1,R6
   \   00000080   5FF47A71           MOVS     R1,#+1000
   \   00000084   96FBF1F1           SDIV     R1,R6,R1
   \   00000088   491C               ADDS     R1,R1,#+1
   \   0000008A   2184               STRH     R1,[R4, #+32]
    226            }
    227            /* Write to I2Cx CCR */
    228            I2Cx->CCR = tmpreg;
   \                     ??I2C_Init_3:
   \   0000008C   A083               STRH     R0,[R4, #+28]
    229          
    230            /* Enable I2Cx */
    231            I2C_Cmd(I2Cx, ENABLE);
   \   0000008E   0121               MOVS     R1,#+1
   \   00000090   2000               MOVS     R0,R4
   \   00000092   ........           BL       I2C_Cmd
    232          
    233          /*---------------------------- I2Cx CR1 Configuration ------------------------*/
    234            /* Get the I2Cx CR1 value */
    235            tmpreg = I2Cx->CR1;
   \   00000096   2088               LDRH     R0,[R4, #+0]
    236            /* Clear ACK, SMBTYPE and  SMBUS bits */
    237            tmpreg &= CR1_CLEAR_Mask;
    238            /* Configure I2Cx: mode and acknowledgement */
    239            /* Set SMBTYPE and SMBUS bits according to I2C_Mode value */
    240            /* Set ACK bit according to I2C_Ack value */
    241            tmpreg |= (u16)((u32)I2C_InitStruct->I2C_Mode | I2C_InitStruct->I2C_Ack);
    242            /* Write to I2Cx CR1 */
    243            I2Cx->CR1 = tmpreg;
   \   00000098   0949               LDR.N    R1,??I2C_Init_0+0xC  ;; 0xfbf5
   \   0000009A   0140               ANDS     R1,R1,R0
   \   0000009C   2888               LDRH     R0,[R5, #+0]
   \   0000009E   0843               ORRS     R0,R0,R1
   \   000000A0   E988               LDRH     R1,[R5, #+6]
   \   000000A2   0143               ORRS     R1,R1,R0
   \   000000A4   2180               STRH     R1,[R4, #+0]
    244          
    245          /*---------------------------- I2Cx OAR1 Configuration -----------------------*/
    246            /* Set I2Cx Own Address1 and acknowledged address */
    247            I2Cx->OAR1 = (I2C_InitStruct->I2C_AcknowledgedAddress | I2C_InitStruct->I2C_OwnAddress1);
   \   000000A6   2889               LDRH     R0,[R5, #+8]
   \   000000A8   A988               LDRH     R1,[R5, #+4]
   \   000000AA   0143               ORRS     R1,R1,R0
   \   000000AC   2181               STRH     R1,[R4, #+8]
    248          }
   \   000000AE   05B0               ADD      SP,SP,#+20
   \   000000B0   BDE8F081           POP      {R4-R8,PC}       ;; return
   \                     ??I2C_Init_0:
   \   000000B4   40420F00           DC32     0xf4240
   \   000000B8   C0FF0000           DC32     0xffc0
   \   000000BC   A1860100           DC32     0x186a1
   \   000000C0   F5FB0000           DC32     0xfbf5
    249          
    250          /*******************************************************************************
    251          * Function Name  : I2C_StructInit
    252          * Description    : Fills each I2C_InitStruct member with its default value.
    253          * Input          : - I2C_InitStruct: pointer to an I2C_InitTypeDef structure
    254          *                    which will be initialized.
    255          * Output         : None
    256          * Return         : None
    257          *******************************************************************************/

   \                                 In segment CODE, align 4, keep-with-next
    258          void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct)
    259          {
    260          /*---------------- Reset I2C init structure parameters values ----------------*/
    261            /* Initialize the I2C_Mode member */
    262            I2C_InitStruct->I2C_Mode = I2C_Mode_I2C;
   \                     I2C_StructInit:
   \   00000000   0021               MOVS     R1,#+0
   \   00000002   0180               STRH     R1,[R0, #+0]
    263          
    264            /* Initialize the I2C_DutyCycle member */
    265            I2C_InitStruct->I2C_DutyCycle = I2C_DutyCycle_2;
   \   00000004   ....               LDR.N    R2,??DataTable8  ;; 0xbfff
   \   00000006   4280               STRH     R2,[R0, #+2]
    266          
    267            /* Initialize the I2C_OwnAddress1 member */
    268            I2C_InitStruct->I2C_OwnAddress1 = 0;
   \   00000008   8180               STRH     R1,[R0, #+4]
    269          
    270            /* Initialize the I2C_Ack member */
    271            I2C_InitStruct->I2C_Ack = I2C_Ack_Disable;
   \   0000000A   C180               STRH     R1,[R0, #+6]
    272          
    273            /* Initialize the I2C_AcknowledgedAddress member */
    274            I2C_InitStruct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
   \   0000000C   5FF48041           MOVS     R1,#+16384
   \   00000010   0181               STRH     R1,[R0, #+8]
    275          
    276            /* initialize the I2C_ClockSpeed member */
    277            I2C_InitStruct->I2C_ClockSpeed = 5000;
   \   00000012   0149               LDR.N    R1,??I2C_StructInit_0  ;; 0x1388
   \   00000014   C160               STR      R1,[R0, #+12]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -