Pages: [1]   Go Down
Author Topic: Suggestions for SPI api  (Read 295 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
Karma: 9
Posts: 109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I noticed one is working on the SPI api's. I thought this is the moment to post some remarks.

1. Both SPI begin() api's, reset the data mode, bit order and divider to their defaults. This invalidates any previous calls to setDataMode(), setBitOrder() and setClockDivider(). The doc does not state that you should call these setters after begin(), and that would be counter intuitive too. Also there is avr code out there that calls the setters before begin(). Better would be to have begin() set data mode and friends from the values recorded in the mode[], ... data fields. (and initialize these correctly).
2. I find the following a bit counter intuitive:
static const uint8_t SS   = BOARD_SPI_SS0;

I relate the names MISO, MOSI and SCK to SS and therefore I would expect that e.g. SPI.setBitorder(SS, order) is the as SPI.setBitOrder(order), which is not the case.

I would suggest this:
static const uint8_t SS0   = BOARD_SPI_SS0;
static const uint8_t SS  = BOARD_SPI_DEFAULT_SS ;
(I know it would break some sketches, but now it can still be changed)
3. What about two macro's:
for sam:
#define SPI_CLOCK_MIN 1
#define SPI_CLOCK_MAX 255
for avr:

Nothing world shocking but a sketch that just wants to be conservative could use SPI_CLOCK_MAX ant that would compile for sam and avr.


Pages: [1]   Go Up
Jump to: