Git Product home page Git Product logo

Comments (2)

kylongmu avatar kylongmu commented on August 22, 2024

在测试发现AT24C02无法正常写入EEPROM,只能正确写入几个不连续的字节,查看代码发现在写入成功的时候没有延时如下所示 rt_err_t at24cxx_write(at24cxx_device_t dev, uint32_t WriteAddr, uint8_t *pBuffer, uint16_t NumToWrite) { uint16_t i = 0; rt_err_t result; RT_ASSERT(dev);

if(WriteAddr + NumToWrite > AT24CXX_MAX_MEM_ADDRESS)
{
    return RT_ERROR;
}

result = rt_mutex_take(dev->lock, RT_WAITING_FOREVER);
if (result == RT_EOK)
{
    while (1) //NumToWrite--
    {
        if (at24cxx_write_one_byte(dev, WriteAddr, pBuffer[i]) != RT_EOK)
        {
            rt_thread_mdelay(EE_TWR);
        }
        else
        {
            WriteAddr++;
            i++;
        }
        if (i == NumToWrite)
        {
            break;
        }

    }
}
else
{
    LOG_E("The at24cxx could not respond  at this time. Please try again");
}
rt_mutex_release(dev->lock);

return RT_EOK;

}

将这个函数改成下面即可成功写入 rt_err_t at24cxx_write(at24cxx_device_t dev, uint32_t WriteAddr, uint8_t *pBuffer, uint16_t NumToWrite) { uint16_t i = 0; rt_err_t result; RT_ASSERT(dev);

if(WriteAddr + NumToWrite > AT24CXX_MAX_MEM_ADDRESS)
{
    return RT_ERROR;
}

result = rt_mutex_take(dev->lock, RT_WAITING_FOREVER);
if (result == RT_EOK)
{
    while (1) //NumToWrite--
    {
        if (at24cxx_write_one_byte(dev, WriteAddr, pBuffer[i]) == RT_EOK)
        {
            WriteAddr++;
        }
        if (++i == NumToWrite)
        {
            break;
        }
        rt_thread_mdelay(EE_TWR);
    }
}
else
{
    LOG_E("The at24cxx could not respond  at this time. Please try again");
}
rt_mutex_release(dev->lock);

return RT_EOK;

}

目前问题依旧,用at24cxx write 后读出只有第一个字节,改为你的每个都延迟后正常。

from at24cxx.

XiaojieFan avatar XiaojieFan commented on August 22, 2024

谢谢

from at24cxx.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.