mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
fix SPI speed calculation @160Mhz Clock
This commit is contained in:
parent
b4a8bb0653
commit
2eea25873d
@ -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) {
|
||||
|
@ -45,6 +45,8 @@
|
||||
#define SPI_CLOCK_DIV64 0x04fc1001 //250 KHz
|
||||
#endif
|
||||
|
||||
#define SPI_MAX_SPEED (80000000L)
|
||||
|
||||
const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0
|
||||
const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1
|
||||
const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user