Skip to content

Commit

Permalink
i2csoft: fix baudrate handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sago35 authored and deadprogram committed Nov 4, 2021
1 parent bd42656 commit a89a261
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions i2csoft/i2csoft.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func New(sclPin, sdaPin machine.Pin) *I2C {
return &I2C{
scl: sclPin,
sda: sdaPin,
baudrate: 100 * 1e3,
baudrate: 100e3,
}
}

// Configure is intended to setup the I2C interface.
func (i2c *I2C) Configure(config I2CConfig) error {
// Default I2C bus speed is 100 kHz.
if config.Frequency != 0 {
i2c.baudrate = config.Frequency
i2c.SetBaudRate(config.Frequency)
}

// This exists for compatibility with machine.I2CConfig. SCL and SDA must
Expand All @@ -52,8 +52,6 @@ func (i2c *I2C) Configure(config I2CConfig) error {
i2c.sda = config.SDA
}

i2c.SetBaudRate(config.Frequency)

// enable pins
i2c.sda.High()
i2c.sda.Configure(machine.PinConfig{Mode: machine.PinOutput})
Expand All @@ -65,6 +63,8 @@ func (i2c *I2C) Configure(config I2CConfig) error {

// SetBaudRate sets the communication speed for the I2C.
func (i2c *I2C) SetBaudRate(br uint32) {
// At this time, the value of i2c.baudrate is ignored because it is fixed
// at 100 kHz. SetBaudrate() is exist for compatibility with machine.I2C.
i2c.baudrate = br
}

Expand Down

0 comments on commit a89a261

Please sign in to comment.