2016-04-26 08:00 AM
I've got an STM32F0 based I2C slave device which I'd like to send simple commands to, as well as updates containing additional bytes of data.
HAL_I2C_Slave_Receive_IT() seems to require you to directly set the number of bytes you are waiting for however, so all received data must be the same length. Is there any way around this using the HAL system? #!i2c #i2c-slave #no-hablo-hal #!stm322017-08-30 11:38 AM
Not sure if you still need an answer but why not do 2 transfers? First transfer is always say 2 bytes and that will be the size. Second transfer will be right after with the real data and now the size from transfer 1.
2017-08-30 07:20 PM
Since the two busses are intended to be separate by means of the two distinct interfaces, you either make them transparent (by having the local I2C controller duplicate the function on the slave bus, or by taking a bus transceiver/switch and making the local bus electrically equivalent to the incoming bus.
The bus switch has the ability to buffer, so that the loading of the slave devices will not load the system bus. You'd then have to have a command to the local processor to switch from remote to local control of that bus.
If you're willing to encapsulate a command to the slave devices on the board, then you can do this with one interface and a well defined packet structure.
With that kind of structure, you have one packet format for local devices, the content is the unique command to that device, data is encapsulated and sent off board, and your board doesn't care who addressed what, because it's handling all the communications on and off board.
That might be an acceptable solution. You'll need a handler for each device type, but you'd need that anyway.
2018-05-09 02:20 AM
Use this:
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c){
// not enough bytes received causes an error, process the data anyway HAL_I2C_SlaveRxCpltCallback( hi2c );}I don't know how to find out how much data was actually received though. I use the first byte as a length indicator, so I don't need to know. Also, I guess this Error Callback could be triggered by other errors, so you probably should find out if the 'Error' is a stop condition.