I have been thru ILI9341 LCD spec and just cannot figure out how to retrieve registers values using command parameters .
For example status register - 0x09 - have 32 bits of data in four 8 bits "parameters " .
Using ARM / Due SPI I can read 16 bits , however -
are these parameters 1 and 2 ?
and how do I read the next 16 bits?
I have not found a single code example how to do this - the published code read only the "no parameters" required registers.
As an example - this is needed to get ILI9341 ID which is in 4 parameters and the first one is a dummy - no valid data .
Any hint would be appreciated.
Jim
You set a special register and how many bytes to read. Look at how to read the ID e.g . 93 41
I am not at a PC. I will edit this message later with an example.
David.
david_prentice:
You set a special register and how many bytes to read. Look at how to read the ID e.g . 93 41I am not at a PC. I will edit this message later with an example.
David.
David, just figured it out , Need to set "command mode " to .8/16/32 bits.
Thanks for your help.
Jim .
here is an example:
#include "Adafruit_ILI9341.h"
...
void diag_reg(char *name, uint8_t reg, uint8_t n)
{
uint8_t x = reg;
Serial.print(name);
Serial.print(" (0x");
Serial.print(x < 0x10 ? "0" : "");
Serial.print(x, HEX);
Serial.print("):");
for (int i = 0; i < n; i++) {
uint8_t x = tft.readcommand8(reg, i);
Serial.print(x < 0x10 ? " 0" : " ");
Serial.print(x, HEX);
}
Serial.println("");
}
void setup() {
Serial.begin(9600);
tft.begin();
// read diagnostics (optional but can help debug problems)
diag_reg("RDMODE", ILI9341_RDMODE, 1);
diag_reg("ILI9341_RDMADCTL", ILI9341_RDMADCTL, 1);
diag_reg("ILI9341_RDPIXFMT", ILI9341_RDPIXFMT, 1);
diag_reg("ILI9341_RDIMGFMT", ILI9341_RDIMGFMT, 1);
diag_reg("ILI9341_RDSELFDIAG", ILI9341_RDSELFDIAG, 1);
diag_reg("DSPFUNC ", 0xb6, 5);
diag_reg("ID4 ", 0xD3, 4);
diag_reg("ILI9341_RDID1", ILI9341_RDID1, 2);
diag_reg("ILI9341_RDID2", ILI9341_RDID2, 2);
diag_reg("ILI9341_RDID3", ILI9341_RDID3, 2);
diag_reg("GAMMAP ", 0xE0, 16);
diag_reg("GAMMAN ", 0xE1, 16);
diag_reg("INTERFACE ", 0xf6, 4);
...
and the Adafruit_ILI9341.cpp has:
uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) {
if (hwSPI) spi_begin();
digitalWrite(_dc, LOW); // command
digitalWrite(_cs, LOW);
spiwrite(0xD9); // woo sekret command?
digitalWrite(_dc, HIGH); // data
spiwrite(0x10 + index);
digitalWrite(_cs, HIGH);
digitalWrite(_dc, LOW);
digitalWrite(_sclk, LOW);
digitalWrite(_cs, LOW);
spiwrite(c);
digitalWrite(_dc, HIGH);
uint8_t r = spiread();
digitalWrite(_cs, HIGH);
if (hwSPI) spi_end();
return r;
}
Note the "secret" 0xD9 command. I get output:
RDMODE (0x0A): 9C
ILI9341_RDMADCTL (0x0B): 48
ILI9341_RDPIXFMT (0x0C): 05
ILI9341_RDIMGFMT (0x0A): 9C
ILI9341_RDSELFDIAG (0x0F): C0
DSPFUNC (0xB6): 00 08 82 27 04
ID4 (0xD3): 41 00 93 41
ILI9341_RDID1 (0xDA): 00 00
ILI9341_RDID2 (0xDB): 00 00
ILI9341_RDID3 (0xDC): 00 00
GAMMAP (0xE0): 00 0F 31 2B 0C 0E 08 4E F1 37 07 10 03 0E 09 00
GAMMAN (0xE1): 00 00 0E 14 03 11 07 31 C1 48 08 0F 0C 31 36 0F
INTERFACE (0xF6): 00 01 00 00
David.
david_prentice:
here is an example:#include "Adafruit_ILI9341.h"
...
void diag_reg(char *name, uint8_t reg, uint8_t n)
{
uint8_t x = reg;
Serial.print(name);
Serial.print(" (0x");
Serial.print(x < 0x10 ? "0" : "");
Serial.print(x, HEX);
Serial.print("):");
for (int i = 0; i < n; i++) {
uint8_t x = tft.readcommand8(reg, i);
Serial.print(x < 0x10 ? " 0" : " ");
Serial.print(x, HEX);
}
Serial.println("");
}
void setup() {
Serial.begin(9600);
tft.begin();
// read diagnostics (optional but can help debug problems)
diag_reg("RDMODE", ILI9341_RDMODE, 1);
diag_reg("ILI9341_RDMADCTL", ILI9341_RDMADCTL, 1);
diag_reg("ILI9341_RDPIXFMT", ILI9341_RDPIXFMT, 1);
diag_reg("ILI9341_RDIMGFMT", ILI9341_RDIMGFMT, 1);
diag_reg("ILI9341_RDSELFDIAG", ILI9341_RDSELFDIAG, 1);
diag_reg("DSPFUNC ", 0xb6, 5);
diag_reg("ID4 ", 0xD3, 4);
diag_reg("ILI9341_RDID1", ILI9341_RDID1, 2);
diag_reg("ILI9341_RDID2", ILI9341_RDID2, 2);
diag_reg("ILI9341_RDID3", ILI9341_RDID3, 2);
diag_reg("GAMMAP ", 0xE0, 16);
diag_reg("GAMMAN ", 0xE1, 16);
diag_reg("INTERFACE ", 0xf6, 4);
...
and the Adafruit_ILI9341.cpp has:uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) {
if (hwSPI) spi_begin();
digitalWrite(_dc, LOW); // command
digitalWrite(_cs, LOW);
spiwrite(0xD9); // woo sekret command?
digitalWrite(_dc, HIGH); // data
spiwrite(0x10 + index);
digitalWrite(_cs, HIGH);
digitalWrite(_dc, LOW);
digitalWrite(_sclk, LOW);
digitalWrite(_cs, LOW);
spiwrite(c);
digitalWrite(_dc, HIGH);
uint8_t r = spiread();
digitalWrite(_cs, HIGH);
if (hwSPI) spi_end();
return r;
}
Note the "secret" 0xD9 command. I get output:RDMODE (0x0A): 9C
ILI9341_RDMADCTL (0x0B): 48
ILI9341_RDPIXFMT (0x0C): 05
ILI9341_RDIMGFMT (0x0A): 9C
ILI9341_RDSELFDIAG (0x0F): C0
DSPFUNC (0xB6): 00 08 82 27 04
ID4 (0xD3): 41 00 93 41
ILI9341_RDID1 (0xDA): 00 00
ILI9341_RDID2 (0xDB): 00 00
ILI9341_RDID3 (0xDC): 00 00
GAMMAP (0xE0): 00 0F 31 2B 0C 0E 08 4E F1 37 07 10 03 0E 09 00
GAMMAN (0xE1): 00 00 0E 14 03 11 07 31 C1 48 08 0F 0C 31 36 0F
INTERFACE (0xF6): 00 01 00 00David.
Thanks,
I should be able to rewrite it for SPI.
I may just ditch current code alltogether , it goes thru about five functions before it does the actual SPI read.
But it is not time critical , so Arduino API's are cool.
The chain I have been tracing also has the "sekret" command.
It funny how "original " some of the code in use is.
I was unable to find the secret command in ILI9341 spec.
Jim
It only works in SPI mode. It is not mentioned in the regular ILI9341 datasheet. It is the only way to identify the ILI9340/9341. It seems odd that the RDID1, RDID2, RDID3 commands do not return simple 93, 41, 00.
It is mentioned in other datasheets but I can't remember which ones.
David.
I did not look in details, but is your code using hardware SPI?
I am still trying to identify the sequence of code when command is executed.
It look as the code ends up in SPI transaction function.
Than it does put command in transmit register and than waits for 8 bits of data in receive register.
I assume that the SPI slave interprets the command and attempts to respond with multiple parameters.
The task is how to have a transaction function capable of checking for multiple responses. .
If multiple res
I'll keep digging into the source code . it cannot be that hard.
"It seems odd that the RDID1, RDID2, RDID3 commands do not return simple 93, 41, 00."
Because that is for 3 wire SPI interface , ID numbers are parameters of single register read. in 4 wire SPI this ILI9341 is set for in hardware. Hence need to figure out how to retrieve 32 bits in single SPI "transaction".