This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Why i2c gio_read() not working?

I got a problem with the following code:  After executing a routine sending a byte to a register of a slave device, then executing the following code, the result is rBuffer[1]=the old data sent onto the bus, not the data from the register with address 0x6. Please help.

    Int32                status = IOM_COMPLETED;
    I2c_DataParam        rxdataBuffer;

    rBuffer[0] = 0x6;
    rxdataBuffer.slaveAddr = I2C_SLAVE_ADDR;
    rxdataBuffer.buffer    = &rBuffer[0];
    rxdataBuffer.bufLen    =sizeof(rBuffer); 
    rxdataBuffer.flags     = I2c_READ | I2c_MASTER | I2c_START | I2c_STOP;

    status = GIO_read(i2c_inoutHandle, &rxdataBuffer,
                        &rxdataBuffer.bufLen); 

 

  • I'm not sure what are your test conditions. Did you write the address and read the data as separate I2C transactions? The code fragment almost suggests you are trying to a write and read in one I2C GIO request. You'll need a repeated start for that. How does your slave device expect the register address to be sent and data to be read?

     

  • I am trying to read from the slave address in the master C6748 I2C. Could you please modify the code to make it work?

  • Not enough detail to go on. You should take a look at the I2C examples in the PSP package. They are at

    pspdrivers_01_30_01\packages\ti\pspiom\examples\evm6748\i2c
    pspdrivers_01_30_01\packages\ti\pspiom\examples\evmOMAPL138\i2c

    The examples appear to be write only. You should use them to check that data is actually coming out the I2C port. Check with with a scope.

     

  • Those TI examples do not cover GIO_read into the DSP I2C, even though it works perfectly for GIO_write out of the DSP to the I2C LED blinking on the EVM board. I have spent a lot of time on those examples and they certainly work, but they do not cover GIO_read for the I2C. If you did not work on those examples, please ask your colleagues and hope they could help me. Thanks anyway.

  • I am guessing your slave requires a repeated start transaction. I've used the GIO for SPI. Haven't tried it for I2C. The I2C code for reading a 8 bit register should look something like:

    Int32 readreg(Uint8 devaddr, Uint8 regaddr, Uint8 *data)
    {
      Int32         status = IOM_COMPLETED;
      I2c_DataParam param;

      param.slaveAddr = devaddr;
      param.buffer    = &regaddr;
      param.bufLen    = 1;
      param.flags     = I2c_WRITE | I2c_MASTER | I2c_START;

      status = GIO_write(i2c_inoutHandle, &param, sizeof(param));
      if(status!=IOM_COMPLETED) return(status);

      param.slaveAddr = devaddr;
      param.buffer    = data;
      param.bufLen    = 1;
      param.flags     = I2c_READ | I2c_MASTER | I2c_START | I2c_STOP;

      status = GIO_read(i2c_inoutHandle, &param, sizeof(param));
      return(status);
    }

    Good luck.