Closed Mechalicious closed 9 months ago
you can use SPI2_HOST.
cfg.spi_host = SPI2_HOST;
Thanks, It's "working" unfortunately i'm having trouble reading data from both spi "at the same time" Changing the cs pin too fast in the loop doesn't work for both It does when i put a long wait time between both periphericals but i want to use cs quite simultaneously Would you know a better way to handle the data ?
Do not manipulate the CS pin outside of the library without permission. If you do so, it is only natural that they will stop working.
How can I use digitalWrite with the lib ? i'm not finding any method or how can I use permissions
Normally, the SPI bus is released after use; assertion and deassertion of the CS pin is automatic. All you have to do is to exclusively control multiple SPI devices so that their communication does not occur at the same time. I don't know how the RFID library is built, but you just need to make sure that it does not communicate with the RFID during the LCD drawing operation.
How would you stop the communication with the display in lgfx in order to communicate with the RFID module ?
No communication unless drawing instructions are used. If you are using LVGL, there should be an instruction to draw to the LCD in the drawing handler you wrote.
Okay thank you very much
If you are using startWrite, the SPI bus is occupied until you use endWrite. In this case, use endWrite before communicating with RFID, and use startWrite after communicating with RFID.
Sorry, i'm Still having troubles making both work Would you mind taking a look at what's wrong ?
The loop
void loop()
{
lv_timer_handler();
vTaskDelay(pdMS_TO_TICKS(TASK_SLEEP_PERIOD_MS));
unsigned long currentMillis = millis();
unsigned long elapsedMillis = currentMillis - StartOfInterval;
if (elapsedMillis >= ResetInterval && !spiState)
{
StartOfInterval = currentMillis;
elapsedMillis = 0;
rfid.PCD_Reset();
initRfid();
Serial.println("Resetting reader");
}
if (!spiState) {
rfidCheck();
}
unsigned long elapsedMillis2 = currentMillis - RfidStartOfInterval;
// 50ms
if (elapsedMillis2 >= ScreenRfidResetInterval) {
elapsedMillis2 = 0;
RfidStartOfInterval = currentMillis;
spiState = !spiState;
}
}
The rfidcheck :
void rfidCheck() {
if ( ! rfid.PICC_IsNewCardPresent())
return;
// Verify if the NUID has been readed
if ( ! rfid.PICC_ReadCardSerial())
return;
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
Serial.println(rfid.PICC_GetTypeName(piccType));
if (rfid.uid.uidByte[0] != nuidPICC[0] ||
rfid.uid.uidByte[1] != nuidPICC[1] ||
rfid.uid.uidByte[2] != nuidPICC[2] ||
rfid.uid.uidByte[3] != nuidPICC[3] ) {
Serial.println(F("A new card has been detected."));
// Store NUID into nuidPICC array
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
Serial.println(F("The NUID tag is:"));
Serial.print(F("In hex: "));
printHex(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
Serial.print(F("In dec: "));
printDec(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
playSound();
}
else Serial.println(F("Card read previously."));
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}
The display flush:
static void display_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
#ifdef DISABLE_FLUSH_DURING_BENCHMARK
if (disable_flush) {
lv_disp_flush_ready(disp);
return;
}
#endif
if (spiState) {
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
Serial.println("Calling display flush");
display.startWrite();
display.setAddrWindow(area->x1, area->y1, w, h);
display.writePixels((uint16_t *)&color_p->full, w * h, true);
display.endWrite();
}
lv_disp_flush_ready(disp);
}
display_flush関数では必ずフラッシュする必要があると思いますが、 spiStateによって勝手に分岐してデータを破棄すると動作がおかしくなりませんか?
これはLGFXのバグではなくてあなたのプログラムの問題だと思います。私はあなたの便利なデバッガーではありません。 LGFXのバグだというのであれば確実に再現できるコンパクトなプログラムを用意して新しいIssueを作ってください。
Hi,
I connected both touch screen and rfid reader to an esp32 Both are working separately but i can't make them work together I might have troubles configuring spi in lgfx My config:
Below, in the initRfid if i uncomment SPI.Begin(); the reader works well but no more screen. The opposite happens if i comment SPI.begin();
How can i configure the spi bus to make them work ?