@@ -40,6 +40,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4040
4141#define I2C_FREQ 400000L // I2C Frequency is 400kHz (fast as possible)
4242
43+ // Configure SPI settings - Max clk frequency for display is 10MHz
44+ SPISettings oledSettings (10000000 , MSBFIRST, SPI_MODE0);
45+
4346/* * \brief Set Up SPI Interface
4447
4548 Sets up the SPI pins, initializes the Arduino's SPI interface.
@@ -52,10 +55,9 @@ void MicroOLED::spiSetup()
5255 pinMode (csPin, OUTPUT); // CS is an OUTPUT
5356 digitalWrite (csPin, HIGH); // Start CS High
5457
55- // Initialize the SPI library:
56- SPI.setClockDivider (SPI_CLOCK_DIV2); // Fastest SPI clock possible
57- SPI.setDataMode (SPI_MODE0); // CPOL=0 and CPHA=0, SPI mode 0
58+ #if defined(__AVR__)
5859 pinMode (10 , OUTPUT); // Required for setting into Master mode
60+ #endif
5961 SPI.begin ();
6062}
6163
@@ -66,9 +68,11 @@ void MicroOLED::spiSetup()
6668**/
6769void MicroOLED::spiTransfer (byte data)
6870{
69- digitalWrite (csPin, LOW);
71+ SPI.beginTransaction (oledSettings);
72+ digitalWrite (csPin, LOW);
7073 SPI.transfer (data);
71- digitalWrite (csPin, HIGH);
74+ digitalWrite (csPin, HIGH);
75+ SPI.endTransaction ();
7276}
7377
7478/* * \brief Initialize the I2C Interface
0 commit comments