Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C not initiating unless pins.X.Y is called #13

Open
chalkers opened this issue Dec 20, 2018 · 9 comments
Open

I2C not initiating unless pins.X.Y is called #13

chalkers opened this issue Dec 20, 2018 · 9 comments
Assignees
Labels

Comments

@chalkers
Copy link

chalkers commented Dec 20, 2018

The following code on a cold boot doesn't initiate the I2C.

let smile: number[] = []
let meh: number[] = []
let frown: number[] = []
ht16k33.setAddress(HT16K33_I2C_ADDRESSES.ADD_0x70)
smile = [60, 66, 165, 129, 165, 153, 66, 60]
meh = [60, 66, 165, 129, 189, 129, 66, 60]
frown = [60, 66, 165, 129, 153, 165, 66, 60]
forever(function () {
    ht16k33.render(frown)
    pause(1000)
    ht16k33.render(meh)
    pause(1000)
    ht16k33.render(smile)
    pause(1000)
})

However if I add the following code I2C works...

let smile: number[] = []
let meh: number[] = []
let frown: number[] = []
/** HERE **/
pins.LED.digitalWrite(false)
ht16k33.setAddress(HT16K33_I2C_ADDRESSES.ADD_0x70)
smile = [60, 66, 165, 129, 165, 153, 66, 60]
meh = [60, 66, 165, 129, 189, 129, 66, 60]
frown = [60, 66, 165, 129, 153, 165, 66, 60]
forever(function () {
    ht16k33.render(frown)
    pause(1000)
    ht16k33.render(meh)
    pause(1000)
    ht16k33.render(smile)
    pause(1000)
})

Or even just setting the pull on the pins....

let smile: number[] = []
let meh: number[] = []
let frown: number[] = []
/** HERE **/
pins.SDA.setPull(PinPullMode.PullNone)
pins.SCL.setPull(PinPullMode.PullNone)
ht16k33.setAddress(HT16K33_I2C_ADDRESSES.ADD_0x70)
smile = [60, 66, 165, 129, 165, 153, 66, 60]
meh = [60, 66, 165, 129, 189, 129, 66, 60]
frown = [60, 66, 165, 129, 153, 165, 66, 60]
forever(function () {
    ht16k33.render(frown)
    pause(1000)
    ht16k33.render(meh)
    pause(1000)
    ht16k33.render(smile)
    pause(1000)
})

I don't need do set both but I just did as a test.

@chalkers
Copy link
Author

I have two trinket m0 that I'm testing right now. One works fine, the other works only sometimes after multiple resets and different pause times at the between the beginning and setAddress calls. But it tends not to work on a cold boot.

@chalkers
Copy link
Author

OK, another test on the one doesn't work...

I drop adafruit-circuitpython-trinket_m0-3.1.1.uf2 on the board, double tap to reset then drop the firmware from MakeCode that I wrote above, then the I2C device works. Unplug and then connect to an external power supply for cold boot and it doesn't work.

So whatever initializes the board with circuitpython enables i2c to work on the board that isn't working...

@jamesadevine
Copy link
Contributor

Thanks @chalkers, great investigation, will reproduce and work out a fix (which from your great diagnostics will be simple 😄).

@pelikhan
Copy link

pelikhan commented Feb 4, 2019

This call returns ERR_DENIED

    ret = i2c_m_sync_init(&i2c, i2c_sercom);

@jamesadevine
Copy link
Contributor

@pelikhan it returns that if the I2C is already enabled (from reading the code)

@pelikhan
Copy link

pelikhan commented Feb 4, 2019

I've added tracing and this is first time in the execution we try to mount i2c.

@pelikhan
Copy link

pelikhan commented Feb 4, 2019

It looks like we are clashing with mounting a SPI for neopixels on Pad5.

@pelikhan
Copy link

pelikhan commented Feb 8, 2019

@chalkers how I do repro your issue?

@chalkers
Copy link
Author

Sorry, I've been in the middle of a move. If I recall correctly, I2C doesn't work on a "cold boot" i.e. after it's been removed from the computer and plugged in to an external source. The only way I've been able to guarantee it to work is to use:

pins.LED.digitalWrite(false)

or

pins.SDA.setPull(PinPullMode.PullNone)
pins.SCL.setPull(PinPullMode.PullNone)

I haven't unpacked all my electronics stuff yet but that is what I can remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants