1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +03:00

fix SPI speed calculation @160Mhz Clock

This commit is contained in:
Markus Sattler
2015-05-15 13:42:30 +02:00
parent b4a8bb0653
commit 2eea25873d
2 changed files with 5 additions and 3 deletions

View File

@ -121,14 +121,14 @@ void SPIClass::setBitOrder(uint8_t bitOrder) {
* @return
*/
static uint32_t ClkRegToFreq(spiClk_t * reg) {
return (F_CPU / ((reg->regPre + 1) * (reg->regN + 1)));
return (SPI_MAX_SPEED / ((reg->regPre + 1) * (reg->regN + 1)));
}
void SPIClass::setFrequency(uint32_t freq) {
static uint32_t lastSetFrequency = 0;
static uint32_t lastSetRegister = 0;
if(freq >= F_CPU) {
if(freq >= SPI_MAX_SPEED) {
setClockDivider(0x80000000);
return;
}
@ -164,7 +164,7 @@ void SPIClass::setFrequency(uint32_t freq) {
reg.regN = calN;
while(calPreVari++ <= 1) { // test different variants for Pre (we calculate in int so we miss the decimals, testing is the easyest and fastest way)
calPre = (((F_CPU / (reg.regN + 1)) / freq) - 1) + calPreVari;
calPre = (((SPI_MAX_SPEED / (reg.regN + 1)) / freq) - 1) + calPreVari;
if(calPre > 0x1FFF) {
reg.regPre = 0x1FFF; // 8191
} else if(calPre <= 0) {