cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 I2C interrupt driven method 2

eexlb2
Associate
Posted on January 16, 2012 at 22:29

I am having issues with interrupt driven I2C using method 2 from the reference manual. I am trying to read from the magnetometer on an lsm303dlh. The least significant bit of the most significant byte seems to be taking a fixed value.

  I have taken a look with an oscilloscope and the data on the bus is correct, for example when the data on the X axis appears as 0xFF04 from my code, it is 0xFE04 on the bus. I don't think the problem concerns the entire most significant byte, as i have seen the other bits flipping.

The accelerometer does not appear to have the same issue, but the data is differently aligned, so this issue may be occuring, but buried in the noise. I have tried using a Bosch barometer and the data seems fine, but the transactions are only 3 bytes in length.

  I have attached my code - it is built around an array of 'job structures'. When a job is requested using the request function the i2c will pass the data in the array associated with the job too or from the i2c bus. I am using EXTI interrupts off the data ready lines from the sensor, these have the same pre-emption priority as the i2c interrupts, but the i2c interrupts have the highest priority in the group (maybe im using the wrong wording there - the i2c interrupt service routines cannot themselves be interrupted, but they may have to wait a short while for the EXTI irq to complete before running - i can see this lag on the scope, but its 1us or so at worst).

 Can anyone offer advice on where I may have gone wrong? I have read the errata but I cant find anything directly relevant to my issue.

Regards,

Laurence

#i2c-interrupts-stm32 #i2c #interrupts
3 REPLIES 3
eexlb2
Associate
Posted on January 23, 2012 at 14:54

 I've managed to fix the code, there were several issues. Unfortunately it seems the only way to ensure reliability was to have while loops inside the ISR waiting for stop and start conditions to clear, which isnt ideal. the hardware fails and locks up occasionally with multiple writes to the control register before a start or stop condition has cleared in the register.

 Working code is up on github now

https://github.com/Laurenceb/Dactyl/blob/master/i2c_int.c
emalund
Associate III
Posted on January 23, 2012 at 15:13

read the errata, that will be helpful

Erik

maxikrie
Associate
Posted on July 08, 2013 at 01:16

Hi Erik,

Could you be a little bit more specific? I also have issues with the I2C and more background on this topic would be great!

Thanks,

Max