Hello together,
I have a problem which I can not solve on my own. I am using the Teensy3 optimized ILI9341 Display Driver library from: https://github.com/PaulStoffregen/ILI9341_t3
I ported it to use UTFT, which works fine so far. Now I want to communicate with another SPI device. But however, after I called the first function that writes to the display (for ex. DrawRect), I am not receiving valid data from the other SPI device (a sensor) any more.
For the other SPI slave, I am using the following code structure to receive data:
When I use it before calling any LCD function, it works fine. Afterwards, only weird data is coming in. So I think the ILI9341 alters some SPI registers which I have to reset.
Inside the ILI9341 library, there is this in the init:
And then it uses some functions I do not completely understand to send out data:
I think it has something to do with those last functions as the init method alone does not cause the sensor to send weird data, its only happening after for example a call of this:
Thanks for any help in advantage !
Max
I have a problem which I can not solve on my own. I am using the Teensy3 optimized ILI9341 Display Driver library from: https://github.com/PaulStoffregen/ILI9341_t3
I ported it to use UTFT, which works fine so far. Now I want to communicate with another SPI device. But however, after I called the first function that writes to the display (for ex. DrawRect), I am not receiving valid data from the other SPI device (a sensor) any more.
For the other SPI slave, I am using the following code structure to receive data:
Code:
SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));
digitalWrite(CS, LOW);
...
SPI.transfer(0x00);
...
digitalWrite(CS, HIGH);
SPI.endTransaction();
Inside the ILI9341 library, there is this in the init:
Code:
void UTFT::InitLCD(byte orientation)
{
pinMode(LED,OUTPUT);
disp_x_size=319;
disp_y_size=239;
TFT_BL_ON;
orient=orientation;
if (SPI.pinIsChipSelect(CS, DC)) {
pcs_data = SPI.setCS(CS);
pcs_command = pcs_data | SPI.setCS(DC);
} else {
pcs_data = 0;
pcs_command = 0;
return;
}
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
...
}
Code:
//void waitFifoNotFull(void) __attribute__((always_inline)) {
void waitFifoNotFull(void) {
uint32_t sr;
uint32_t tmp __attribute__((unused));
do {
sr = SPI0.SR;
if (sr & 0xF0) tmp = SPI0_POPR; // drain RX FIFO
} while ((sr & (15 << 12)) > (3 << 12));
}
//void waitFifoEmpty(void) __attribute__((always_inline)) {
void waitFifoEmpty(void) {
uint32_t sr;
uint32_t tmp __attribute__((unused));
do {
sr = SPI0.SR;
if (sr & 0xF0) tmp = SPI0_POPR; // drain RX FIFO
} while ((sr & 0xF0F0) > 0); // wait both RX & TX empty
}
void waitTransmitComplete(void) __attribute__((always_inline)) {
uint32_t tmp __attribute__((unused));
while (!(SPI0.SR & SPI_SR_TCF)) ; // wait until final output done
tmp = SPI0_POPR; // drain the final RX FIFO word
}
void writecommand_cont(uint8_t c) __attribute__((always_inline)) {
SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
waitFifoNotFull();
}
void writedata8_cont(uint8_t c) __attribute__((always_inline)) {
SPI0.PUSHR = c | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
waitFifoNotFull();
}
void writedata16_cont(uint16_t d) __attribute__((always_inline)) {
SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
waitFifoNotFull();
}
void writecommand_last(uint8_t c) __attribute__((always_inline)) {
waitFifoEmpty();
SPI0.SR = SPI_SR_TCF;
SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0);
waitTransmitComplete();
}
void writedata8_last(uint8_t c) __attribute__((always_inline)) {
waitFifoEmpty();
SPI0.SR = SPI_SR_TCF;
SPI0.PUSHR = c | (pcs_data << 16) | SPI_PUSHR_CTAS(0);
waitTransmitComplete();
}
void writedata16_last(uint16_t d) __attribute__((always_inline)) {
waitFifoEmpty();
SPI0.SR = SPI_SR_TCF;
SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1);
waitTransmitComplete();
}
Code:
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
setAddr(x1, y1, x1+w-1, y1+h-1);
writecommand_cont(ILI9341_RAMWR);
word color = ( fch << 8 | fcl );
for(int y=h; y>0; y--) {
for(int x=w; x>1; x--) {
writedata16_cont(color);
}
writedata16_last(color);
}
SPI.endTransaction();
Max