10 years, 1 month ago.

Beginner - chosing pins with F401RE

Hello,

My boss gave me a Nucleo F401RE to play with and try to get me interested, so far so good!

I have successfully hooked up an LCD display, and also watched the square wave output of my multimeter using the analog in pins. However I'm now struggling with a DS18B20 temperature sensor and the HC-SR04 range finder.

I don't seem to get anywhere with either, my code is all taken from user contributions on this website. I generally replace the mbed library (which I presume is different for my F401RE?) and change the pins and most things compile. I have had to rename anything CRC to CRCval as that appears to be reserved with my mbed library.

Anyway with the DS18B20 I'm using this example

https://mbed.org/users/richardlane/code/DS18B20_1wire/

but the output I get is

DS18B20 Configuration Family code: 0xFF Serial Number: FF:FF:FF:FF:FF:FF CRC: 0xFF

This looks like I've chosen the wrong pin. I get a similar problem with my rangefinder, my code hangs (or never returns) when querying the distance.

I have tried all sorts of pin outs for the temp sensor, and nothing returns. I have just tried using the pins my LCD was hooked up to (as I know they're good) and similar story.

I suppose my questions are this:

1) Is there something I'm missing when choosing pins, e.g. for my temp sensor is PC_4 ok? (https://mbed.org/platforms/ST-Nucleo-F401RE/)

2) Is there a trick to debugging this? Interogating pins, break points etc?

Thank you very much for your time, I've all sorts of ambitions with this and I'm falling at about the second hurdle :)

NB: Datasheet for the temp sensor http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

2 Answers

10 years, 1 month ago.

Depending on the code you use, the HC-SR04 might require an InterruptIn pin, those can only be used on pins markes as IntIn on the handbook page (or something like that). That should be fixed (all pins can be interrupt inputs), no idea when though. If that is the case it should tell you on your serial terminal that it cannot used that pin as interruptin, but i don't know if the Nucleos do that properly (quite frankly, for the same price you get KLxxZ, which has way better device code atm).

If you import a helloworld program you don't need to replace the mbed lib btw, it is the same for all devices (and includes proper code depending on which device you select). You generally do need to update it, since most will be from before Nucleo support. Click on the mbed lib, click update at the right side.

Debugging wise I have always simply used printf statements, but they also feature real debuggers, for that you need to export the code to an offline toolchain, and then run the debugger like usual (no idea personally what usual is, but there are some tutorials here, and otherwise on the interwebs, since it is same as debugging otherwise is for those devices). But you can get quite far with just using printf to see where it hangs for example, why, etc.

Finally, the DS18B20. Wish I knew about that one when I required one, looks better than some others. Since it only seems to read '1's I would guess the pull-up works fine, but it is never pulled down. You do have a proper resistor? Something like 1k at least, not that it is a 40 ohms resistor. That library cannot handle parasitic power (although it shouldn't matter when reading Serial Number), so the power pins should be connected to VDD. Your ground is properly connected to a ground pin? And of course data pin goes to your PC_4 pin actually?

10 years, 1 month ago.

Thanks very much for your help.

Ok I'll stick with debugging on my lcd, every time I update my code I lose my com port to mbed terminal connection, and it's a pain resetting it each time.

Ok I've had another go with the DS18B20. I've got two more on the way in case this one is a dud or somehow I've cooked it.

I've got 5v across my Vcc and GND (both straight to the mbed), and when I disconnect the DQ my program stops working. I've got a 1k resistor in line as well now, I had missed that before. I've also tried 4700 and 5600 ohm as per the datasheet. I don't seem to be reading it properly, everything returns 0xFF, even the temperature it seems.

I'll have another go with the HC-SR04 and see if I get any further with that, thanks :)

I have the range finder working, using the Int In pins, thank you :)

The only thing is the output isn't very stable, it works a bit but keeps dropping out. Hmmm

posted by Russell Taylor 03 Mar 2014

For terminal connection debugging, assuming you use Teraterm: Alt+i (disable current connection), alt+n (new one), <enter>, alt+b (reset mbed). Then it isn't too bad :).

If your range finder isn't too stable that might be either a bad connection, or just a cheap rangefinder ;). For DS18B20, I personally used this code and it worked for me: https://mbed.org/components/DS1820/. You didn't mix up which side is GND and which side is VDD? And the resistor should be from the data pin to VDD.

posted by Erik - 03 Mar 2014

Ahh good tip, I'll try and macro that somehow :)

Could be the quality of it, I've bought another two, I'll see if they are any better and maybe cobble a few together and take an average :)

I'll try that code tonight thank you. I have taken the data pin (DQ) to a pinout on the mbed. I'll have another read of the datasheet now thank you and see what I can figure out.

posted by Russell Taylor 03 Mar 2014

Erik, thank you. It seems I am missing the 'pullup' element of my signal. I've now learnt about pullups and pulldowns, and can't wait to get home and try it :) For anyone else reading this consult the datasheet, it keeps mentioning Vpu.

Then read

http://electronics.stackexchange.com/questions/7423/what-is-a-pull-up-and-pull-down

and

http://www.roguescience.org/wordpress/building-a-midi-out-controller/part-3-add-a-switch/exercise-6/

Thank you!

posted by Russell Taylor 03 Mar 2014