English 中文(简体)
STM32 I2C1 Start bit not set on SR1 register
原标题:

I am trying to program the stm32 to talk to my i2c EEprom, but it seems like everytime I say:

I2C_GenerateSTART(I2C1, ENABLE);
while( !(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) );  the code hangs here

I went through with the debugger and I found that the SR1 bit 0 flag (which is the start bit generated flag) is not set which is why the code hangs. I can see in the oscilloscope that the start bit was generated and this works sometimes. it usually breaks when I tried to do several writes in a row. I checked the HW is everything looks fine I checked the frequency that I am running on the i2c bus it is 100Khz well within the 24lc1025 eeprom.

any ideas,

thanks

最佳回答

Since you say that this usually breaks when you re doing several writes in a row, you might want to ensure that you re not violating this note in the STM32 datasheet for the STOP bit in the I2C_CR1 control register:

Note: When the STOP, START or PEC bit is set, the software must not perform any write access to I2C_CR1 before this bit is cleared by hardware. Otherwise there is a risk of setting a second STOP, START or PEC request.

Once you set the STOP bit you need to make sure that the hardware has cleared it before you write the next START bit.

问题回答

Check the Errata for your device (get it from the ST website). The STM32 has a lot of bugs in the I2C implementation. The errata gives software workarounds for them.

Also, when using the driver source files typically provided with STM32 platforms, don t forget to read through the headers! They can be very helpful, especially for novices (like me) who aren t sure where to start.

In this case, you would be looking at stm32f4xx_i2c.c





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签