AnsweredAssumed Answered

Problem using I2C under MQX

Question asked by Mark Potts on Aug 2, 2011
Latest reply on Aug 9, 2011 by Mark Potts

Hi,

 

I am trying to use I2C under MQX on an MCF52259 design. We have tested I2C under Processor Expert so know the hardware works. The I2C documentation and example are not very clear but I am doing the following:

 

To install/initialize I2C:

 

    MCF52XX_I2C_INIT_STRUCT i2c0_init = {
        0,
        BSP_I2C0_MODE,
        BSP_I2C0_ADDRESS,
        BSP_I2C0_BAUD_RATE,
        BSP_I2C0_INT_LEVEL,
        BSP_I2C0_INT_SUBLEVEL,
        BSP_I2C0_TX_BUFFER_SIZE,
        BSP_I2C0_RX_BUFFER_SIZE
    };


    rc = _mcf52xx_i2c_polled_install("i2c0:", &i2c0_init);

This returns 0xA00 which I do not know whether is correct.

 

To read an 8-byte buffer from I2C:

 

    if (NULL != (fd = fopen ("i2c0:", NULL))) goto fail;
    param = I2C_ADDR;
    if (I2C_OK != ioctl(fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &param)) goto fail;
    param = sizeof(buff);
    if (I2C_OK != ioctl(fd, IO_IOCTL_I2C_SET_RX_REQUEST, &param)) goto fail;
    fread(&buff, 1, sizeof(buff), fd);
    if (I2C_OK != ioctl(fd, IO_IOCTL_FLUSH_OUTPUT, &buff)) goto fail;

     fclose(fd);

This executes without indicating failure but reads incorrect data. If I change the destination I2C address it still reads the same data, so something is wrong!

 

Mark

Outcomes