Skip to content

Commit

Permalink
[sam] Fix SPI bug in handling of CPHA/CPOL
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbridejc committed Feb 7, 2022
1 parent 3f3ff3d commit ac46099
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/modm/platform/spi/sam/spi_master.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ public:

static void
setDataMode(DataMode mode) {
uint32_t value = (uint32_t)mode ^ 2; // Flip CPHA bit
Regs()->SPI_CSR[0] = (Regs()->SPI_CSR[0] & ~(SPI_CSR_CPOL | SPI_CSR_NCPHA)) | (value << SPI_CSR_CPOL_Pos);
uint32_t value = (uint32_t)mode ^ 1; // Flip CPHA bit
Regs()->SPI_CSR[0] = (Regs()->SPI_CSR[0] & ~(SPI_CSR_CPOL | SPI_CSR_NCPHA)) |
(((value & 2) >> 1) << SPI_CSR_CPOL_Pos) |
((value & 1) << SPI_CSR_NCPHA_Pos);
}

static void
Expand Down

0 comments on commit ac46099

Please sign in to comment.