0
\$\begingroup\$

I'm extremely new to the STM32F103 (just received it in the post today) and would like to know how (the best way) to set up one of its pins as a clock source for an external circuit.

Ideally, I would like it to be able to produce a 2, 4 or 8 MHz (software selectable) clock signal suitable to run an external microprocessor.

Can anyone point me in the right direction with some example code?

Thanks!

EDIT: Oops. Missed out an important part of the question - I need TWO clock sources - one as described above and the other fixed at 2 MHz (but synched with the first clock signal.) Is this possible using one or two of the Timers?

\$\endgroup\$

closed as too broad by Eugene Sh., RoyC, Sparky256, Chris Stratton, Dmitry Grigoryev Jan 22 '18 at 10:27

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    \$\begingroup\$ Have you read the datasheet? \$\endgroup\$ – vofa Jan 16 '18 at 17:31
  • \$\begingroup\$ Ditto. If you intend to to enter the embedded business you really should learn how to extract this information from the technical documentation. \$\endgroup\$ – Eugene Sh. Jan 16 '18 at 17:38
  • \$\begingroup\$ @Nockieboy, I think the first step is getting the the thing to turn on and blink an LED. How much experience do you have with any other microcontroller? Typically to one of these things turned on you would write software to turn on the internal oscillator, set the inputs/outputs of the MCU ports (in your case to blink an LED, set one of the ports as an output), and then blink the output. That's kind of the grand picture of that process. \$\endgroup\$ – Leroy105 Jan 16 '18 at 17:45
  • \$\begingroup\$ I would look for "STM32F103" tutorials, to get a sense of how to put this all together. Don't let the haters get you down. It can be hard to know where to start with a datasheet. Datasheets tell a lot of "what" -- but assume a lot of knowledge that you know how everything works. Once you get how an embedded MCU works and the general strategy to write the software. It's nearly the same across all of the devices. Here is one that looks recently up-to-date: instructables.com/id/STM32F103-Blink-LED \$\endgroup\$ – Leroy105 Jan 16 '18 at 17:47
  • 1
    \$\begingroup\$ Thanks for the explanation, Leroy105. Yes, I have experience with Arduinos and I'm looking to replace one as a clock source in a single-board computer with the STM32. I actually missed the most important part of my question out - I need two clock sources, one I can vary between 2, 4 or 8 MHz and the other fixed at 2 MHz (but synched with the variable one if possible.) I think Jeroen3's answer is actually pointing me in the right direction though. \$\endgroup\$ – nockieboy Jan 16 '18 at 22:44
0
\$\begingroup\$

Nice way: Master Clock Out (MCO PA8).
Other way: APB2 Timer outputs (capable of 18 MHz). But there might be other factors that reduce this speed or limit other features in the chip if you want this.

All can be found in the Datasheet and the Reference manual.

\$\endgroup\$
  • \$\begingroup\$ Thanks Jeroen3 - that's what I wanted to know in a nutshell basically. :) \$\endgroup\$ – nockieboy Jan 16 '18 at 22:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.