File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -121,14 +121,14 @@ void SPIClass::setBitOrder(uint8_t bitOrder) {
121121 * @return
122122 */
123123static uint32_t ClkRegToFreq (spiClk_t * reg) {
124- return (F_CPU / ((reg->regPre + 1 ) * (reg->regN + 1 )));
124+ return (SPI_MAX_SPEED / ((reg->regPre + 1 ) * (reg->regN + 1 )));
125125}
126126
127127void SPIClass::setFrequency (uint32_t freq) {
128128 static uint32_t lastSetFrequency = 0 ;
129129 static uint32_t lastSetRegister = 0 ;
130130
131- if (freq >= F_CPU ) {
131+ if (freq >= SPI_MAX_SPEED ) {
132132 setClockDivider (0x80000000 );
133133 return ;
134134 }
@@ -164,7 +164,7 @@ void SPIClass::setFrequency(uint32_t freq) {
164164 reg.regN = calN;
165165
166166 while (calPreVari++ <= 1 ) { // test different variants for Pre (we calculate in int so we miss the decimals, testing is the easyest and fastest way)
167- calPre = (((F_CPU / (reg.regN + 1 )) / freq) - 1 ) + calPreVari;
167+ calPre = (((SPI_MAX_SPEED / (reg.regN + 1 )) / freq) - 1 ) + calPreVari;
168168 if (calPre > 0x1FFF ) {
169169 reg.regPre = 0x1FFF ; // 8191
170170 } else if (calPre <= 0 ) {
Original file line number Diff line number Diff line change 4545#define SPI_CLOCK_DIV64 0x04fc1001 // 250 KHz
4646#endif
4747
48+ #define SPI_MAX_SPEED (80000000L )
49+
4850const uint8_t SPI_MODE0 = 0x00 ; // /< CPOL: 0 CPHA: 0
4951const uint8_t SPI_MODE1 = 0x01 ; // /< CPOL: 0 CPHA: 1
5052const uint8_t SPI_MODE2 = 0x10 ; // /< CPOL: 1 CPHA: 0
You can’t perform that action at this time.
0 commit comments