Yes, you're right, I modified my library to this method and it worked and I think it's faster than my previous coding system.
But if I'm dealing with a faster SPI module; e.g. a TFT display, should I use this method with command/data functions ?
Like this:
void glcd_cmd(uint8_t cmd) {
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE3));
digitalWrite(CS_PIN, HIGH);
SPI.transfer(0xF8);
SPI.transfer(cmd & 0xF0);
SPI.transfer(cmd << 4);
digitalWrite(CS_PIN, LOW);
SPI.endTransaction();
}
// ----------------------------------------------------------------
void glcd_data(uint8_t data){
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE3));
digitalWrite(CS_PIN, HIGH);
SPI.transfer(0xFA);
SPI.transfer(data & 0xF0);
SPI.transfer(data << 4);
digitalWrite(CS_PIN, LOW);
SPI.endTransaction();
}
Or use my old method:
void glcd_cmd(uint8_t cmd){
SPI.transfer(CMD_MSK);
SPI.transfer(cmd & 0xf0);
SPI.transfer(cmd << 4);
}
void glcd_data(uint8_t data){
SPI.transfer(DATA_MSK);
SPI.transfer(data & 0xf0);
SPI.transfer(data << 4);
}
I think my older method it more faster, but with the ST7920, the first method should be enough and it saved a lot of memory as well.