Skip to content

Conversation

@devsaurus
Copy link
Member

Fixes #1845.

  • This PR is for the dev branch rather than for master.
  • This PR is compliant with the other contributing guidelines as well (if not, please describe why).
  • I have thoroughly tested my contribution.
  • The code changes are reflected in the documentation at docs/en/*.

Having the I2C configuration included in the modules' init functions is an issue for a shared bus. In worst case it prevents coexistence with other I2C slaves on the same bus:

This PR introduces a setup() function for each listed module which performs the core hardware initialization and avoids any (re) configuration of the I2C bus. The existing init() function is kept and tagged as deprecated with planned removal in (one of) the next master drop.

I don't have any of the sensors on my desk - my verification is therefore restricted to compilation and basic call tests. Tagged the related originators / maintainers of the modules, please double check the changes on real hardware.

@marcelstoer
Copy link
Member

Can you apply these changes to #1880 as well (can be done even before we merge it)?

@hvegh
Copy link
Contributor

hvegh commented Mar 29, 2017 via email

@devsaurus devsaurus mentioned this pull request Mar 29, 2017
4 tasks
@v1993
Copy link
Contributor

v1993 commented Mar 30, 2017

Can I help with testing?

@marcelstoer
Copy link
Member

Sure, we appreciated your support. Let us know if you need help building your custom firmware from https://github.com/devsaurus/nodemcu-firmware/tree/refactor_i2c_init.

@v1993
Copy link
Contributor

v1993 commented Apr 1, 2017

Note to am2320:

i2c.setup(0, sda, scl, i2c.SLOW)
am2320.setup()

failed. But

i2c.setup(0, sda, scl, i2c.SLOW)
tmr.delay(100)
am2320.setup()

is OK.

@v1993
Copy link
Contributor

v1993 commented Apr 1, 2017

local sda = 3
local scl = 4

local duration = 1000

local i2c = require 'i2c'
local tmr = require 'tmr'
local am2320 = require 'am2320'

i2c.setup(0, sda, scl, i2c.SLOW)
tmr.delay(100)
am2320.setup()

local getData = function()
	local h, t = am2320.read()
	print(string.format("Humidity: %s%%", h / 10))
	print(string.format("Temperature: %s\194\176C", t / 10))
end

tmr.create():alarm(duration, tmr.ALARM_AUTO, getData)

am2320 is working.

@devsaurus
Copy link
Member Author

devsaurus commented Apr 1, 2017

Ah, I see. I missed the os_delay_us(1500); in the original am2320_init(). Will need to re-add that in the C code and the example.

Thanks a lot for testing!

Just noticed that I did port the os_delay_us(1500); over to am2320_setup().
The sequence of

i2c.setup(0, sda, scl, i2c.SLOW)
am2320.setup()

should be equivalent to

am2320.init(sda, scl)

I start to wonder how the latter could ever have worked.

@marcelstoer
Copy link
Member

@v1993 FYI tmr.delay will sooner or later be removed, see #1892.

@v1993
Copy link
Contributor

v1993 commented Apr 2, 2017

Also,

am2320.init(sda, scl)

is OK. I'm really confused.

@marcelstoer
Copy link
Member

Everything ready, isn't it?

@devsaurus
Copy link
Member Author

Kind of, could be merged with certain risk for untested changes in the other modules.

@FrankX0
Copy link
Contributor

FrankX0 commented Apr 27, 2017

Can we merge? Risk of the untested changes are low.

@marcelstoer
Copy link
Member

Can we merge?

I'd support that but I'd like to hear from other collaborators as well.

@marcelstoer marcelstoer added this to the 2.1 follow-up milestone May 15, 2017
@marcelstoer marcelstoer merged commit 7dae523 into nodemcu:dev May 21, 2017
@devsaurus devsaurus deleted the refactor_i2c_init branch May 21, 2017 14:45
eiselekd pushed a commit to eiselekd/nodemcu-firmware that referenced this pull request Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants