We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello. I am a beginner and i am trying to use one of the ADCs on my stm32f103ze.I have been using the examples from keil, they are well written and understandable. The problem is, they dont have an example showing use of an ADC. I have read the example from the stm firmware library and they use a different way of of setting up things than the examples from keil so i understood nothing. Can anyone link me to an (understandable,keil-example-like) example describing setting up the adc, and receiving values from it?
There are at least as many different ways to write any program as there are different programmers.
"so i understood nothing"
At the end of the day, it's still the same chip with the same functions and the same registers - so, if you've really understood one, you should be able to understand the other!
What is it, particularly, that you find hard about ST's examples?
As this is more about the STM32 than about Keil, you'd probably do well to also post on the ST forum:
my.st.com/.../AllItems.aspx
But, if you do, be sure to give links between both threads - so that eveyone in both forums can see the full picture.
"Can anyone link me to an (understandable,keil-example-like) example describing setting up the adc, and receiving values from it?"
it is probably more helpful to read the datasheet and see how to configure the various registers to read the adc.
in a non-interrupt mode, I would use two functions, adc_init() to set up the basic parameters for the adc, and then adc_read() to read back a particular channel's adc results.
hope it helps.
the firmware library is good in that it shows you how to configure an adc but they are so generic that they become unnecessarily complicated for 99% of the adc applications out there.
so it is actually a lot easier / simpler to just read the datasheet.
"in a non-interrupt mode, I would use two functions, adc_init() to set up the basic parameters for the adc, and then adc_read() to read back a particular channel's adc results."
Potentially a adc_start() to start a conversion, so adc_read() can be called later and pick up the result without having to wait. But that depends on how much work the CPU has to do, and what conversion speed the ADC will have.
they use a different way of of setting up things than the examples from keil so i understood nothing.
what would be the most likely source for STM32 'examples' Keil or ST?
well, if you guess the answer, I suggst you get yourself to understanding the ST examples this is NOT a complaint about Keil but who do you think will be most concerned about well working 'examples'.
The Keil examples are about showing the compiler, the ST examples are about showing the chip.
Erik
"Potentially a adc_start() to start a conversion, so adc_read() can be called later and pick up the result without having to wait. But that depends on how much work the CPU has to do, and what conversion speed the ADC will have."
agreed.
if you are concerned about concurrency, using an interrupt to automate adc and adc_read() to simply return the value of the adc.
either way, at a minimum, one will need to set up the adc (adc_init()) and then perform a conversion (adc_read()).
"The Keil examples are about showing the compiler, the ST examples are about showing the chip." Well, exactly- i do understand basically the examples of st in the level of what each code line does. so maybe i didnt explain myself correctly.the problem i encounter is when i attempt to use this in Keil. first of all, in the st examples the library used is stm32f10x.h and in the keil examples for everything else stm32f10x_lib.h is the library of choice. second of all, when using stm32f10x_lib.h, the examples of st are not functional at all, because the wont compile. so yeah, basically i dont need instructions on the chip itself and all of its registers and stuff, i need instructions on getting my code compiled "keil-example" style.
please bear with me, i might be very stupid about that, but yet again i am a beginner and highly dependent on the Keil examples, so i must apologize in advance for any dumb comments.
"The Keil examples are about showing the compiler, the ST examples are about showing the chip."
the st examples utilizes the firmware - thus some unique ways to access the peripherals, and the keil ones are unlikely to have done that.
either way, they all use the same functions on the chip, just different ways of doing the same thing.
I did some quick search.
===========================================================>
http://www.keil.com/dd/docs/arm/st/stm32f10x/stm32f10x_lib.h stm32f10x_lib.h
#ifndef __STM32F10x_LIB_H #define __STM32F10x_LIB_H /* Includes ------------------------------------------------------------------*/ #include "stm32f10x_map.h" #ifdef _ADC #include "stm32f10x_adc.h" #endif /*_ADC */
" href= "http://code.google.com/p/plex-svn/source/browse/trunk/h103/stm32f10x.h?r=411"> code.google.com/.../stm32f10x.h stm32f10x.h
/** * @brief Analog to Digital Converter */ typedef struct { __IO uint32_t SR; __IO uint32_t CR1; __IO uint32_t CR2; __IO uint32_t SMPR1; __IO uint32_t SMPR2; __IO uint32_t JOFR1; __IO uint32_t JOFR2; __IO uint32_t JOFR3; __IO uint32_t JOFR4; __IO uint32_t HTR; __IO uint32_t LTR; __IO uint32_t SQR1; __IO uint32_t SQR2; __IO uint32_t SQR3; __IO uint32_t JSQR; __IO uint32_t JDR1; __IO uint32_t JDR2; __IO uint32_t JDR3; __IO uint32_t JDR4; __IO uint32_t DR; } ADC_TypeDef;
<===========================================================
I guess that, the problem is: the OP doesn't know how to use header files to access the registers.
Why, exactly, will they not compile?
Nobody can help you with that if you don't give any details of the specific problem(s) that you're having!
"the OP doesn't know how to use header files to access the registers."
no one can help with that.