本帖最后由 一只耳朵怪 于 2018-6-21 15:40 编辑
大家好:
我是根据Startware中的 MLO 使用I2C0与PMIC例程来修改的。程序调试卡在 while(I2CMasterBusBusy(SOC_I2C_1_REGS) == 0); 详情如下:
一. 按照套路 修改pinmux,修改时钟初始化等,具体如下:
1. 使用I2C1 脚位E17、E18。
- 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;
- ]
- 2. 时钟初始化参考 startware_02_01_01platformevmAm335xhsi3c.c中的void I2C1ModuleClkConfig(void),代码如下:
- 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)));
- ]
-
- 3. 修改I2C0的SetupReception(),改为I2C1的,代码如下:
- void I2C_1_SetupReception(unsigned int recvlen)
- [
- I 2CSetDataCount(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); //调试时此处一直为真,不知为何?
- I2CMasterDataPut(SOC_I2C_1_REGS, dataToSlave[txCount]);
- I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY);
- 。。。。
]
二. 另请教Am335x作为master, slave add如何设置呢? 我调试时使用0x40 , 35390的datasheet 如附件
不知还有哪里设置有问题,所以请大家帮助,先行谢过。