TL;DR

Jump to second part, the first part illustrate how did I found the problem, which is not interesting at all.

How did I find this problem

Recently, my roommate is practicing for interview with Leetcode, he keeps coming to ask for my help with some problems. The problems in Leetcode are really easy (especially when compared with problems in OJs oriented for ACM), but if you keep sensitive, it could still help you find some corner in the language that you would never notice otherwise.

Here is my log about investigating difference of range() between python2 and python3 - and their different against xrange().

Reason to use DS18B20

You know, a common solution to this is to use some thermistor and try to use some ADC(Analog-Digital-Converter) to capture the voltage on that. The temperature captured by thermistor won’t be too accurate, just around 1 degree or so. If you need a temperature with accuracy of 0.0625 degree, the DS18B20 would be a good choice.

But DS18B20 has an really time sensitive 1-wire protocol. A normal solution to this problem is to use GPIO and NOP() instruction to simulate this, but I tend to use something different.

What’s the problem with I2C of STM32?

The STM32 chips are all really good designed, coming with a really nice price - for a normal, wide-used STM32F1, the price is around 1-2 bucks in some small scale order. If take the fact that ST is really nice to small order and always willing to give a good price, everything about STM32 seems so perfect.

However, such bargain has its own weakness - its own I2C peripheral has some really serious hardware bug, that it is really sensitive to the time sequence, even interrupted by a small function, the peripheral would fail. An application engineering of STMicroelectronics has mention their concern in an offline meeting. She said the I2C peripheral is designed like this on purposely, just to avoid some strict patent of NXP. Check here