Merge pull request #13537 from jue89/feature/sam0-spi-frequency
cpu/sam0_common: mitigate rounding errors of SPI baud rate calculation
This commit is contained in:
commit
681678e3f3
@ -36,7 +36,7 @@ extern "C" {
|
|||||||
#define AT86RF2XX_PARAM_INT GPIO_PIN(PB, 0)
|
#define AT86RF2XX_PARAM_INT GPIO_PIN(PB, 0)
|
||||||
#define AT86RF2XX_PARAM_SLEEP GPIO_PIN(PA, 20)
|
#define AT86RF2XX_PARAM_SLEEP GPIO_PIN(PA, 20)
|
||||||
#define AT86RF2XX_PARAM_RESET GPIO_PIN(PB, 15)
|
#define AT86RF2XX_PARAM_RESET GPIO_PIN(PB, 15)
|
||||||
#define AT86RF2XX_PARAM_SPI_CLK SPI_CLK_1MHZ
|
#define AT86RF2XX_PARAM_SPI_CLK SPI_CLK_5MHZ
|
||||||
/** @}*/
|
/** @}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -103,8 +103,11 @@ int spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk)
|
|||||||
|
|
||||||
/* configure bus clock, in synchronous mode its calculated from
|
/* configure bus clock, in synchronous mode its calculated from
|
||||||
* BAUD.reg = (f_ref / (2 * f_bus) - 1)
|
* BAUD.reg = (f_ref / (2 * f_bus) - 1)
|
||||||
* with f_ref := CLOCK_CORECLOCK as defined by the board */
|
* with f_ref := CLOCK_CORECLOCK as defined by the board
|
||||||
const uint8_t baud = (sam0_gclk_freq(spi_config[bus].gclk_src) / (2 * clk) - 1);
|
* to mitigate the rounding error due to integer arithmetic, the
|
||||||
|
* equation is modified to
|
||||||
|
* BAUD.reg = ((f_ref + f_bus) / (2 * f_bus) - 1) */
|
||||||
|
const uint8_t baud = ((sam0_gclk_freq(spi_config[bus].gclk_src) + clk) / (2 * clk) - 1);
|
||||||
|
|
||||||
/* configure device to be master and set mode and pads,
|
/* configure device to be master and set mode and pads,
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user