AnsweredAssumed Answered

I2C Master_Transmit and Receive Problem with going from polling to interrupt functions

Question asked by Rollinator on Jun 8, 2016
Latest reply on Jun 8, 2016 by ForumSTM32.ForumSTM3

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:

 

http://www.st.com/content/ccc/resource/technical/document/user_manual/2f/71/ba/b8/75/54/47/cf/DM00105879.pdf/files/DM00105879.pdf/jcr:content/translations/en.DM00105879.pdf

 

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

Outcomes