KurtE
Senior Member+
I have taken a quick look. The issue is that the ILI9341_t3 library is using the FIFO on the SPI and the returned values from the drawPixel have not been poped off of the input fifo.Have been trying to use ILI9341_t3 library along with doing some other SPI stuff but don't get expected results, received bytes are delayed by one byte.
Here is code to reproduce problem. No hardware is connected except for a jumper from pin0 to pin12 to get some values into the SPI register.
In the ILI9341_t3 library it needs a logical call to: waitFifoEmpty, which in the library header file is:
Code:
void waitFifoEmpty(void) {
uint32_t sr;
uint32_t tmp __attribute__((unused));
do {
sr = KINETISK_SPI0.SR;
if (sr & 0xF0) tmp = KINETISK_SPI0.POPR; // drain RX FIFO
} while ((sr & 0xF0F0) > 0); // wait both RX & TX empty
}
I did a copy of that code into your test program (after the call to drawPixel) and I think it is getting better results.
The real question is when and where to do something like in the main code base. This happens because SPI directly uses the registers. In particular:
Code:
inline static uint8_t transfer(uint8_t data) {
SPI0_SR = SPI_SR_TCF;
SPI0_PUSHR = data;
while (!(SPI0_SR & SPI_SR_TCF)) ; // wait
return SPI0_POPR;
}
I could hack something in, but Paul may want to think it through. Things like maybe BeginTransaction (if the settings don't match, clear the queues...)