我把周立功的LPC800例子里面的I2C中的I2C_EEPROM的程序改了一下,还是无法运行,请帮忙看一下。
void I2CInit (void)
{
//原始程序用的最适宜做I2C的口,小板上没有
//LPC_IOCON->PIO0_10 &= ~(0x3 << 8); /* 引脚属性 */
//LPC_IOCON->PIO0_10 |= (0x2 << 8); /* 使能I2C_SDA 增强快速模式 */
//LPC_IOCON->PIO0_11 &= ~(0x3 << 8);
//LPC_IOCON->PIO0_11 |= (0x2 << 8); /* 使能I2C_SCL 增强快速模式 */
/* Pin Assign 8 bit Configuration */
/* I2C0_SDA */
LPC_SWM->PINASSIGN7 = 0x00ffffffUL; /* I2C_SDA ~ P0.0 */
LPC_IOCON->PIO0_0 |= (0x3 << 3); //我按照手册把下拉电阻关了
LPC_IOCON->PIO0_0 |= (1 << 10);
/* I2C0_SCL */
LPC_SWM->PINASSIGN8 = 0xffffff01UL; /* I2C_SCL ~ P0.1 */
LPC_IOCON->PIO0_1 |= (0x3 << 3);
LPC_IOCON->PIO0_1 |= (1 << 10);
//LPC_SWM->PINASSIGN7 &= ~(0xFFUL << 24); /* 管脚分配 */
//LPC_SWM->PINASSIGN7 |= (10 << 24); /* I2C_SDA ~ P0.10 */
//LPC_SWM->PINASSIGN8 &= ~(0xFF << 0);
//LPC_SWM->PINASSIGN8 |= (11 << 0); /* I2C_SCL ~ P0.11 */
/*
* 时钟换算关系: I2C_Pclk = MAIN_CLK / SYSAHBCLKDIV;
* I2C_Fclk = I2C_Pclk / DIVVAL;
* I2C_SCLclk = I2C_Fclk / (MSTSCLLOW + MSTSCLHIGH + 4);
*
* 系统时钟: MAIN_CLK = 24 MHz, SYSAHBCLKDIV = 1;
* I2C增强快速模式: I2C_SCLclk = 400 kHz;
* CAT24C02要求: I2C_Fclk = 8 * I2C_SCLclk = 3.2 MHz, MSTSCLLOW = 2, MSTSCLHIGH = 0;
* DIVVAL = I2C_Pclk / I2C_Fclk - 1= 24 / 3.2 - 1 = 7;
*/
LPC_SYSCON->PRESETCTRL |= (1 << 6);
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 5); /* 初始化I2C AHB时钟 */
LPC_I2C->DIV = 7;
LPC_I2C->MSTTIME |= (0 << 0) | (0 << 4); //不知道为什么原始程序用的是(2<<0),我安装手册改成了(0<<0)
/* SCL_LOW = SCL_HIGH = 2 * CLK */
LPC_I2C->CFG |= (1 << 0) | (0 << 3); /* 使能主机模式,禁止超时 */
}
程序无法运行,我把引脚连到一个LED灯上,板子RESET之后灯没有闪烁,感觉没有输出。
麻烦看一下问题出在什么地方,谢谢。
此帖出自
小平头技术问答
一周热门 更多>