Skip to content

Commit

Permalink
Change order of SPI transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Unger committed Jan 16, 2024
1 parent 4d08d14 commit e6913d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/encoders/sc60228/SC60228.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include "./SC60228.h"

#include "Arduino.h"

SC60228::SC60228(SPISettings settings, int nCS) : settings(settings), nCS(nCS) {
// nix
Expand All @@ -13,6 +13,7 @@ void SC60228::init(SPIClass* _spi) {
if (nCS>=0)
pinMode(nCS, OUTPUT);
digitalWrite(nCS, HIGH);
delay(1);
spi->begin();
readRawAngle();
};
Expand Down Expand Up @@ -41,15 +42,15 @@ bool SC60228::isError() {

uint16_t SC60228::spi_transfer16(uint16_t outdata){
uint16_t result;
spi->beginTransaction(settings);
if (nCS>=0)
digitalWrite(nCS, LOW);
// min delay here: 250ns
spi->beginTransaction(settings);
result = spi->transfer16(outdata);
// min delay here: clock period / 2
spi->endTransaction();
if (nCS>=0)
digitalWrite(nCS, HIGH);
spi->endTransaction();
// min delay until next read: 250ns
return result;
};
Expand Down
2 changes: 1 addition & 1 deletion src/encoders/sc60228/SC60228.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef union {
#define SC60228_CPR 4096
#define SC60228_BITORDER MSBFIRST

static SPISettings SC60228SPISettings(8000000, SC60228_BITORDER, SPI_MODE0); // @suppress("Invalid arguments")
static SPISettings SC60228SPISettings(8000000, SC60228_BITORDER, SPI_MODE1); // @suppress("Invalid arguments")



Expand Down

0 comments on commit e6913d8

Please sign in to comment.