Hi!
I'm building a project that involves a breadboard ATMega328P. It does not have a crystal, because I'm going for simplicity and compactness. However, if adding a 20MHz crystal will speed up I²C and SPI communications, it would surely be worth it.
For those curious:
So, if I got 2.5x the clock rate, would I have 2.5x communication speed?
Thanks!
Depends on the device.
For I2C it can range from 100 kHz to a few MHz. The DS324 has a 4 MHz SPI.
Oh, Thanks!
I couldn't find anything in the 1.44" TFT's datasheet. Does SPI have a standard? (This is the protocol that needs to be fastest)
But just adding a 20MHz crystal will not speed it up. The default I2C speed on the Arduino is 100kHz, no matter the crystal.
And the datasheet just mentions the timing. Not in Hz but in s but that's just each others inverse.
The relevant spec is "Serial clock cycle", which specifies the minimum period the SPI clock must have. Period is just the reciprocal of frequency. Note that it's higher for reading than for writing. The 66 ns write period represents a maximum frequency of 15 MHz, and the 150 ns read period is 6.67 MHz.
Unlike the UART and TWI peripherals, the SPI peripheral in the ATmega328P does not give you fine control of the bit rate. The most is gives you is very coarse selection with a 7-bit prescaler, that can divide the main clock speed by a power of 2 from 2 to 128.
All of the peripherals are of course limited by the main oscillator frequency. Because there's no frequency multiplier in the chip (often just called a PLL even though that's only half of what goes into a frequency multiplier), it's impossible to generate bit rates higher than the chip's clock speed.
So yes, increasing the clock speed does let you increase the maximum speed you can generate for all of the communication peripherals. A 20 MHz crystal will let you use up to 10 MHz SPI.
Tip: If you're using Windows calculator in Scientific mode, the shortcut key for doing a reciprocal operation is 'r'. Easy reciprocals make it a lot easier to do many kinds of calculations relevant to electronics, not the least of which is parallel resistances and period/frequency conversion.