2016-06-08 12:05 AM
Hello,Here I've got a board hosting a sensor communicatingvia I2C.
The Board is based on a STM32F410RBT***I use the HALdrivers!
below you can find the manual:
onpage 440 ffyou can find the basic Master Transmit andReceive Functions!
For my comprehension (and yours as well ;) :(
The I2C initialization has been done using the STM32CubeMXtool,
that worked quite well and is a very handy tool.
Having a proper initialization I can move straight forwardto access to
the I2C Busand devices attached to it!
In order to get a value from my sensor I should obey thefollowing rules ( I guess):
transmit a value to sensor (sensor's address + register ofsensor to be writtenread from)
then
receive value from sensor (or respectively transmit value dependingon what you want to do)
I did this using the ''polling'' (busy waiting)functions -->
first
call
HAL_I2C_Master_Transmit
then
call
HAL_I2C_Master_Receive
data has been stored to the address the datapointer waspointing to!!!
that worked quite fine for me but now I d like to avoidpolling
so switching to the interrupt functions!!!
then I have to
call
HAL_I2C_Master_Transmit_IT
then
HAL_I2C_Master_Receive_IT''
HAL_I2C_Master_Transmit_IT''
triggers the ISR
HAL_I2C_MasterTxCpltCallback()
when data has been fully sent! Am I right?''
HAL_I2C_Master_Receive_IT''
triggers the ISR
HAL_I2C_MasterRxCpltCallback()
when fully received data! AM I rigt?
Unfortunately Here I can only get ''random'' datafrom the sensor
when just calling the Receive-function!
if using both, no data can be received at all!!
I assume I have to use the I2C ISRs for a nice blockingmechanism.....
like
do not start receive before having transmit and vice versa;
do not start transmit before data of recent call is sent;
do not start receive before data of recent call is received;
Am I right?
Or are those Interrupt I2C functions completely differently
meant to be applied?
kind regards
Oli
2016-06-08 04:22 AM
Hi,
I suggest you to use the last version of v4.15 and refer to this examples under the cube firmware package version 1.12 : STM32Cube_FW_F4_V1.12.0\Projects\STM32F410xx-Nucleo\Examples\I2C\I2C_TwoBoards_ComPolling which describes how to perform I2C data buffer transmission/reception in Polling mode.Regards2016-06-08 04:46 AM
Hi,
thanks for your reply. Anyway I don't want to know how this stuff works in polling mode. That's what I already managed to get running.I 'd rather like to do the same stuff in interrupt mode.Btw my STMCube did not come up with any example!!!where can I find them?2016-06-08 04:52 AM
Ah I just figured out there is a bunch of Firmware Packages in STM32Cube ready to be downloaded!!! I take a look....
2016-06-08 04:59 AM
Hi,
You can downolad the STM32F4 Firmware package from CubeMx or from this and you can find the running examples for I2C using an interrupt in:STM32Cube_FW_F4_V1.12.0\Projects\STM32F410xx-Nucleo\Examples\I2C
Regards