cancel
Showing results for 
Search instead for 
Did you mean: 

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

oliver239955_stm1_st
Associate II
Posted on June 08, 2016 at 09:05

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

4 REPLIES 4
slimen
Senior
Posted on June 08, 2016 at 13:22

Hi,

I suggest you to use the last version of

http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html

 v4.15 and refer to this examples under the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

 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.

Regards

oliver239955_stm1_st
Associate II
Posted on June 08, 2016 at 13:46

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?
oliver239955_stm1_st
Associate II
Posted on June 08, 2016 at 13:52

Ah I just figured out there is a bunch of Firmware Packages in STM32Cube ready to be downloaded!!! I take a look....

slimen
Senior
Posted on June 08, 2016 at 13:59

Hi,

You can downolad the STM32F4 Firmware package from CubeMx or from this

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

  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