This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

am335x bootloader( modified i2c0 to i2c1 with tps65217 )

Other Parts Discussed in Thread: TPS65217

Dear all:

I've build an bootloader MLO based on starterware tool 2.0.0.1.

Which the MLO can work in the Beaglebone Black(BBB).

However, we made the customized board. 

The HW team designed the am335x's i2c1 intefacing with tps6517c.

In fact, I made some modification in ~/(starterware2.0.0.1)/bootloader/armv7a/am335x/bl_platform.c

I tried to cange the code named I2C_0 to I2C_1

here's the part of changed source code :

-------------------------------

#define  I2C_0                             (0x0u)
#define  I2C_1                             (0x1u)

void SetupI2C(void)
{
    I2C1ModuleClkConfig();

    I2CPinMuxSetup(I2C_1);

    /* Put i2c in reset/disabled state */
    I2CMasterDisable(SOC_I2C_1_REGS);

    I2CSoftReset(SOC_I2C_1_REGS);

    /* Disable auto Idle functionality */
    I2CAutoIdleDisable(SOC_I2C_1_REGS);

    /* Configure i2c bus speed to 100khz */
    I2CMasterInitExpClk(SOC_I2C_1_REGS, I2C_SYSTEM_CLOCK, I2C_INTERNAL_CLOCK,
                                                           I2C_OUTPUT_CLOCK);
    I2CMasterEnable(SOC_I2C_1_REGS);

    while(!I2CSystemStatusGet(SOC_I2C_1_REGS));
}

void SetupI2CTransmit(unsigned int dcount)
{
    I2CSetDataCount(SOC_I2C_1_REGS, dcount);

    CleanupInterrupts();

    I2CMasterControl(SOC_I2C_1_REGS, I2C_CFG_MST_TX);

    I2CMasterStart(SOC_I2C_1_REGS);

    while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0);

    while((I2C_INT_TRANSMIT_READY == (I2CMasterIntRawStatus(SOC_I2C_1_REGS)
                                     & I2C_INT_TRANSMIT_READY)) && dcount--)
    {
        I2CMasterDataPut(SOC_I2C_1_REGS, dataToSlave[tCount++]);

        I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY);
    }

    I2CMasterStop(SOC_I2C_1_REGS);

    while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_STOP_CONDITION));

    I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_STOP_CONDITION);

}

void SetupReception(unsigned int dcount)
{
    I2CSetDataCount(SOC_I2C_1_REGS, 1);

    CleanupInterrupts();

    I2CMasterControl(SOC_I2C_1_REGS, I2C_CFG_MST_TX);

    I2CMasterStart(SOC_I2C_1_REGS);

    while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0);

    I2CMasterDataPut(SOC_I2C_1_REGS, dataToSlave[tCount]);

    I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY);

    while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_ADRR_READY_ACESS));

    I2CSetDataCount(SOC_I2C_1_REGS, dcount);

    CleanupInterrupts();

    I2CMasterControl(SOC_I2C_1_REGS, I2C_CFG_MST_RX);

    I2CMasterStart(SOC_I2C_1_REGS);

    /* Wait till the bus if free */
    while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0);

    /* Read the data from slave of dcount */
    while((dcount--))
    {
        while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_RECV_READY));

        dataFromSlave[rCount++] = I2CMasterDataGet(SOC_I2C_1_REGS);

        I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_RECV_READY);
    }

    I2CMasterStop(SOC_I2C_1_REGS);

    while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_STOP_CONDITION));

    I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_STOP_CONDITION);
}

void TPS65217RegWrite(unsigned char port_level, unsigned char regOffset,
                      unsigned char dest_val, unsigned char mask)
{
    unsigned char read_val;
    unsigned xor_reg;

    dataToSlave[0] = regOffset;
    tCount = 0;
    rCount = 0;

    if(mask != MASK_ALL_BITS)
    {
         SetupReception(1);

         read_val = dataFromSlave[0];
         read_val &= (~mask);
         read_val |= (dest_val & mask);
         dest_val = read_val;
    }

    if(port_level > 0)
    {
         xor_reg = regOffset ^ PASSWORD_UNLOCK;

         dataToSlave[0] = PASSWORD;
         dataToSlave[1] = xor_reg;
         tCount = 0;

         SetupI2CTransmit(2);
    }

    dataToSlave[0] = regOffset;
    dataToSlave[1] = dest_val;
    tCount = 0;

    SetupI2CTransmit(2);

    if(port_level == PROT_LEVEL_2)
    {
         dataToSlave[0] = PASSWORD;
         dataToSlave[1] = xor_reg;
         tCount = 0;

         SetupI2CTransmit(2);

         dataToSlave[0] = regOffset;
         dataToSlave[1] = dest_val;
         tCount = 0;

         SetupI2CTransmit(2);

  }

}

void ConfigVddOpVoltage(void)
{
    SetupI2C();

#ifdef beaglebone

    unsigned char pmic_status = 0;

    /* Configure PMIC slave address */
//kuso modified1
    I2CMasterSlaveAddrSet(SOC_I2C_1_REGS, PMIC_TPS65217_I2C_SLAVE_ADDR);

    TPS65217RegRead(STATUS, &pmic_status);
    /* Increase USB current limit to 1300mA */
    TPS65217RegWrite(PROT_LEVEL_NONE, POWER_PATH, USB_INPUT_CUR_LIMIT_1300MA,
                       USB_INPUT_CUR_LIMIT_MASK);

        /* Set DCDC1 (DDR3) voltage to 1.5V */
    if(isBBB)
    {
        TPS65217VoltageUpdate(DEFDCDC1, DCDC_VOLT_SEL_1500MV);
    }

    /* Set DCDC2 (MPU) voltage to 1.275V */
    TPS65217VoltageUpdate(DEFDCDC2, DCDC_VOLT_SEL_1275MV);

    /* Set LDO3, LDO4 output voltages according to the board */
        if(isBBB)
        {
                TPS65217RegWrite(PROT_LEVEL_2, DEFLS1, LDO_VOLTAGE_OUT_1_8, LDO_MASK);
        }
        else
        {
                TPS65217RegWrite(PROT_LEVEL_2, DEFLS1, LDO_VOLTAGE_OUT_3_3, LDO_MASK);
        }

    TPS65217RegWrite(PROT_LEVEL_2, DEFLS2, LDO_VOLTAGE_OUT_3_3, LDO_MASK);

#elif  defined (evmAM335x) || defined (evmskAM335x)

    /* Configure PMIC slave address */
    I2CMasterSlaveAddrSet(SOC_I2C_1_REGS, PMIC_CNTL_I2C_SLAVE_ADDR);

        /* Select SR I2C(0) */
    SelectI2CInstance(PMIC_DEVCTRL_REG_SR_CTL_I2C_SEL_CTL_I2C);

    /* Configure vdd1- need to validate these parameters */
    ConfigureVdd1(PMIC_VDD1_REG_VGAIN_SEL_X1, PMIC_VDD1_REG_ILMAX_1_5_A,
                      PMIC_VDD1_REG_TSTEP_12_5, PMIC_VDD1_REG_ST_ON_HI_POW);

    /* Select the source for VDD1 control */
    SelectVdd1Source(PMIC_VDD1_OP_REG_CMD_OP);

#else

    #error Unsupported EVM !!

#endif
}

-------------

 How to (1)modify or can I (2)skip to read i2c but set the correct parameter in this code?

Thank you very much if you have any comment and suggestion.

  • Hi Joe,

    The changes you have done to I2C configuration to handle the change in instance from 0 to 1 seems to be correct. However we are not able to understand your question could you please elaborate on your question. "How to (1)modify or can I (2)skip to read i2c but set the correct parameter in this code?"

    Regards

    Anant Pai

  • Dear Anant Pai:

    Thanks for your suggestion.

    For my board laout, I2C1 Pin layout set the diffent layout (I found the the original I2C1 Pin: C16,C17 ) :

    I2C_SCL ---> D17

    I2C_SDA ---> D18

    So  I build the bootloader with AM335X_StarterWare_02_00_01_01.

    Based on the ./AM335X_StarterWare_02_00_01_01/include/hw/soc_AM335x.h
    #define SOC_I2C_0_REGS                       (0x44E0B000)
    #define SOC_I2C_1_REGS                       (0x4802A000)
    #define SOC_I2C_2_REGS                       (0x4819C000)

    void I2CPinMuxSetup(unsigned int instance)
    {

        // modified
        if(instance == 0)
        {
             HWREG(SOC_CONTROL_REGS + CONTROL_CONF_I2C0_SDA)  =
                    (CONTROL_CONF_I2C0_SDA_CONF_I2C0_SDA_RXACTIVE  |
                     CONTROL_CONF_I2C0_SDA_CONF_I2C0_SDA_SLEWCTRL  |
                     CONTROL_CONF_I2C0_SDA_CONF_I2C0_SDA_PUTYPESEL   );

             HWREG(SOC_CONTROL_REGS + CONTROL_CONF_I2C0_SCL)  =
                    (CONTROL_CONF_I2C0_SCL_CONF_I2C0_SCL_RXACTIVE  |
                     CONTROL_CONF_I2C0_SCL_CONF_I2C0_SCL_SLEWCTRL  |
                     CONTROL_CONF_I2C0_SCL_CONF_I2C0_SCL_PUTYPESEL );

        }
        else if(instance == 1)
        {
             HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_RTSN(1))  =
               (CONTROL_CONF_UART1_RTSN_CONF_UART1_RTSN_RXACTIVE  |
               CONTROL_CONF_UART1_RTSN_CONF_UART1_RTSN_SLEWCTRL  |
               CONTROL_CONF_UART1_RTSN_CONF_UART1_RTSN_PUTYPESEL |
               CONTROL_CONF_MUXMODE(3));

             HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_CTSN(1))  =
                  (CONTROL_CONF_UART1_CTSN_CONF_UART1_CTSN_RXACTIVE  |
                   CONTROL_CONF_UART1_CTSN_CONF_UART1_CTSN_SLEWCTRL  |
                   CONTROL_CONF_UART1_CTSN_CONF_UART1_CTSN_PUTYPESEL |
                  CONTROL_CONF_MUXMODE(3));

        } 

    }

    At first, I tried to skip tsp65217 read and update, but it's not work.

    So I tried to modified the code, change interfacing and pinmux.

    The code structure is as following (as same as the org boot code):

    I traced the SetupReceptionI2C function:

    SetupI2C1 
    ----------
    TPS65217RegReadI2C
    --------------------
    CleanupInterruptsI2C
    ----------------------
    I2CMasterControl
    ----------------------
    I2CMasterStart
    ----------------------
    I2CMasterBusBusy       <---------------- Stock here !

    The detial code of SetupReceptionI2C  described as following (changed SOC_I2C_0_REGS to SOC_I2C_1_REGS):

    void SetupReceptionI2C(unsigned int dcount)  // settin
    {
        I2CSetDataCount(SOC_I2C_1_REGS, 1);
        CleanupInterruptsI2C();
        I2CMasterControl(SOC_I2C_1_REGS, I2C_CFG_MST_TX);
        I2CMasterStart(SOC_I2C_1_REGS);
        while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0);

        I2CMasterDataPut(SOC_I2C_1_REGS, dataToSlave[tCount]);
        I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY);
        while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_ADRR_READY_ACESS));
        I2CSetDataCount(SOC_I2C_1_REGS, dcount);
        CleanupInterruptsI2C();
        I2CMasterControl(SOC_I2C_1_REGS, I2C_CFG_MST_RX);
        I2CMasterStart(SOC_I2C_1_REGS);

        /* Wait till the bus if free */
        while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0);
        /* Read the data from slave of dcount */
        while((dcount--))
        {
            while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_RECV_READY));

            dataFromSlave[rCount++] = I2CMasterDataGet(SOC_I2C_1_REGS);

            I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_RECV_READY);
        }
        I2CMasterStop(SOC_I2C_1_REGS);

        while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_STOP_CONDITION));
        I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_STOP_CONDITION);
    }

    void TPS65217RegReadI2C(unsigned char regOffset, unsigned char* dest)
    {
        dataToSlave[0] = regOffset;
        tCount = 0;

        SetupReceptionI2C1(1);

        *dest = dataFromSlave[0];
    }

    void SetupI2C(void)
    {
        I2C1ModuleClkConfig();
        I2CPinMuxSetup(I2C_1);
        /* Put i2c in reset/disabled state */
        I2CMasterDisable(SOC_I2C_1_REGS);
        I2CSoftReset(SOC_I2C_1_REGS);
        /* Disable auto Idle functionality */
        I2CAutoIdleDisable(SOC_I2C_1_REGS);
        /* Configure i2c bus speed to 100khz */
        I2CMasterInitExpClk(SOC_I2C_1_REGS, I2C_SYSTEM_CLOCK, I2C_INTERNAL_CLOCK,
                  I2C_OUTPUT_CLOCK);
        I2CMasterEnable(SOC_I2C_1_REGS);
        while(!I2CSystemStatusGet(SOC_I2C_1_REGS));
    }

    What the key point that I didn't considered,

    Do I need to change I2C1ModuleClkConfig() ?

    Thank you very much if you have any comment or suggestion.

    Best Regards ,Joe.

  • Dear :

    I found that the SOC_I2C_1_REGS is not the memory address within my pinmux.

    need to change to  SOC_I2C_2_REGS

    because I set the pin mux  to mode(3) -> I2C2

    And the memort map address is: 0x4819c000

    However, I also need to modified/add  the clock control function : I2C2ModuleClkConfig();

      ( just lick the function I2C1ModuleClkConfig())

    void I2C1ModuleClkConfig(void)

    {

       HWREG(SOC_PRCM_REGS + CM_PER_L3S_CLKSTCTRL) |=

                                CM_PER_L3S_CLKSTCTRL_CLKTRCTRL_SW_WKUP;

       while((HWREG(SOC_PRCM_REGS + CM_PER_L3S_CLKSTCTRL) &

        CM_PER_L3S_CLKSTCTRL_CLKTRCTRL) != CM_PER_L3S_CLKSTCTRL_CLKTRCTRL_SW_WKUP);

       HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKSTCTRL) |=

                                CM_PER_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP;

       while((HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKSTCTRL) &

        CM_PER_L3_CLKSTCTRL_CLKTRCTRL) != CM_PER_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP);

       HWREG(SOC_PRCM_REGS + CM_PER_L3_INSTR_CLKCTRL) |=

                                CM_PER_L3_INSTR_CLKCTRL_MODULEMODE_ENABLE;

       while((HWREG(SOC_PRCM_REGS + CM_PER_L3_INSTR_CLKCTRL) &

                                  CM_PER_L3_INSTR_CLKCTRL_MODULEMODE) !=

                                      CM_PER_L3_INSTR_CLKCTRL_MODULEMODE_ENABLE);

       HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKCTRL) |=

                                CM_PER_L3_CLKCTRL_MODULEMODE_ENABLE;

       while((HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKCTRL) &

           CM_PER_L3_CLKCTRL_MODULEMODE) != CM_PER_L3_CLKCTRL_MODULEMODE_ENABLE);

       HWREG(SOC_PRCM_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) |=

                                CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP;

       while((HWREG(SOC_PRCM_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) &

                                 CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL) !=

                                   CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP);

       HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKSTCTRL) |=

                                CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL_SW_WKUP;

       while((HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKSTCTRL) &

                                CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL) !=                              

                                CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL_SW_WKUP);

       HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKCTRL) |=

                                CM_PER_L4LS_CLKCTRL_MODULEMODE_ENABLE;

       while((HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKCTRL) &

         CM_PER_L4LS_CLKCTRL_MODULEMODE) != CM_PER_L4LS_CLKCTRL_MODULEMODE_ENABLE);

       HWREG(SOC_PRCM_REGS + CM_PER_I2C1_CLKCTRL) |=

                                CM_PER_I2C1_CLKCTRL_MODULEMODE_ENABLE;

       while((HWREG(SOC_PRCM_REGS + CM_PER_I2C1_CLKCTRL) &

         CM_PER_I2C1_CLKCTRL_MODULEMODE) != CM_PER_I2C1_CLKCTRL_MODULEMODE_ENABLE);

       while(!(HWREG(SOC_PRCM_REGS + CM_PER_L3S_CLKSTCTRL) &

               CM_PER_L3S_CLKSTCTRL_CLKACTIVITY_L3S_GCLK));

       while(!(HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKSTCTRL) &

               CM_PER_L3_CLKSTCTRL_CLKACTIVITY_L3_GCLK));

       while(!(HWREG(SOC_PRCM_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) &

              (CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L3_GCLK |

               CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L4_GCLK)));

       while(!(HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKSTCTRL) &

              (CM_PER_L4LS_CLKSTCTRL_CLKACTIVITY_L4LS_GCLK |

               CM_PER_L4LS_CLKSTCTRL_CLKACTIVITY_I2C_FCLK)));

    }

  • Hi Joe,

    Did you solve the problem?

    I met the same problem as you, which is the code hang  while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0);    ,and your experence give me much help. i try to modify the I2C0 --> I2C1 , but i still have the problem,and don't know why?

    I use  I2C1 to  communication with a  device with I2C interface.

    pinmux: 

    void I2C_PinMuxSetup( void)

    {

    //I2C1_SCL  E17          

    HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_RTSN(0))  = 0x73;

     //I2C1_SDA  E18         

    HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_CTSN(0)) =  0x73;

    }

    I2C1 CLK init:

    void I2C_1_ModuleClkConfig(void)

    {    

    HWREG(SOC_PRCM_REGS + CM_PER_L3S_CLKSTCTRL) |=                              CM_PER_L3S_CLKSTCTRL_CLKTRCTRL_SW_WKUP;

        while((HWREG(SOC_PRCM_REGS + CM_PER_L3S_CLKSTCTRL) &      CM_PER_L3S_CLKSTCTRL_CLKTRCTRL) != CM_PER_L3S_CLKSTCTRL_CLKTRCTRL_SW_WKUP);

        HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKSTCTRL) |=                              CM_PER_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP;

        while((HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKSTCTRL) &      CM_PER_L3_CLKSTCTRL_CLKTRCTRL) != CM_PER_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP);

        HWREG(SOC_PRCM_REGS + CM_PER_L3_INSTR_CLKCTRL) |=                              CM_PER_L3_INSTR_CLKCTRL_MODULEMODE_ENABLE;

        while((HWREG(SOC_PRCM_REGS + CM_PER_L3_INSTR_CLKCTRL) &                                CM_PER_L3_INSTR_CLKCTRL_MODULEMODE) !=                                    CM_PER_L3_INSTR_CLKCTRL_MODULEMODE_ENABLE);

        HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKCTRL) |=                              CM_PER_L3_CLKCTRL_MODULEMODE_ENABLE;

        while((HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKCTRL) &         CM_PER_L3_CLKCTRL_MODULEMODE) != CM_PER_L3_CLKCTRL_MODULEMODE_ENABLE);

        HWREG(SOC_PRCM_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) |=                              CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP;

        while((HWREG(SOC_PRCM_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) &                               CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL) !=                                 CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP);

        HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKSTCTRL) |=                              CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL_SW_WKUP;

        while((HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKSTCTRL) &                              CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL) !=                                CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL_SW_WKUP);

        HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKCTRL) |=                              CM_PER_L4LS_CLKCTRL_MODULEMODE_ENABLE;

        while((HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKCTRL) &       CM_PER_L4LS_CLKCTRL_MODULEMODE) != CM_PER_L4LS_CLKCTRL_MODULEMODE_ENABLE);

        HWREG(SOC_PRCM_REGS + CM_PER_I2C1_CLKCTRL) |=                              CM_PER_I2C1_CLKCTRL_MODULEMODE_ENABLE;

        while((HWREG(SOC_PRCM_REGS + CM_PER_I2C1_CLKCTRL) &       CM_PER_I2C1_CLKCTRL_MODULEMODE) != CM_PER_I2C1_CLKCTRL_MODULEMODE_ENABLE);

        while(!(HWREG(SOC_PRCM_REGS + CM_PER_L3S_CLKSTCTRL) &             CM_PER_L3S_CLKSTCTRL_CLKACTIVITY_L3S_GCLK));

        while(!(HWREG(SOC_PRCM_REGS + CM_PER_L3_CLKSTCTRL) &             CM_PER_L3_CLKSTCTRL_CLKACTIVITY_L3_GCLK));

        while(!(HWREG(SOC_PRCM_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) &            (CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L3_GCLK |             CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L4_GCLK)));

        while(!(HWREG(SOC_PRCM_REGS + CM_PER_L4LS_CLKSTCTRL) &            (CM_PER_L4LS_CLKSTCTRL_CLKACTIVITY_L4LS_GCLK |             CM_PER_L4LS_CLKSTCTRL_CLKACTIVITY_I2C_FCLK)));

    }

    I2C1 init:  (same as the init i2c0 ,just change i2c0-->i2c1)

    void  I2CSetUp( unsigned int bassAdd)

    {  

     I2C_1_ModuleClkConfig();

     I2C_PinMuxSetup();

     /* Put i2c in reset/disabled state */

     I2CMasterDisable(bassAdd);

     I2CSoftReset(bassAdd);

     /* Disable auto Idle functionality */  

    I2CAutoIdleDisable(bassAdd);

     /* Configure i2c bus speed to 100khz */

     I2CMasterInitExpClk(bassAdd, I2C_SYSTEM_CLOCK, I2C_INTERNAL_CLOCK, I2C_OUTPUT_CLOCK);

     I2CMasterEnable(bassAdd);

     while(!I2CSystemStatusGet(bassAdd));

    }

    receive data  function as follow;

    void I2C_1_SetupReception(unsigned int recvlen)

    {    

    I2CSetDataCount(SOC_I2C_1_REGS, 1);

    I2C_1_CleanupInterrupts();

     I2CMasterControl(SOC_I2C_1_REGS, I2C_CFG_MST_TX);    

    I2CMasterStart(SOC_I2C_1_REGS);        

    while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0);      //stop here ,cause the bit  BB is zero

     I2CMasterDataPut(SOC_I2C_1_REGS, dataToSlave[txCount]);    

    I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY);    

    while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_ADRR_READY_ACESS));

        I2CSetDataCount(SOC_I2C_1_REGS, recvlen);

        I2C_1_CleanupInterrupts();

        I2CMasterControl(SOC_I2C_1_REGS, I2C_CFG_MST_RX);

        I2CMasterStart(SOC_I2C_1_REGS);

        /* Wait till the bus if free */    

    while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0);

        /* Read the data from slave of dcount */    

    while((recvlen--))    

    {        

    while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_RECV_READY));

     dataFromSlave[rxCount++] = I2CMasterDataGet(SOC_I2C_1_REGS);

       I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_RECV_READY);    

    }

        I2CMasterStop(SOC_I2C_1_REGS);

        while(0 == (I2CMasterIntRawStatus(SOC_I2C_1_REGS) & I2C_INT_STOP_CONDITION));

        I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_STOP_CONDITION);

    }

    Could someone give me some advice?

    Thansk for ahead.

     

    stone

  • Hi Stone,

    Your code changes to port the code from I2C0 to I2C1 seems to be correct, the code matches with the I2C polling example used in bootloader of StarterWare 02.00.01.01 found at bootloader/src/armv7a/am335x/bl_platform.c

    I suggest you reconfirm the following things like the I2C1 baseaddress you are passing to I2CSetUp( unsigned int bassAdd) function and also confirm you are clearing all the interrupts through I2C_1_CleanupInterrupts API.

    Regards

    Anant