cancel
Showing results for 
Search instead for 
Did you mean: 

I2C HAL For Protocols With Length Specified in Data

jon2
Associate II
Posted on January 15, 2016 at 15:25

I need to read from a device with a variable length response, where the length of the following data is specified in the first byte received.  I don't see a way to accomplish this using the HAL, as it appears you need to know the rx length at the time of the call.  I think this is a fairly common scenario.  Does anyone have any ideas how to work around this short of writing my own I2C implementation?

4 REPLIES 4
craig239955_stm1_st
Associate II
Posted on April 26, 2016 at 16:51

Did you ever find a solution for this?

I've been looking, and the only way I think you might be able to do it is by assessing first byte and then polling for the remaining bytes afterwards in the I2C ISR...? 

If you ever figured it out please let me know, I'm having the same difficulty at the moment.

Rosiney Silva
Associate II
Posted on April 29, 2016 at 18:47

it could be that?

...

HAL_I2C_Master_Receive_IT(&handle, addr, data, 1);

...

void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)

{

  static uint8_t frame = 0;

  if (frame) {

    HAL_I2C_Master_Receive_IT(&handle, addr, data, 1);

    frame = 0;

  } else {

    HAL_I2C_Master_Receive_IT(&handle, addr, &data[1], *(hi2c->pBuffPtr));

    // *(hi2c->pBuffPtr) -> data[0]

    frame = 1;

    // use the data

  }

}

not tested!

sasha
Associate III
Posted on February 10, 2017 at 06:51

Hi, I'm having the same issue.  Has anyone had any success in doing this?

transistorboy32
Associate II
Posted on June 11, 2017 at 02:06

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6sY&d=%2Fa%2F0X0000000bx8%2F0CGWF8aB0bbJOt5JI4rl0Jg_a_s5XPOvU4BON4iEUqY&asPdf=false