some troubles with ili9341, spi connectivity issues?

ag123
Tue Apr 25, 2017 2:14 pm
after quite a bit of tests with the ili9341_stm library, i think i managed to get my rather ‘broken’ ili9341 lcds working.
while trying out the graphics test

the ili9341 i’m using is something like this http://www.ebay.com/itm/New-240×320-SPI … 1863818914
and working via spi interface with an additional C/D pin (command / data) – i read somewhere that some boards are hardwired for 9-bits SPI, need to figure out if it may be the case. for now it doesn’t seem so

i run into various register read and spi issues the register reads seem to vary between 2 consecutive read attempts separated by a delay and that i need to issue a sleep out and display on command before any graphics test would work
Display id: 0x0,0,0
Display status: 0x0,0,0,0
Display Power Mode: 0x8
MADCTL Mode: 0x0
Pixel Format: 0x6
set pix format 16 bits
Pixel Format: 0x5
Image Format: 0x8
Self Diagnostic: 0x0
sleep out << issue sleep out command
Display id: 0x0,0,0
Display status: 0xC0,0,0,0
Display Power Mode: 0x98
MADCTL Mode: 0x0
Pixel Format: 0x0
set pix format 16 bits
Pixel Format: 0x0 << invalid values of pixel format
Image Format: 0x0 << invalid values of image format
Self Diagnostic: 0x0 << incorrect values of self diagnostic status 0xC0 is expected after doing a sleep out command
display on << issue display on command
sleep out << issue sleep out command
ILI9341 Test!
Display id: 0x0,0,0
Display status: 0xC0,0,0,0
Display Power Mode: 0x9C
MADCTL Mode: 0x0
Pixel Format: 0x6
set pix format 16 bits
Pixel Format: 0x5
Image Format: 0x9C
Self Diagnostic: 0xC0 << now it looked a little more sane
Benchmark Time (microseconds)
Screen fill 682875 << note the graphics test terminates midstream on the lcd leaving a blank screen
Text 89295
Lines 510067
Horiz/Vert Lines 58799
Rectangles (outline) 39863
Rectangles (filled) 1418504
Circles (filled) 348216
Circles (outline) 393844
Triangles (outline) 120584
Triangles (filled) 541684
Rounded rects (outline) 144681
Rounded rects (filled) 1590095
Done!


ag123
Tue Apr 25, 2017 3:47 pm
changed the wires, similar symptoms, now worse, it doesn’t work :P :lol:
the values of the read (lcd) registers function seem to return different values with each set of consecutive call, (no reset, no display on, no sleep out etc) something else seemed amiss
isplay id: 0x0,0,0
Display status: 0x0,0,0,0
Display Power Mode: 0x8
MADCTL Mode: 0x0
Pixel Format: 0x0
set pix format 16 bits
Pixel Format: 0x0 << all zeros
Image Format: 0x0 << all zeros
Self Diagnostic: 0x0
Display id: 0x0,0,0
Display status: 0x0,0,0,0
Display Power Mode: 0x8
MADCTL Mode: 0x0
Pixel Format: 0x6
set pix format 16 bits
Pixel Format: 0x5<< looked more sane (note this is deliberately set for value 0x55, but actually 0x05 is retrieved)
Image Format: 0x8 << looked more sane
Self Diagnostic: 0x0
Display id: 0x0,0,0
Display status: 0x0,0,0,0
Display Power Mode: 0x8
MADCTL Mode: 0x0
Pixel Format: 0x5
set pix format 16 bits
Pixel Format: 0x5
Image Format: 0x8
Self Diagnostic: 0x0
Display id: 0x0,0,0
Display status: 0x0,0,0,0
Display Power Mode: 0x8
MADCTL Mode: 0x0
Pixel Format: 0x5
set pix format 16 bits
Pixel Format: 0xFF << all 0xFF !
Image Format: 0xFF << all 0xFF !
Self Diagnostic: 0xFF << all 0xFF !

david.prentice
Tue Apr 25, 2017 4:03 pm
The first step is to get a reliable diag() result.
Any problems there indicate unreliable SPI connections e.g. loose or broken wire.

Which version of the IDE are you using? Early “MapleCore” versions crash with the F() macro.

David.


ag123
Tue Apr 25, 2017 4:14 pm
thanks
i’m using the ILI9341_STM library pretty much from the existing F1 core
https://github.com/rogerclarkmelbourne/ … LI9341_STM
as for SPI i’m using this library
https://github.com/rogerclarkmelbourne/ … raries/SPI

basically made a copy of Adafruit_ILI9341_STM.cpp and running it ‘locally’ within the same app so that i can insert more statements to figure out the issues.
currently i’m doing my version of readcommand8(uint8_t cmd, 0) that doesn’t issue that ‘sekret’ command :lol:
and modified slightly (enclosed below) so that i can return multiple parameters, for the read-commands e.g. ILI9341_RDDST, the ili9341 can actually return several bytes of responses. hence the modification.
/*
params
buf[] u'd need to provide an array of bytes to store the results returned from ili9341
c - this is the ili9341 command
n - how many bytes to read and insert in buf[] from the response
*/
void Adafruit_ILI9341_STM::readcommandx(uint8 *buf, uint8_t c, int8 n) {
uint index = 0;
if (hwSPI)
spi_begin();

/*
SETDC_CMD();
CS_ENABLE();
spiwrite(0xD9); // woo sekret command?
SETDC_DATA();
spiwrite(0x10 + index);
CS_DISABLE();
*/

SETDC_CMD();
CS_ENABLE();
//if(hwSPI) digitalWrite(_sclk, LOW);
spiwrite(c);

SETDC_DATA();
SPI.transfer(0x00); //the first 8 bits/clocks are dummy clocks
for (int i = 0; i < n; i++) {
uint8 b = SPI.transfer(0x00);
*(buf+i) = b;
}

CS_DISABLE();
if (hwSPI)
spi_end();
}


Pito
Tue Apr 25, 2017 4:33 pm
I used the 9341 with Maple Mini, and the _stm (dma?) library. Wires 12-15cm long. It worked 18/36MHz spi fine.

ag123
Tue Apr 25, 2017 4:38 pm
thanks
i’d need to slowly debug this, i made my ‘custom’ readcommandx function return an extra byte, more than the spec, so far it doesn’t seem to say that my ili9341 is hardwired for 9bits spi, i tend to get both 0xff or 0x00, which for now didn’t mean anything in particular :lol:

david.prentice
Tue Apr 25, 2017 6:01 pm
You have a regular Red 2.4″ with Touch display.

It uses 8-bit SPI. Connect all the pins. Use the full constructor().

Make sure that you have solid connections. i.e. good header sockets.

David.


ag123
Tue Apr 25, 2017 9:05 pm
figured it out, my lcd reset pin is at pin 0 PB11 on maple mini, the codes are written to expect lcd reset at a pin other than 0
swapped the pins and now it works :D

surprisingly while now graphics test runs to completion, the varying values from lcd register reads commands persists, i.e. it still varies between consecutive sets of reads, the first reads after the graphics test run apparently reflect the correct values, after that it varies to 0xff and 0x00


zmemw16
Wed Apr 26, 2017 3:22 pm
does it have an auto-increment register address mode ?
srp

ag123
Wed Apr 26, 2017 7:03 pm
based on the ili9341 documentations
https://www.crystalfontz.com/controller … LI9341/142
https://www.crystalfontz.com/controllers/ILItek/ILI9341
e.g. page 83 section 8 command list, page 92 8.2.4 read display status (this is the detailed command spec)
the idea is we set the D/C pin low (i.e. command) issue the command
next pull D/C pin high (i.e. data) and start reading the results coming in at the MISO pin coming from the lcd.
the specs would suggest that for such a command, e.g. issue read display status command 0x09, and read the next 5 bytes from the miso pin, the first byte should be ignored while the next 4 bytes contains the status bytes

what i observed with my tests is that after running the graphics test and issue 0x09 read status, the status is correct / expected
however, subsequent same command and read start to ‘drift’ and i’d either get 0x00 or perhaps sometimes 0xff. 0xff is particularly observed after a reset and then issuing a display on and sleep out command. but a next read all that become 0x00

however despite all these goofy status bytes, currently graphics tests run to completion
there is some ‘magic’ in that initlal reset at tft.begin() and the initialization codes :lol:

for now i still don’t really understand spi e.g. is the spi clock running even if there is no SPI.transfer(0x00) command? and if after issuing the command, would there be circumstances where the lcd take more spi clocks before providing a response (the specs didn’t seem to suggest it)? other things that might influence the results are like timings as D/C and CS pins are gpio pins and the notion of ‘sekret’ command, i noted that issuing the ‘sekret’ command prior do not fix the invalid returned status. my guess is that there’s possibly something more i’d need to learn about spi and that it seem some information is not documented in the ‘reference manual’ for ili9341 (in particular some of those ‘magic’ cryptic commands found in tft.begin() are not documented in the reference manual)

just 2 cents
;)


david.prentice
Wed Apr 26, 2017 9:27 pm
If you don’t understand SPI, read Wikipedia.

You can read reg(0x04), reg(0x09) and GRAM registers directly.

You need the ‘sekret’ command to read multi-byte registers like ID (0xD3) or GAMMAP (0xE0)

As far as I can remember, the Adafruit code reads registers correctly. Use the full-fat method for index into a multi-byte register.

David.


Leave a Reply

Your email address will not be published. Required fields are marked *