Closed Greece2 closed 4 years ago
I'm a bit late to the party, but hopefully I can shed some light for someone in the future. I did not like how the SPI port had to be explicitly called in the begin function so that has been changed. Now you can do something a little less confusing: lightning.beginSPI(spiCS)
.
The way its' setup now is that it will default to 1MHz (down from 2MHz just in case there are slower peripherals), but the user can also pass it a speed like it was setup previously to get a different...speed.
As to your question, the divider you're using will work until lightning.beginSPI
is called because it's setting the speed SPI port relative to the internal clock and then beginSPI
is setting it to something different: 2000000 and yes that is 2MHz. Valid SPI port speed parameters depend on the upstream controller chip - your ATmega 328 in this case. You'll have to do some googling to figure that out, I don't know it off the top of my head.
I suggest trying something smaller, perhaps 1000000. One thing to note: do not set it to 500 kHz because that speed will interfere with the lightning detector's antenna.
Using an ATmega328P, internal 1 MHZ osc., the SPI bus works fine with all other components like LCD-displays etc. up to the moment where the statement
lightning.beginSPI(spiCS, 2000000)
seems to mess up the speed of the SPI port, checked that with an oscilloscope. Much too fast now, i.e. for the LCD-display, only garbled characters. After having a look at the source file of this lib, I found this routine:So, what is "spiPortSpeed" ? 2000000 (like in the expample) meaning 2000000 Hz -> 2MHz ?! What are valid values for this parameter ? And the third parameter of the function call "SPIClass &spiPort" is never mentioned in the examples nor explained. Trying to slow the SPI down again with
SPI.setClockDivider(SPI_CLOCK_DIV64);
(or values of 8, 16, 32, ... 128) doesn't seem to have any effect now. Works fine before lightning.beginSPI(spiCS, 2000000) is issued.Any idea how not to mess up the SPIport (speed) or how to set it correctly in this lib ?
Regards, Greece2