-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Wrong clock divider from setFrequency #6380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What frequency are we talking about here? |
sorry, I'm not very familar with github. I did not mention that this column is valid for the complete esp8266/Arduino. Yes, I'm speaking about SPI. In spi.cpp in method SPIClass::setFrequency in line 215 the value of minFreqReg is set to 0x7FFFF000: In line 219 this value ist passed to method setClockDivider: setClockDivider sets this value without modification to the SPI clock register (line 290): However, the twelve least significant bits of this register are responsible for the duty cycle. 0x0 is not correct here. The schould be filled with 0x020 for 0x7FFFF in the higher Bits. The best solution is replacing 0x7FFFF000 by 0x7FFFF020 in line 215 |
Just for my understanding. It looks like this line was changed 4 years ago in this commit: d7a88c3 |
Here's a good explanation for the SPI CLOCK register: www.esp8266.com. Look at "SPI_CLKCNT_H & SPI_CLKCNT_L". If the difference of both parts is zero no clock signal is generated. The difference schould be something about half of the number of SPI clock cycles. The problem only occurs when a frequency value is specified that is smaller than the minimum of 152 Hz. In this case 0x7FFFF000 is taken with zero values for both SPI_CLKCNT_H and SPI_CLKCNT_L . 0x7FFFF020 is the correct value. setFrequency calculates this value for 152 Hz but gives 0x7FFFF000 for 151 an lower. I assume that this error is rarely a problem, because such a low clock frequency is rarely used. |
Oops, I read this as I2C and not SPI and was going to link it to the rewrite. @UlliBien, this would be a very simple PR for you. Feel like taking it up and getting stuck in the |
Sorry, as mentioned I'm not familiar with github. I don't know how to do that. |
i'll be working on this issue. |
Thanks to fix suggestion from @UlliBien. Fixes: esp8266#6380
As mentioned I'm not familiar with github. Looking at "spi.cpp" there ist still the wrong statement. when does the change take effect? |
@UlliBien a PR (=pull request) was made by @thangktran as #6409. You can check his proposed code change in thst link. The PR is not merged yet, which is why you don't see it in the code base. |
Hello @UlliBien, If you would like to test my code, you would need to clone my repo https://github.com/thangktran/Arduino/tree/thangktran/bugfix/setFrequency_clock_divider since the change is not merged to [esp8266/Arduino] yet. |
Ok,
There is another question: Issue 2820 from 2016-04-05: #2820 This problem still exists. How to "reactivate" the issue? I added a working code as comment. |
Wrong clock divider from setFrequency(frq) if frq is below the minimal frequency (152 at 80 MHz processor clock). setFrequency passes 0x7FFFF000 to setClockDivider. For the correct setting of regL this should be 0x7FFFF020. 0x7FFFF020 is the value you get when you call setFrequency(152).
The text was updated successfully, but these errors were encountered: