Configurable SPI CPHA and CPOL
parent
57abb7ecc4
commit
13ee425352
|
|
@ -18,6 +18,8 @@ namespace spi {
|
|||
hal::gpio::GPIO_pin sck_pin;
|
||||
hal::gpio::GPIO_pin ss_pin;
|
||||
uint8_t prescaler;
|
||||
uint8_t cpha;
|
||||
uint8_t cpol;
|
||||
};
|
||||
|
||||
__attribute__((always_inline)) inline void Init(SPI_TypeDef *const hspi, SPI_InitTypeDef *const conf) {
|
||||
|
|
@ -30,7 +32,7 @@ namespace spi {
|
|||
const uint8_t spi2x = (conf->prescaler == 7) ? 0 : (conf->prescaler & 0x01);
|
||||
const uint8_t spr = ((conf->prescaler - 1) >> 1) & 0x03;
|
||||
|
||||
hspi->SPCRx = (0 << SPIE) | (1 << SPE) | (0 << DORD) | (1 << MSTR) | (0 << CPOL) | (0 << CPHA) | (spr << SPR0);
|
||||
hspi->SPCRx = (0 << SPIE) | (1 << SPE) | (0 << DORD) | (1 << MSTR) | ((conf->cpol & 0x01) << CPOL) | ((conf->cpha & 0x01) << CPHA) | (spr << SPR0);
|
||||
hspi->SPSRx = (spi2x << SPI2X);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ void setup() {
|
|||
.sck_pin = gpio::GPIO_pin(TMC2130_SPI_SCK_PIN),
|
||||
.ss_pin = gpio::GPIO_pin(TMC2130_SPI_SS_PIN),
|
||||
.prescaler = 2, //4mhz
|
||||
.cpha = 1,
|
||||
.cpol = 1,
|
||||
};
|
||||
spi::Init(SPI0, &spi_conf);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue