Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
720f55cc
Commit
720f55cc
authored
Jun 17, 2014
by
Damien George
Browse files
Merge pull request #698 from dhylands/adc-fix
Fix problem with ADC reads and multiple channels
parents
bcb3ab45
535b8813
Changes
1
Hide whitespace changes
Inline
Side-by-side
stmhal/adc.c
View file @
720f55cc
...
...
@@ -80,7 +80,7 @@ typedef struct _pyb_obj_adc_t {
ADC_HandleTypeDef
handle
;
}
pyb_obj_adc_t
;
void
adc_init_single
(
pyb_obj_adc_t
*
adc_obj
)
{
STATIC
void
adc_init_single
(
pyb_obj_adc_t
*
adc_obj
)
{
if
(
!
IS_ADC_CHANNEL
(
adc_obj
->
channel
))
{
return
;
}
...
...
@@ -114,7 +114,9 @@ void adc_init_single(pyb_obj_adc_t *adc_obj) {
adcHandle
->
Init
.
EOCSelection
=
DISABLE
;
HAL_ADC_Init
(
adcHandle
);
}
STATIC
void
adc_config_channel
(
pyb_obj_adc_t
*
adc_obj
)
{
ADC_ChannelConfTypeDef
sConfig
;
sConfig
.
Channel
=
adc_obj
->
channel
;
...
...
@@ -122,10 +124,10 @@ void adc_init_single(pyb_obj_adc_t *adc_obj) {
sConfig
.
SamplingTime
=
ADC_SAMPLETIME_15CYCLES
;
sConfig
.
Offset
=
0
;
HAL_ADC_ConfigChannel
(
adc
H
andle
,
&
sConfig
);
HAL_ADC_ConfigChannel
(
&
adc
_obj
->
h
andle
,
&
sConfig
);
}
uint32_t
adc_read_channel
(
ADC_HandleTypeDef
*
adcHandle
)
{
STATIC
uint32_t
adc_read_channel
(
ADC_HandleTypeDef
*
adcHandle
)
{
uint32_t
rawValue
=
0
;
HAL_ADC_Start
(
adcHandle
);
...
...
@@ -193,6 +195,7 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
STATIC
mp_obj_t
adc_read
(
mp_obj_t
self_in
)
{
pyb_obj_adc_t
*
self
=
self_in
;
adc_config_channel
(
self
);
uint32_t
data
=
adc_read_channel
(
&
self
->
handle
);
return
mp_obj_new_int
(
data
);
}
...
...
@@ -226,6 +229,7 @@ STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_
// This uses the timer in polling mode to do the sampling
// We could use DMA, but then we can't convert the values correctly for the buffer
adc_config_channel
(
self
);
for
(
uint
index
=
0
;
index
<
bufinfo
.
len
;
index
++
)
{
// Wait for the timer to trigger
while
(
__HAL_TIM_GET_FLAG
(
&
TIM6_Handle
,
TIM_FLAG_UPDATE
)
==
RESET
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment