Skip to content

I2C driver implementation (Master mode) for the SAMR21 #2016

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

Merged
merged 1 commit into from
Dec 15, 2014
Merged

I2C driver implementation (Master mode) for the SAMR21 #2016

merged 1 commit into from
Dec 15, 2014

Conversation

biboc
Copy link
Member

@biboc biboc commented Nov 15, 2014

Implementation of the I2C driver (Master mode) for the SAMR21 including:

  • periph_conf.h: I2C configuration added
  • i2c.c: I2C_0, implementation of all functions but slave mode

I do some "return;" when I detect an error which is not that good. Which solution do I have?

@thomaseichinger thomaseichinger added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: new feature The issue requests / The PR implemements a new feature for RIOT swp-telematic-sose14 and removed swp-telematic-sose14 labels Nov 16, 2014
@thomaseichinger thomaseichinger added this to the Release NEXT MAJOR milestone Nov 16, 2014
@thomaseichinger thomaseichinger self-assigned this Nov 16, 2014
@biboc
Copy link
Member Author

biboc commented Nov 17, 2014

@thomaseichinger , Why did Travis CI build fail?

@miri64
Copy link
Member

miri64 commented Nov 17, 2014

@bapclenet cppcheck found some issues:

cpu/samd21/periph/i2c.c:52: style (unassignedVariable): Variable 'pin_scl' is not assigned a value.
cpu/samd21/periph/i2c.c:53: style (unassignedVariable): Variable 'pin_sda' is not assigned a value.
cpu/samd21/periph/i2c.c:55: style (unassignedVariable): Variable 'clock_source_speed' is not assigned a value.

They are triggered since the variables in question are only assigned in the #if I2C_0_EN build path.

@thomaseichinger
Copy link
Member

Travis fails because cppcheck complains.

cpu/samd21/periph/i2c.c:52: style (unassignedVariable): Variable 'pin_scl' is not assigned a value.
cpu/samd21/periph/i2c.c:53: style (unassignedVariable): Variable 'pin_sda' is not assigned a value.
cpu/samd21/periph/i2c.c:55: style (unassignedVariable): Variable 'clock_source_speed' is not assigned a value.

Cppcheck isn't smart regarding preprocessor defines and and if statements. You could try initializing with 0.

#define I2C_SDA PIN_PA16
#define I2C_SCL PIN_PA17
#define I2C_0_PINS (PORT_PA16 | PORT_PA17)
#define I2C_0_REF_F (8000000UL) // Default Clock Source on reset OSC8M - 8MHz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align the defines and use /* C-style comments */

@miri64
Copy link
Member

miri64 commented Nov 17, 2014

OT: cppcheck IS smart regarding preprocessor defines, checking every possible build path ;-). If you leave a variable unset in a possible build path it could lead to errors; if you do it intentionally you should very carefully reason why.

port_group = &I2C_0_PORT;
pin_scl = I2C_SDA;
pin_sda = I2C_SCL;
i2c_port = I2C_0_PINS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assigning I2C_0_PINS to i2c_port is quite confusing. Maybe rename s/i2c_port/i2c_pins/ ?

@thomaseichinger
Copy link
Member

@bapclenet Awesome work! Some first style comments above and please change to spaces instead of tabs for indentation. Will test it in the afternoon.

@thomaseichinger
Copy link
Member

@bapclenet Please rebase. Also you still have some tabs in your code. https://github.com/RIOT-OS/RIOT/wiki/Coding-conventions#indentation-and-braces

@biboc
Copy link
Member Author

biboc commented Nov 20, 2014

How do I rebase?
I did "git rebase" in my master branch but I don't see any differences.

@BytesGalore
Copy link
Member

@bapclenet sorry that was wrong.
try git fetch upstream && git rebase upstream/master in master,
then change to this branch and use git rebase master

@biboc
Copy link
Member Author

biboc commented Nov 20, 2014

Rebase done, thank you @BytesGalore!

@thomaseichinger
Copy link
Member

Travis failing is unrelated to this PR. Will be solved by #2064.

@thomaseichinger thomaseichinger added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 27, 2014
@wiredsource
Copy link
Member

@bapclenet

26 files changed...? This is not only a I2C PR anymore :-)

@biboc
Copy link
Member Author

biboc commented Nov 28, 2014

A problem occured with my rebase apparently...
I will repair that this afternoon

I don't know how I did that.
How can I repair it?
Should I create another pull request?

@thomaseichinger
Copy link
Member

@haukepetersen could you take another look?

@thomaseichinger thomaseichinger removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Dec 11, 2014
@haukepetersen
Copy link
Contributor

code looks good to me, though I don't have an I2C device here for testing. I also kicked Travis once more.

@wiredsource
Copy link
Member

I have had a logic analyzer connected to it and it seems all right...
I was trying to implement the SHT21 driver without success... But that the SHT21 drivers fault not this PR.

@PeterKietzmann
Copy link
Member

I will test it with one of the ultrasonic sensors

@PeterKietzmann
Copy link
Member

I tested this PR with #1998 and #2179. I2C seems to work but for this test if get STATUS_ERR_TIMEOUT at any point. On stm32f4discovery this test ran really stable

@biboc
Copy link
Member Author

biboc commented Dec 12, 2014

How do you test it ? Which test do you use ? I may have a look this
week-end to solve the problem.
You always receive STATUS ERR TIMEOUT ?
Le 12 déc. 2014 10:19, "Peter Kietzmann" [email protected] a écrit
:

I tested this PR with #1998 #1998
and #2179 #2179. I2C seems to work
but for this test if get STATUS_ERR_TIMEOUT at any point. On
stm32f4discovery this test ran really stable


Reply to this email directly or view it on GitHub
#2016 (comment).

@biboc
Copy link
Member Author

biboc commented Dec 12, 2014

Two other questions :
Which frequency do you use ?
Are you sure about your address device ? STATUS ERROR TIME OUT mainly occurs when the I2C device doesn't answer so either the address is wrong or the speed or something else.

@PeterKietzmann
Copy link
Member

Hi! In #2179 is a test for the srf08 supersonic ranger which is an i2c device. The address is correct as the same application runs stable on stm32f4discovery. Also it runs stable for a while on samr21-xpro but then it gets stuck and one can see the debug message STATUS_ERR_TIMEOUT. I'm using I2C_SPEED_NORMAL which should lead to ~100kbps. I'll try another i2c ranger

@PeterKietzmann
Copy link
Member

I tested this with the srf02 ultrasonic ranger and it seems to work stable. I assume i2c is fine. Do you have another i2c device to test with?

@PeterKietzmann
Copy link
Member

Ok just do clarify the situation a bit: I tested this i2c implementation with tests/drivers_srf02 and tests/drivers_srf08 (PR #2179). For both sensors the i2c-based device drivers do work. But when testing the srf08 ranger, I got the problems described above, when I have a logic analyzer in parallel. These problems didn't occur when testing with srf02. However, I tried to reproduce this a several times and it occured again and again.

@biboc
Copy link
Member Author

biboc commented Dec 12, 2014

Ok, so basically, you try watch the I2C frame with the logic analyzer ?
And that works with the srf02 but not with the srf08 (and you fall every time into the debug error, in start, read or write function ? )
That's a it weird if it works for one and not another.
I use the SI7013 with an logic analyzer in parrallel and it works.
What do you want me to do then?

@PeterKietzmann
Copy link
Member

Nothing more :-) ! I give my ACK for the functionality as this behavior is probably an electrical one. Good to here that is is also fine with your SI7013

@biboc
Copy link
Member Author

biboc commented Dec 13, 2014

Good to here that :-)
Thanks

What's wrong with Travis CI build?

@PeterKietzmann
Copy link
Member

Code looks good to me and I also ACKed the functionality. As I am not too deep into that board, is someone else willing to click merge?

@thomaseichinger
Copy link
Member

Kicked Travis, will merge when passed.

@biboc
Copy link
Member Author

biboc commented Dec 15, 2014

What should I change for Travis test to pass?
"
failed: riot_and_cpp, vtimer_msg_diff
"

@thomaseichinger
Copy link
Member

@bapclenet Nothing, Travis seems to have some random fails. Built locally without errors so let's do this.

ACK & Go

thomaseichinger added a commit that referenced this pull request Dec 15, 2014
cpu/samd21: I2C driver implementation (Master mode)
@thomaseichinger thomaseichinger merged commit 29c5822 into RIOT-OS:master Dec 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants