Improve SPI clock configuration.

This commit is contained in:
Peter Van Hoyweghen 2015-09-05 20:41:03 +02:00
parent 82e5d4a88d
commit bfffb17e40
1 changed files with 9 additions and 7 deletions

View File

@ -38,14 +38,16 @@
#define PROG_FLICKER true
// Configure SPI clock.
// E.g. for an attiny @128 kHz:
// (pulseWidth should be > 2 cpu cycles, so take 3 cycles:)
// #define SPI_CLOCK (128000/3)
// Configure SPI clock (in Hz).
// E.g. for an attiny @128 kHz: the datasheet states that both the high
// and low spi clock pulse must be > 2 cpu cycles, so take 3 cycles i.e.
// divide target f_cpu by 6:
// #define SPI_CLOCK (128000/6)
//
// A clock slow enough for an attiny85 @ 1MHz, is a reasonable default:
#define SPI_CLOCK (1000000/3)
#define SPI_CLOCK (1000000/6)
// Select hardware or software SPI, depending on SPI clock.
// Currently only for AVR, for other archs (Due, Zero,...),
@ -161,7 +163,7 @@ public:
}
void beginTransaction(SPISettings settings) {
pulseWidth = 1000 / (settings.clock / 1000);
pulseWidth = (500000 + settings.clock - 1) / settings.clock;
if (pulseWidth == 0)
pulseWidth = 1;
}