A PTX1xxR or a PTX130W device (NFC device) has been connected via SPI to a custom MCU and SDK initialization fails. It is unclear if an incorrect implementation of the SPI HAL in the SDK causes the issue or if the SPI channel in general is not working, e.g. wrong wiring or SPI module configuration.
It is recommended to run a smoke-test to ensure that the SPI interface is working without actually using the SDK code itself. For that purpose following Python code examples can be either used directly, or re-implemented for the target system. Get yourself familiar with SPI first (refer to https://en.wikipedia.org/wiki/Serial_Peripheral_Interface) before start interfacing to the NFC device using SPI.
Before connecting the NFC device to the host device please make sure that your SPI interface works in general by short-circuiting the MOSI and MISO and verifying with a basic SPI transceive operation if the data is echoed back correctly. Following python script can be used as an example (port it to the specific platform if the platform does not support Python 3):
#!/usr/bin/python import spidev spi = spidev.SpiDev() spi.open(0,0) spi.max_speed_hz = 1000000 msg = [0xDE, 0xAD, 0xC0, 0xDE] result = spi.xfer2(msg) print (''.join('0x' + format(x, '02X') + ',' for x in result))
The expected output when running this example is 0xDE,0xAD,0xC0,0xDE
. Please note that this only confirms that your SPI interface is able to send and receive data but it does not check if SPI parameters such as clock phase and clock polarity are set correctly. Verifying that is also possible as shown in the next step.
Connect the NFC device to the host device. Following SPI query is recommended for testing basic SPI communication with the NFC device.
To execute that command a simple python script can be used (port it to the specific platform if the platform does not support Python 3):
#!/usr/bin/python import spidev spi = spidev.SpiDev() spi.open(0,0) spi.max_speed_hz = 1000000 spi.mode = 0 #CPOL=0,CPHA=0 - data sampled at rising edge msg = [0x30, 0xFF, 0xFF, 0xFF] result = spi.xfer2(msg) print (''.join('0x' + format(x, '02X') + ',' for x in result))
The expected output when running this example is 0x00,0x00,0x00,0x21
. Note that this confirms basic SPI functionality but still implementation-dependent bugs (e.g. byte alignment for DMA transfers, maximum buffer size limitations) or even hardware-related issues (e.g. bad ground, capacitive behaviour on data lines) can cause a SPI communication fail even if the basic SPI transaction shown in this example works. For correct operation of the NFC device also an interrupt signal is required, but usually validation of the reception of that signal can be done while implementing the SDK's HAL layer.