Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C Assert while Reading Slave-Device #544

Open
rapper2000 opened this issue Nov 28, 2023 · 0 comments
Open

I2C Assert while Reading Slave-Device #544

rapper2000 opened this issue Nov 28, 2023 · 0 comments

Comments

@rapper2000
Copy link

1. SDK version(SDK 版本)

{
https://github.com/ZakKemble/GPRS_C_SDK
}


2. In what kind of operation problems appear, and how to reproduce the problem ?(什么样的操作步骤问题会出现,是否是稳定复现,如何复现问题?)

{
I have a basic I2C communication set up, that works fine.
The problem is, that i'm reading a sequence of Registers from a slave device, and sometimes (even I can not get it to reproduce) the read fails with the following exception:

Assert received!! Reading detail...
ASSERT DETAIL :
I2C bus is not configured as used: 0

Tracer Log:
[16:51:20.514] MMI 06 : Reading Register number 7
[16:51:20.514] MMI 06 : Entering read
[16:51:20.514] MMI 06 : Entering open
[16:51:20.514] : Fn 0577036 T1 0435 T2 18 T3 22 Time 00 00 52 864
[16:51:20.514] PAL 01 :
##############################################
FATAL assert
I2C bus is not configured as used: 0
##############################################
[16:51:20.514] SXR 01 : Stack found for Task\n
[16:51:20.514] SXR 01 : Task 29: HTTP GPS Task Priority 233
[16:51:20.514] SXR 01 : is active.\n
[16:51:20.514] SXR 01 : Stack 6312/16384 Top 0x82274a68 <- 0x82278a68\n
[16:51:20.514] SXR 01 : Back trace\n
[16:51:20.514] SXR 01 : 82005a25y\n
[16:51:20.514] SXR 01 : 8200594cy\n
[16:51:20.514] SXR 01 : 881d23bcy\n
[16:51:20.514] SXR 01 : 82005a25y\n
[16:51:20.514] SXR 01 : 82005a05y\n
[16:51:20.514] SXR 01 : 881930efy\n
[16:51:20.514] SXR 01 : 8200e409y\n
[16:51:20.514] SXR 01 : 881930d5y\n
[16:51:20.514] SXR 01 : 8819387dy\n
[16:51:20.514] SXR 01 : 8809e119y\n
[16:51:20.514] SXR 01 : 881c9110y\n
[16:51:20.514] SXR 01 : 881c9110y\n
[16:51:20.514] SXR 01 : 88193883y\n
[16:51:20.514] SXR 01 : 88185ea7y\n

For all the preceding reads (~several hundred) it can work just fine, but then suddenly this error comes up, sometimes at the first reads, sometimes after several minutes of runtime....

I will attach some more code here

int ADXL345_getFIFO(XYZ_Point_t p[], uint16_t length)
{
    I2C_Error_t ret = 0;
    uint8_t regSave = '\x00';
    // Put Device in Standy
    ret = readI2C(ADXL345_REG_POWERCTL, &regSave, 1);
    uint8_t regBuf = regSave & ~ADXL345_PM_MEASURE;
    if (ret) {Trace(ADX_ET, "Failed to read from ADXL345 in getFIFO: read. Error in I2C: %2d", ret); return ret;}
    ret = writeI2C(ADXL345_REG_POWERCTL, &regBuf, 1);
    if (ret) {Trace(ADX_ET, "Failed to write to ADXL345 in getFIFO: write. Error in I2C: %2d", ret); return ret;}
    // Read FIFO (should be 32 Bytes long; read of 0x32 to 0x37 => corresponds to last 2560 ms...)
    int i = 0;
    for (i = length-1; i>=0; i--)
    {
        Trace(I2C_ET, "Reading Register number %d", i);
        ret = readI2C(ADXL345_REG_DATAX0, p[i].raw, 6);
        if (ret) {Trace(ADX_ET, "Failed to read from ADXL345 in getFIFO_for %d: read. Error in I2C: %2d", i, ret); return ret;}
    }
    ret = writeI2C(ADXL345_REG_POWERCTL, &regSave, 1);
    if (ret) {Trace(ADX_ET, "Failed to write to ADXL345 in getFIFO: write_save. Error in I2C: %2d", ret); return ret;}
    return 0;
};

I2C_Error_t writeI2C(uint32_t firstMemAddr, uint8_t * sendBuffer, uint16_t numberOfBytes)
{
    I2C_Error_t ret = I2C_ERROR_NONE;
    if (openI2C()) // Error in open if != I2C_ERROR_NONE (= 0)
    {
        Trace(I2C_ET, "Could NOT open I2C Nr. %d on A9G @ read.\nError was: %d", A9G_I2C_Class.id, ret);
    }
    Trace(I2C_ET, "Middle of write");
    ret = I2C_WriteMem(A9G_I2C_Class.id, A9G_I2C_Class.address, firstMemAddr, A9G_I2C_Class.addrBusWidth, sendBuffer, numberOfBytes, A9G_I2C_Class.timeout);
    if (closeI2C()) // Error in open if != I2C_ERROR_NONE (= 0)
    {
        Trace(I2C_ET, "Could NOT close I2C Nr. %d on A9G @ read.", A9G_I2C_Class.id);
    }
    Trace(I2C_ET, "Returning write");
    return ret;
}

I2C_Error_t readI2C(uint32_t firstMemAddr, uint8_t * recBuffer, uint16_t numberOfBytes)
{
    Trace(I2C_ET, "Entering read");
    I2C_Error_t ret = I2C_ERROR_NONE;
    if (openI2C()) // Error in open if != I2C_ERROR_NONE (= 0)
    {
        Trace(I2C_ET, "Could NOT open I2C Nr. %d on A9G @ read.\nError was: %d", A9G_I2C_Class.id, ret);
    }
    Trace(I2C_ET, "Got to middle of read");
    ret = I2C_ReadMem(A9G_I2C_Class.id, A9G_I2C_Class.address, firstMemAddr, A9G_I2C_Class.addrBusWidth, recBuffer, numberOfBytes, A9G_I2C_Class.timeout);
    Trace(I2C_ET, "Got to after read MEM");
    if (closeI2C()) // Error in open if != I2C_ERROR_NONE (= 0)
    {
        Trace(I2C_ET, "Could NOT close I2C Nr. %d on A9G @ read.", A9G_I2C_Class.id);
    }
    Trace(I2C_ET, "Returning");
    return ret;
}

I2C_Error_t openI2C(void)
{
    Trace(I2C_ET, "Entering open");
    switch(I2C_Init(A9G_I2C_Class.id, A9G_I2C_Class.config))
    {
        case true: Trace(I2C_ET, "Leaving Open"); return I2C_ERROR_NONE;
        default:   return I2C_ERROR_MAX;
    }
    
};
static I2C_Error_t closeI2C(void)
{
    Trace(I2C_ET, "Entering close");
    switch(I2C_Close(A9G_I2C_Class.id))
    {
        case true: Trace(I2C_ET, "Leaving Close"); return I2C_ERROR_NONE;
        default:   return I2C_ERROR_MAX;
    }
    
};

Thanks in advance :)
}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant