Mega ATmega2560 + PN523 + TFT LCD Touch Screen Expansion Shield - conflict

Hello,

As will be noticed further, I am new in the exciting Arduino world, so please forgive possible common knowledge gaps extensive reading in the last several months haven't been able to fill.

Hardware setup:
Arduino Mega ATmega2560 (micro USB) - https://www.aliexpress.com/item/32850843888.html
3.2" 240X400TFT LCD Touch Screen Expansion Shield (note the exact chip model is ILI9327, not HX8352B as shown on picture; pins out is identical) - 3.2" 3.2 Inch 240x400 Tft Lcd Touch Screen Expansion Shield Led Display Module 5v / 3.3v With Touch Pen For Arduino - Lcd Modules - AliExpress
PN532 NFC RFID Wireless Module - 1set Pn532 Nfc Rfid Wireless Module V3 User Kits Reader Writer Mode Ic S50 Card Pcb Attenna I2c Iic Spi Hsu - Integrated Circuits - AliExpress

Screen Expansion Shield connected directly on top of the Arduino Mega leaving uncovered only digital pins from 23 to 53 (+5V and GND).
Screen and touch functionality don’t use SPI neither for data transfer nor management according specification. The shield however is connected to SPI pins on ICSP for SD card communication support. SD card is not used (SPI pins on ICSP) and not needed.

PN532 connected on SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI communication using the SPI library. Setup of those pins is made in the test sketch.

Used libraries:
HCDisplay.h // HCDisplay specific ILI9327 library from HCDisplay Arduino library for Hobby Components Displays - forum.hobbycomponents.com - attached
Adafruit_PN532.h //standard
SPI.h //standard

Test sketch:
TestReadMifare.ino - attached

Problem:
Screen and touch function work very well when connected alone to Arduino Mega.
PN532 works very well when connected alone to Arduino Mega.
When connected in the same time to Arduino and the attached sketch is uploaded the PN532 can’t be found by the board even with screen setup is commented out in the code.

Goal:
Get screen, touch and PN532 working together.

I believe there is a SPI communication mismanagement although SD card in not used. Maybe a conflict between hardware and software SPI pins… guidance would be highly appreciated.

Thank you in advance,
Lara

TestReadMifare.ino (7.81 KB)

HCDisplay_V0_2.zip (344 KB)

Update

It turns out that if all SPI ports for PN532 are set to digital pins different than the ones cross connected with the hardware pins (in Arduino Mega those are 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). The devices operate normally together.

I updated TestReadMifare.ino with:

#define PN532_SCK  (35)
#define PN532_MISO (37)
#define PN532_MOSI (39)
#define PN532_SS   (41)

and all worked fine.

Hope this would be useful for some newbie as myself, otherwise the moderators could freely delete the posts.

Happy Arduining!

It appears that the HCDisplay library does a ton of direct port manipulation and probably does not leave the SPI in a good state for the PN532. I would suggest that you change the PN532 connection to something that is NOT the SPI pins (44-48 or something) since your code already is using the software SPI version for the PN532

edit: a bit late with the post :slight_smile: