Skip to content

DigitalWrite fails after analogWrite #92

Closed
@nseidle

Description

@nseidle

Suppose a user does an analogWrite to an output pin. Then they do a digitalWrite HIGH to the same pin. On Artemis as currently implemented, the pin will remain in PWM / analog output mode rather than going HIGH. However, the ATmega328 core will actually drive the pin high. This discrepancy leads to some user code not working correctly when users switch to Artemis.

I'm trying to figure out the best place to implement the fix. I believe we could do a .uFuncSel on a given pin inside digitalWrite:

image

But that would basically be a pinMode(xPin, OUTPUT); every time digitalWrite was called (not good).

I believe we can't easily read or decipher a pad's current funcsel. Correct me if I'm wrong. So I am slowly leaning towards a global array of 50 uint8_ts that keep track of how each pin/pad is setup (in, out, analogin, analogout, i2c, spi, pdm, uart, ?). This would replace and supersede the ap3_analog_configure_map (used to keep track of which pads are currently defined as analogInput).

I love how "this will be a simple fix" turns into a big deal...

Metadata

Metadata

Assignees

Labels

wontfixThis will not be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions