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
Implement SPI driver on ATmega2560 #4045
Implement SPI driver on ATmega2560 #4045
Conversation
@danielamkaer Please add a prefix to your commit message, like "cpu/atmega2560: Add SPI driver implementation", and also squash your whitespace fixes into the main commit. I don't have the hardware available right now so I can't test. @N8Fear or @LudwigOrtmann, do you have any SPI devices that you can wire up to the Arduino? |
#define SPI_1_EN 0 | ||
|
||
// SPI 0 Registers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use C comment style. //
-> /* */
ffc05f3
to
3664b33
Compare
#if SPI_0_EN | ||
case SPI_0: | ||
SPI_0_DDR |= (1<<SPI_0_MOSI)|(1<<SPI_0_SCK); | ||
SPI_0_DDR &= ~((1<<SPI_0_MISO)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines could be moved to spi_conf_pins
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration of the pins depends on whether it is master/slave, no parameter for spi_conf_pins to configure that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, didn't see SPI_0_SCK
changed lines.
3664b33
to
5678835
Compare
switch (dev) { | ||
#if SPI_0_EN | ||
case SPI_0: | ||
SPI_0_DR = out; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a ATmega expert, but wouldn't it be better to check if a previously set data register was already written out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can read from the data sheet, there isn't a way to check if the outgoing data register is empty. However the function will not return until SPIF is set, which indicates that the operation is finished.
Welcome to RIOT, @danielamkaer! |
@danielamkaer Great job! Please see some minor remarks above. |
be465fe
to
297bf0c
Compare
I have, but I probably won't get around to testing this PR in the immediate future. |
36a575d
to
4e77d79
Compare
Now that I gave up my Atmega2560 board, testing this PR might also be a job for @ReneHerthel :-) |
With diff --git a/boards/arduino-mega2560/Makefile.features b/boards/arduino-mega2560/Makefile.features
index 6d25415..ad1a466 100644
--- a/boards/arduino-mega2560/Makefile.features
+++ b/boards/arduino-mega2560/Makefile.features
@@ -1,4 +1,5 @@
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_gpio
FEATURES_PROVIDED += periph_timer
+FEATURES_PROVIDED += periph_spi
FEATURES_MCU_GROUP = avr8 I get
Please ping me when this is resolved. |
33013c6
to
9cf1db7
Compare
@LudwigKnuepfer try now. |
9cf1db7
to
8ed35ff
Compare
@danielamkaer: On a general note regarding our development procedures - please don't instantly squash your commits, it makes it easier for reviewers to see what changed. The "needs squashing" label is not there to alert you, but to prevent merging of unsquashed PRs. |
Okay @LudwigKnuepfer - I'll remember for the future. This PR + 2 others are my first ever contributions to open source projects. |
@danielamkaer No sweat, you'll (hopefully) get more feedback like this during your first steps. And remember: although some work has gone into our processes and policies, they are not perfect and can benefit from your input. So don't refrain from speaking out if you see room for improvement. |
Can't test, don't know how to map GPIO pins to board layout anymore due to changes in RIOT =( |
6e78880
to
f24c0b4
Compare
@LudwigKnuepfer - Lookup using https://www.arduino.cc/en/Hacking/PinMapping2560 Translate pin 4 (PG5) on Arduino into |
Any progress? |
@LudwigKnuepfer I guess we can shed some light on the pin mapping: we don't have a sub-set statically mapped anymore, but you can access any MCU pin freely using the Now mapping the acutal MCU pins to Arduino pins is another issue, just refer to the Arduino doc (e.g. the link posted above) for details. But I have an idea how to make this easier - will prepare a PR... |
how about this: #4313. Now you can just use |
Sorry, I did not have time for testing.. I would not feel hurt if anyone else tests this ;) |
@danielamkaer Ping. A kind reminder for rebase. |
@zhuoshuguo I need some help I think. I'm trying to do |
@danielamkaer |
f24c0b4
to
ddde457
Compare
@thomaseichinger, @haukepetersen, @PeterKietzmann, anyone for a review? |
Yes, in general but not so much time currently. At the latest during the next Hack'n'ACK |
Maybe @aabadie would like to try this? (: |
Thanks @kYc0o. Why not, if I have time. |
Hi, just tested this PR, for me it does not work. Connecting a logic analyzer to pins 50-52 does not show me any pin activity when sending data on the bus... |
While starting to debug the driver, I did so many changes, that I decided to make a new PR -> #5020. @danielamkaer: Sorry again for starting to actually test this so late! It's the good old thing that you only start with something until you really need it... |
closed in favor of #5020 |
No description provided.