2015-02-13 03:04 AM
I wanted to have a simple slave device that could respond to a read OR write from a i2c master.
the current HAL drivers don't support this so i added a few things to the HAL driver. the attached files are modified versions of existing HAL drivers. in stm32f0xx_hal_conf.h i removed ref to exisiting i2c driver //&sharpdefine HAL_I2C_MODULE_ENABLED and added all this &sharpdefine GS_HAL_I2C_MODULE_ENABLED &sharpifdef GS_HAL_I2C_MODULE_ENABLED &sharpinclude ''gs_stm32f0xx_hal_i2c.h'' &sharpendif /* GS_HAL_I2C_MODULE_ENABLED */ in order to start i2c slave for example just run once eg. i2c_ret_state = GS_HAL_I2C_Slave_Transmit_Receive_IT(&hi2c1, (uint8_t *)&i2c_tx_buff, sizeof(i2c_tx_buff), (uint8_t *)&i2c_rx_buff, sizeof(i2c_rx_buff)) ; and use IT callbacks to know whats been happening. don't forget to change i2c handler to point to new routine eg. void I2C1_IRQHandler(void) { HAL_NVIC_ClearPendingIRQ(I2C1_IRQn); if ( hi2c1.Instance->ISR & (I2C_FLAG_BERR | I2C_FLAG_ARLO | I2C_FLAG_OVR)) { HAL_I2C_ER_IRQHandler(&hi2c1); } else { GS_HAL_I2C_EV_IRQHandler(&hi2c1); } } i'm sure all this can be tidyed up more but this is first go at it. hope this helps and maybe something like this can be added to existing HAL drivers in future. #i2c-slave-hal-autonomous2015-04-11 07:00 AM
Hello,
Thank you for sharing :) That's exactly what I need to do with the stm32l0.Do you have a bigger other piece of your code with a 'real' and full use case ? Cheers,Alexis