cancel
Showing results for 
Search instead for 
Did you mean: 

ADC I2C Problem

dree86
Associate II
Posted on January 18, 2017 at 03:16

Hello

I have project MP3 using STM32F030C8.

MP3 decoder using I2C interface and user key using ADC. So, beginning of my prototype use STM32L0 series, it already done and no problem at all. After that I change to STM32F030C8 then problem happen.

User key didn't work because ADC value are wrong (random). There is no different value when press each key. But if I disable MP3 (I2C) interface, ADC is works.

Here my block system

0690X00000605vDQAQ.png

I attach my related code.

Thank you any clue I appreciate.

Edit : I checked ADC and DMA register by KEIL debugger, here the screenshoot

This is condition when I comment MP3 (i2c)  code, Register value seem OK.

register DR value is FFF when no key press. And when I press each key, it give desired value.

0690X00000603YtQAI.jpg

And here normal condtion (MP3 I2C active).

Both ADC and DMA register value are absurd. Sometime it change to random value.

But MP3 function is works. Its like there is collision between I2C and ADC. ADC peripheral address suddenly change every time read and write data via I2C.

.This is very strange please help.

0690X00000603YyQAI.jpg

#adc #i2c
5 REPLIES 5
Posted on January 18, 2017 at 23:02

I don't Cube and won't attempt to understand the code you posted, but my first rough guess is that this you have some runaway buffer index or pointer.

JW

dree86
Associate II
Posted on January 19, 2017 at 03:03

Hello Jan

Thanks for reply. Should I move using std periperal library ?

Because this error very strange. I change I2C buffer size then suddenly when I place breakpoint at :

HAL_I2C_Master_Transmit(&I2CHandle,(uint16_t)LSI_ADDR_WR,(uint8_t *)temp, len_1 + len_2,1000)

also I place breakpoint inside HAL_I2C_Master_Transmit function then click run it didn't stop at second breakpoint. It go to HardFault_Handler().

HAL_driver sometime give me odd error.

dree86
Associate II
Posted on January 19, 2017 at 09:17

I found solution but this is ugly solution. Since ADC DR register located at 0x40012440, then I trace memory using debugger it seem this address store ADC value correctly.

So I make pointer to that address then read pointer data everytime key bouncing occur.

uint32_t  value = *(uint32_t*) 0x40012440;

But still I hope there is a good solution about my problem. Is this a reason why mostly people avoid HAL_Driver?

Posted on January 19, 2017 at 09:31

Should I move using std periperal library ?

I did not say that.

If you are seing variables to be overwritten unexpectedly, start from that. Can you use data breakpoints (i.e. breakpoints which stop when a memory position or range is read or written)? If yes, use them on those Cube 'device instance' structures which got overwritten and find out why are they overwritten.

JW

Because this error very strange. I change I2C buffer size then suddenly when I place breakpoint at :

HAL_I2C_Master_Transmit(&I2CHandle,(uint16_t)LSI_ADDR_WR,(uint8_t *)temp, len_1 + len_2,1000)

then click run it didn't go to function HAL_I2C_Master_Transmit.

HAL_driver sometime give me odd error.

Reply to this message by replying to this email, or go to the message on STMicroelectronics Community Start a new discussion in STM32 MCUs Forum by email or at STMicroelectronics Community Following STM32 MCUs Forum in these streams: Following This email was sent by STMicroelectronics Community because you are a registered user.

You may unsubscribe instantly from STMicroelectronics Community, or adjust email frequency in your email preferences

--- message truncated ---

Posted on January 23, 2017 at 03:54

No I cant find where that memory or position is overwritten. Because ADC structure is written on  initialisation (which is beggining of run program) except interrupt flag