dotnet / dotnet/iot

Mcp23017 initialization resets pin values

Open
#1,663 4 comments 0 reactions 0 assignees View on GitHub
bug Priority:2 up-for-grabs
Dominant language
C#
Stars
2.4k
Forks
630
Avg merge
7d 11h
Merged PRs (30d)
3

Description

**Describe the bug**

Every time a new instance of Mcp23017() is being created the pins are being reset to low. This is an issue when the written software reboots, eg when updating the software version.

**Steps to reproduce**

```csharp
var pinNumber = 0;

var i2cConnectionSettings = new I2cConnectionSettings(1, 0x20);

var i2cDevice = I2cDevice.Create(i2cConnectionSettings);

var device = new Mcp23017(i2cDevice);

var controller = new GpioController(PinNumberingScheme.Logical, Mcp23017Device);

controller.Write(pinNumber, PinValue.High);

var device2 = new Mcp23017(i2cDevice);

var pinValue = controller.Read(pinNumber);
```

**Expected behavior**

Pins need to keep their value after re-initializing the Mcp23017() adapter.

**Actual behavior**

Pins are being reset every time a new instance of Mcp23017() is being declared. Looks like it is embedded in the init code here:
https://github.com/dotnet/iot/blob/main/src/devices/Mcp23xxx/Mcp23xxx.cs - starting at line 84.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/devices/Mcp23xxx/Mcp23xxx.cs around line 84, where Mcp23017 initialization is performed. Reproduce the sequence of creating an adapter, writing a pin high, and creating a second adapter; done means the pin retains its value after re-initialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.