Skip to content

AnalogRead() will not return with incorrect pin #143

@paulvha

Description

@paulvha

Subject of the issue

When performing a Analogread() with a pin number that does not have analog support
the Analogread() will not return and loop forever.

Steps to reproduce

loop()
{
Serial.print("test :");
uint16_t tempadc = analogRead(37);
Serial.print("analog pin :");
Serial.println(tempadc);
}
The text 'test :' will be displayed, but 'analog pin :' will not be displayed.

Root cause:

In ap3_analog.h the wrong number of entries is indicated : AP3_ANALOG_PADS where it should be
AP3_ANALOG_CHANNELS. AP3_ANALOG_PADS = 10 where AP3_ANALOG_CHANNELS = 15,

In ap3_analog_structures.c the structures are defined as :

const ap3_analog_channel_map_elem_t ap3_analog_channel_map[AP3_ANALOG_CHANNELS] = {
and
ap3_analog_configure_map_elem_t ap3_analog_configure_map[AP3_ANALOG_CHANNELS] = {

In ap3_analog.h the structures are referenced as :

extern const ap3_analog_channel_map_elem_t ap3_analog_channel_map[AP3_ANALOG_PADS];
and
extern ap3_analog_configure_map_elem_t ap3_analog_configure_map[AP3_ANALOG_PADS];

Solution :

correctly reference the structures in ap3_analog.h as a size AP3_ANALOG_CHANNELS :

extern const ap3_analog_channel_map_elem_t ap3_analog_channel_map[AP3_ANALOG_CHANNELS];
extern ap3_analog_configure_map_elem_t ap3_analog_configure_map[AP3_ANALOG_CHANNELS];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions