查看: 4590|回复: 2

[求助] LPC824 IIC的问题

[复制链接]

该用户从未签到

1

主题

1

帖子

0

注册会员

Rank: 2

积分
59
最后登录
2020-5-11
发表于 2020-5-11 21:22:40 | 显示全部楼层 |阅读模式
本帖最后由 coolhe88 于 2020-5-11 21:35 编辑

您好!关于LPC824M201的IIC,有个问题请教一下,谢谢!
硬件:I2C主机:LPC824M201,内部晶体;IIC从机:APDS-9960;IIC两线上拉10K电阻
工具:J-Link V9
问题:在线仿真,主机可以读到从机,功能正常;下载后重新上电,主机识别不了从机。

IIC初始化代码:
//************************************************************//
void I2C_Init(void)
{

  LPC_SYSCON->SYSAHBCLKCTRL |= (I2C0 | SWM);  // Enable clocks to I2C0, SWM (see lpc8xx_syscon.h)

  LPC_SWM->PINENABLE0 &= ~(I2C0_SCL|I2C0_SDA); // Use for LPC824(Enable I2C on P0_10 and P0_11)

  // Give I2C0 a reset  (see lpc8xx_syscon.h)
  LPC_SYSCON->PRESETCTRL &= (I2C0_RST_N);  //Reset IIC.
  LPC_SYSCON->PRESETCTRL |= ~(I2C0_RST_N);  //Clear IIC reset.

  // Configure the I2C0 clock divider
  // Desired bit rate = Fscl = 100,000 Hz (1/Fscl = 10 us, 5 us low and 5 us high)
  // Use default clock high and clock low times (= 2 clocks each)
  // So 4 I2C_PCLKs = 100,000/second, or 1 I2C_PCLK = 400,000/second
  // I2C_PCLK = SystemClock = 30,000,000/second, so we divide by 30/.4 = 75
  // Remember, value written to DIV divides by value+1
  LPC_I2C0->DIV = (75 - 1);

  LPC_I2C0->CFG = CFG_MSTENA;   //Enable LPC824 as IIC master.
}

//************************************************************//
从机检测代码:
//************************************************************//
unsigned char Slave_Check(void)
{
        unsigned char uTemp=0;
        WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_IDLE); // Wait the master state to be idle
        LPC_I2C0->MSTDAT = (Slave_address<<1) | 0;    // Address with 0 for RWn bit (WRITE)
        LPC_I2C0->MSTCTL = CTL_MSTSTART|CTL_MSTCONTINUE;                   // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.
        WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_MTR);   // Wait for the address to be ACK'd

        LPC_I2C0->MSTDAT = APDS9960_ID;                           // Send the data to the slave
        LPC_I2C0->MSTCTL = CTL_MSTCONTINUE;                // Continue the transaction
        WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_MTR);   // Wait for the data to be ACK'd

        LPC_I2C0->MSTDAT = (Slave_address<<1) | 1;    // Address with 1 for RWn bit (Read)
        LPC_I2C0->MSTCTL = CTL_MSTSTART;                   // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.
        WaitI2CMasterState(LPC_I2C0, I2C_STAT_MSTST_MRR);   // Wait for the address to be ACK'd

        uTemp=LPC_I2C0->MSTDAT;
        LPC_I2C0->MSTCTL = CTL_MSTSTOP;                    // Send a stop to end the transaction
        if(uTemp==0xAB)
        {
                return True;
        }
        else
        {
        
        return False;
        }
}

//************************************************************//


我知道答案 目前已有2人回答
回复

使用道具 举报

  • TA的每日心情
    慵懒
    2021-12-23 09:57
  • 签到天数: 1587 天

    连续签到: 1 天

    [LV.Master]伴坛终老

    5

    主题

    3048

    帖子

    23

    金牌会员

    Rank: 6Rank: 6

    积分
    8416
    最后登录
    2025-4-23
    发表于 2020-5-12 09:56:16 | 显示全部楼层
    抓IIC波形看吧,示波器/逻辑分析仪都行。
    感觉系统时钟异常。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    712

    主题

    6371

    帖子

    0

    超级版主

    Rank: 8Rank: 8

    积分
    24890
    最后登录
    2025-7-21
    发表于 2020-5-12 13:32:07 | 显示全部楼层
    正如二楼说的,抓取波形看看,比较一下仿真和实际代码运行时的差别
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-21 17:11 , Processed in 0.084804 second(s), 22 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表