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

atsamd21e18a I2C #680

Closed
hugolgst opened this issue Mar 31, 2023 · 6 comments
Closed

atsamd21e18a I2C #680

hugolgst opened this issue Mar 31, 2023 · 6 comments

Comments

@hugolgst
Copy link

Hello,

I am writing code for this board using ATSAMD21E18A.
I would like to initiate an I2C connection but am failing with this code:
Screenshot 2023-03-31 alle 14 45 37
following https://docs.rs/atsamd-hal/latest/atsamd_hal/sercom/i2c/index.html

The LED stays on and nothing is happening, I am not sure why

@sakian
Copy link
Contributor

sakian commented Mar 31, 2023

Doesn't look like you ever control the LED? Can try adding pa02.set_high().unwrap() or pa02.set_low().unwrap()?

@hugolgst
Copy link
Author

hugolgst commented Mar 31, 2023

@sakian Sorry I shortened the code but below there is a loop where I blink the LED.
When I do not .enable() the I2C Config it blinks well, when I do, the LED stays lit up and nothing is happening

@sakian
Copy link
Contributor

sakian commented Mar 31, 2023

I think you need to configure the peripheral clock then. Check this example out:

let gclk0 = clocks.gclk0();
let sercom3_clock = &clocks.sercom3_core(&gclk0).unwrap();
let pads = i2c::Pads::new(sda, scl);
let mut i2c = i2c::Config::new(&pm, peripherals.SERCOM3, pads, sercom3_clock.freq())
.baud(100.khz())
.enable();

When you enable, it waits for the register to be synchronized, which won't happen if the sercom isn't given a clock. You'll need to pass enable the peripheral clock, like in the example I linked.

As an aside, it would be nice to have the Config::new call take the whole clock, instead of just the clock frequency to make this impossible from happening.

@hugolgst
Copy link
Author

hugolgst commented Apr 3, 2023

@sakian Thanks, that was it. Since we are here at it I have another question, I am trying to communicate with this chip https://ww1.microchip.com/downloads/aemDocuments/documents/SCBU/ProductDocuments/DataSheets/ATECC608B-TNGTLS-CryptoAuthentication-Data-Sheet-DS40002250A.pdf and have successfully executed the wake call with the proper response but for some reason am getting a NACK with a payload that I know is working (tested and sent in another programming language). I suspect that the write function has a different behaviour than the one in Go (tinygo), but could be wrong.
Screenshot 2023-04-03 alle 18 51 43

would you have an idea why I am getting a NACK in the two instances of i2c.write?

@sakian
Copy link
Contributor

sakian commented Apr 4, 2023

I don't see anything wrong that sticks out to me. Probably need to go through standard debugging (make sure port is configured properly to talk to that chip, confirm data being sent is correct, probe data on wires to make sure it's correct, etc.).

@ianrrees
Copy link
Contributor

@hugolgst - did you get this sorted?

Gentle suggestion: rather than posting images of code, it's helpful to use code blocks so that others can easily copy-and-paste, use search, etc. For bigger pieces of code, a GitHub gist is be a good option too.

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

No branches or pull requests

3 participants