From a9dff1ad25bcda009ca17ea3a3b552af5e23c90e Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Wed, 5 Sep 2012 15:23:32 -0700 Subject: [PATCH] AP_HAL_AVR: bugfix to SPIDriver.cpp * Had freq set to 10 mhz, not 1mhz... stupid mistake. --- libraries/AP_HAL_AVR/SPIDriver.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/AP_HAL_AVR/SPIDriver.cpp b/libraries/AP_HAL_AVR/SPIDriver.cpp index 0736829f6a..2feeced81d 100644 --- a/libraries/AP_HAL_AVR/SPIDriver.cpp +++ b/libraries/AP_HAL_AVR/SPIDriver.cpp @@ -20,14 +20,13 @@ void ArduinoSPIDriver::init(void* machtnichts) { SPCR |= _BV(MSTR); SPCR |= _BV(SPE); - // set_freq(10000000); - // dbg: set_freq is broken - // lets just set SPR0 (div/16) - SPCR |= _BV(SPR0); + set_freq( 1000000); } void ArduinoSPIDriver::set_freq(uint32_t freq_hz) { - int div = F_CPU / freq_hz; + const uint16_t freq_khz = (uint16_t)(freq_hz / 1000UL); + const uint16_t fcpu_khz = (uint16_t)(F_CPU / 1000UL); + const int16_t div = fcpu_khz / freq_khz; /* can't divide clock by more than 128. */ uint8_t b = _divider_bits( div > 128 ? 128 : ((uint8_t) div)); _set_clock_divider_bits(b);