SH1106 - Transferring long buffer via SPI

2018-03-27 13:51:44

I am using an SH1106 and am creating my own driver for it. Nearly everything is doing great with about 2/3ms send time using transfer16. I did notice however that I can use transfer with a buffer and length to give a 1ms display time; something that'd be extremely useful.

For reference before here is the datasheet:

http://support.technologicalarts.ca/docs/Components/OLED13-SPI/SH1106.pdf

So the working solution is this:

SPI.beginTransaction(settings);

//

for (int page = 0; page < 8; page++)

{

digitalWrite(DC, LOW);

SPI.transfer(0xB0 + page);

SPI.transfer(0x02);

SPI.transfer(0x10);

digitalWrite(DC, HIGH);

for (int column = 0; column < 128; column += 2)

SPI.transfer16(buffer[(page * 128) + column]);

}

digitalWrite(DC, LOW);

//

SPI.endTransaction();

This for each of the 8 pages writes the 128 bytes 2 at a time. I want to write the 128 bytes in a single call. This would be something like this:

SPI.transfer(buffer + (page * 128), 128