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

📄 stm32f10x_i2c.lst

📁 编译环境是 iar EWARM ,STM32 下的UCOSII
💻 LST
📖 第 1 页 / 共 5 页
字号:
    145          * Output         : None
    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   70B5               PUSH     {R4-R6,LR}
   \   00000002   85B0               SUB      SP,SP,#+20
   \   00000004   0400               MOVS     R4,R0
   \   00000006   0D00               MOVS     R5,R1
    150            u16 tmpreg = 0, freqrange = 0;
    151            u16 result = 0x04;
    152            u32 pclk1 = 8000000;
    153            RCC_ClocksTypeDef  rcc_clocks;
    154          
    155            /* Check the parameters */
    156            assert_param(IS_I2C_ALL_PERIPH(I2Cx));
    157            assert_param(IS_I2C_MODE(I2C_InitStruct->I2C_Mode));
    158            assert_param(IS_I2C_DUTY_CYCLE(I2C_InitStruct->I2C_DutyCycle));
    159            assert_param(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1));
    160            assert_param(IS_I2C_ACK_STATE(I2C_InitStruct->I2C_Ack));
    161            assert_param(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress));
    162            assert_param(IS_I2C_CLOCK_SPEED(I2C_InitStruct->I2C_ClockSpeed));
    163          
    164          /*---------------------------- I2Cx CR2 Configuration ------------------------*/
    165            /* Get the I2Cx CR2 value */
    166            tmpreg = I2Cx->CR2;
   \   00000008   A688               LDRH     R6,[R4, #+4]
    167            /* Clear frequency FREQ[5:0] bits */
    168            tmpreg &= CR2_FREQ_Reset;
    169            /* Get pclk1 frequency value */
    170            RCC_GetClocksFreq(&rcc_clocks);
   \   0000000A   6846               MOV      R0,SP
   \   0000000C   ........           _BLF     RCC_GetClocksFreq,??RCC_GetClocksFreq??rT
    171            pclk1 = rcc_clocks.PCLK1_Frequency;
   \   00000010   0298               LDR      R0,[SP, #+8]
    172            /* Set frequency bits depending on pclk1 value */
    173            freqrange = (u16)(pclk1 / 1000000);
   \   00000012   2649               LDR.N    R1,??I2C_Init_0  ;; 0xf4240
   \   00000014   B0FBF1F1           UDIV     R1,R0,R1
   \   00000018   89B2               UXTH     R1,R1
    174            tmpreg |= freqrange;
    175            /* Write to I2Cx CR2 */
    176            I2Cx->CR2 = tmpreg;
   \   0000001A   254A               LDR.N    R2,??I2C_Init_0+0x4  ;; 0xffc0
   \   0000001C   3240               ANDS     R2,R2,R6
   \   0000001E   0B00               MOVS     R3,R1
   \   00000020   1343               ORRS     R3,R3,R2
   \   00000022   A380               STRH     R3,[R4, #+4]
    177          
    178          /*---------------------------- I2Cx CCR Configuration ------------------------*/
    179            /* Disable the selected I2C peripheral to configure TRISE */
    180            I2Cx->CR1 &= CR1_PE_Reset;
   \   00000024   2288               LDRH     R2,[R4, #+0]
   \   00000026   ....               LDR.N    R3,??DataTable6  ;; 0xfffe
   \   00000028   1340               ANDS     R3,R3,R2
   \   0000002A   2380               STRH     R3,[R4, #+0]
    181          
    182            /* Reset tmpreg value */
    183            /* Clear F/S, DUTY and CCR[11:0] bits */
    184            tmpreg = 0;
    185          
    186            /* Configure speed in standard mode */
    187            if (I2C_InitStruct->I2C_ClockSpeed <= 100000)
   \   0000002C   EA68               LDR      R2,[R5, #+12]
   \   0000002E   214B               LDR.N    R3,??I2C_Init_0+0x8  ;; 0x186a1
   \   00000030   9A42               CMP      R2,R3
   \   00000032   09D2               BCS.N    ??I2C_Init_1
    188            {
    189              /* Standard mode speed calculate */
    190              result = (u16)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed << 1));
   \   00000034   5200               LSLS     R2,R2,#+1
   \   00000036   B0FBF2F0           UDIV     R0,R0,R2
    191              /* Test if CCR value is under 0x4*/
    192              if (result < 0x04)
   \   0000003A   80B2               UXTH     R0,R0
   \   0000003C   0428               CMP      R0,#+4
   \   0000003E   00D2               BCS.N    ??I2C_Init_2
    193              {
    194                /* Set minimum allowed value */
    195                result = 0x04;  
   \   00000040   0420               MOVS     R0,#+4
    196              }
    197              /* Set speed value for standard mode */
    198              tmpreg |= result;	  
    199              /* Set Maximum Rise Time for standard mode */
    200              I2Cx->TRISE = freqrange + 1; 
   \                     ??I2C_Init_2:
   \   00000042   491C               ADDS     R1,R1,#+1
   \   00000044   2184               STRH     R1,[R4, #+32]
   \   00000046   1EE0               B.N      ??I2C_Init_3
    201            }
    202            /* Configure speed in fast mode */
    203            else /*(I2C_InitStruct->I2C_ClockSpeed <= 400000)*/
    204            {
    205              if (I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_2)
   \                     ??I2C_Init_1:
   \   00000048   6A88               LDRH     R2,[R5, #+2]
   \   0000004A   ....               LDR.N    R3,??DataTable9  ;; 0xbfff
   \   0000004C   9A42               CMP      R2,R3
   \   0000004E   EA68               LDR      R2,[R5, #+12]
   \   00000050   04D1               BNE.N    ??I2C_Init_4
    206              {
    207                /* Fast mode speed calculate: Tlow/Thigh = 2 */
    208                result = (u16)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 3));
   \   00000052   0323               MOVS     R3,#+3
   \   00000054   5A43               MULS     R2,R3,R2
   \   00000056   B0FBF2F0           UDIV     R0,R0,R2
   \   0000005A   05E0               B.N      ??I2C_Init_5
    209              }
    210              else /*I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_16_9*/
    211              {
    212                /* Fast mode speed calculate: Tlow/Thigh = 16/9 */
    213                result = (u16)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 25));
    214                /* Set DUTY bit */
    215                result |= I2C_DutyCycle_16_9;
   \                     ??I2C_Init_4:
   \   0000005C   1923               MOVS     R3,#+25
   \   0000005E   5A43               MULS     R2,R3,R2
   \   00000060   B0FBF2F0           UDIV     R0,R0,R2
   \   00000064   50F48040           ORRS     R0,R0,#0x4000
    216              }
    217              /* Test if CCR value is under 0x1*/
    218              if ((result & CCR_CCR_Set) == 0)
   \                     ??I2C_Init_5:
   \   00000068   0205               LSLS     R2,R0,#+20
   \   0000006A   01D1               BNE.N    ??I2C_Init_6
    219              {
    220                /* Set minimum allowed value */
    221                result |= (u16)0x0001;  
   \   0000006C   50F00100           ORRS     R0,R0,#0x1
    222              }
    223              /* Set speed value and set F/S bit for fast mode */
    224              tmpreg |= result | CCR_FS_Set;
   \                     ??I2C_Init_6:
   \   00000070   50F40040           ORRS     R0,R0,#0x8000
    225              /* Set Maximum Rise Time for fast mode */
    226              I2Cx->TRISE = (u16)(((freqrange * 300) / 1000) + 1);  
   \   00000074   5FF49672           MOVS     R2,#+300
   \   00000078   5143               MULS     R1,R2,R1
   \   0000007A   5FF47A72           MOVS     R2,#+1000
   \   0000007E   91FBF2F1           SDIV     R1,R1,R2
   \   00000082   491C               ADDS     R1,R1,#+1
   \   00000084   2184               STRH     R1,[R4, #+32]
    227            }
    228            /* Write to I2Cx CCR */
    229            I2Cx->CCR = tmpreg;
   \                     ??I2C_Init_3:
   \   00000086   A083               STRH     R0,[R4, #+28]
    230          
    231            /* Enable the selected I2C peripheral */
    232            I2Cx->CR1 |= CR1_PE_Set;
   \   00000088   2088               LDRH     R0,[R4, #+0]
   \   0000008A   50F00100           ORRS     R0,R0,#0x1
   \   0000008E   2080               STRH     R0,[R4, #+0]
    233          
    234          /*---------------------------- I2Cx CR1 Configuration ------------------------*/
    235            /* Get the I2Cx CR1 value */
    236            tmpreg = I2Cx->CR1;
   \   00000090   2088               LDRH     R0,[R4, #+0]
    237            /* Clear ACK, SMBTYPE and  SMBUS bits */
    238            tmpreg &= CR1_CLEAR_Mask;
    239            /* Configure I2Cx: mode and acknowledgement */
    240            /* Set SMBTYPE and SMBUS bits according to I2C_Mode value */
    241            /* Set ACK bit according to I2C_Ack value */
    242            tmpreg |= (u16)((u32)I2C_InitStruct->I2C_Mode | I2C_InitStruct->I2C_Ack);
    243            /* Write to I2Cx CR1 */
    244            I2Cx->CR1 = tmpreg;
   \   00000092   0949               LDR.N    R1,??I2C_Init_0+0xC  ;; 0xfbf5
   \   00000094   0140               ANDS     R1,R1,R0
   \   00000096   2888               LDRH     R0,[R5, #+0]
   \   00000098   0843               ORRS     R0,R0,R1
   \   0000009A   E988               LDRH     R1,[R5, #+6]
   \   0000009C   0143               ORRS     R1,R1,R0
   \   0000009E   2180               STRH     R1,[R4, #+0]
    245          
    246          /*---------------------------- I2Cx OAR1 Configuration -----------------------*/
    247            /* Set I2Cx Own Address1 and acknowledged address */
    248            I2Cx->OAR1 = (I2C_InitStruct->I2C_AcknowledgedAddress | I2C_InitStruct->I2C_OwnAddress1);
   \   000000A0   2889               LDRH     R0,[R5, #+8]
   \   000000A2   A988               LDRH     R1,[R5, #+4]
   \   000000A4   0143               ORRS     R1,R1,R0
   \   000000A6   2181               STRH     R1,[R4, #+8]
    249          }
   \   000000A8   05B0               ADD      SP,SP,#+20
   \   000000AA   70BD               POP      {R4-R6,PC}       ;; return
   \                     ??I2C_Init_0:
   \   000000AC   40420F00           DC32     0xf4240
   \   000000B0   C0FF0000           DC32     0xffc0
   \   000000B4   A1860100           DC32     0x186a1
   \   000000B8   F5FB0000           DC32     0xfbf5
    250          
    251          /*******************************************************************************
    252          * Function Name  : I2C_StructInit
    253          * Description    : Fills each I2C_InitStruct member with its default value.
    254          * Input          : - I2C_InitStruct: pointer to an I2C_InitTypeDef structure
    255          *                    which will be initialized.
    256          * Output         : None
    257          * Return         : None
    258          *******************************************************************************/

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

⌨️ 快捷键说明

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