0

I've got a Waveshare PN532 RFID reader/writer. I want to use it with a Pi 4B, but since it is already using a HAT with no free GPIO, I want to use it in UART mode, but not connecting to the GPIO pins 8 and 10, but rather using a TTL-to-USB adapter. Now I want to follow the first step in the wiki, "Quick testing", which is explaining this for a windows PC and "Serial assistant software". It says the connection should be baud rate 115200 and 8N1. The instruction then is:

Select correct serial port and open.

Send data below to wake up FN532 module:

55 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF 03 FD D4 14 01 17 00

...

The response from PN532 module should be:

00 00 FF 00 FF 00 00 00 FF 02 FE D5 15 16 00

How do I do this on the Pi (Raspbian Buster)? I guess I must somehow send these bytes to /dev/ttyUSB0 and poll the response.


Here is an attempt:

  • terminal 1: cat /dev/ttyUSB0 >out.bin
  • terminal 2: echo -en '\x55\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\x03\xFD\xD4\x14\x01\x17\x00' > /dev/ttyUSB0

But how do I stop cat? If I ctrl-C it, the contents of out.bin is empty. If I use use cat /dev/ttyUSB0, I can see a response of five unprintable characters; my idea was to hexdump -C -n out.bin, but apparently I need to flush and quit cat, or can I pipe it into a "live" hex view without it waiting for linefeed or flush?

photo of ttl-to-usb adapter sitting between Pi and RFID board

2
  • Not really Pi specific. Perhaps use echo with the -e option to send the bytes.
    – joan
    Dec 14, 2021 at 21:46
  • @joan Can you please advise how to send bytes to ttyUSB0 via echo, and how to hex dump response from ttyUSB0, choosing the given baud rate etc.
    – 0__
    Dec 14, 2021 at 21:49

1 Answer 1

0

To configure the device

$ stty -F /dev/ttyUSB0 speed 115200 cs8 -cstopb -parenb -echo

To wait for the next fifteen bytes to arrive

$ hexdump -C -n 15 /dev/ttyUSB0

To send bytes (from a second terminal)

$ echo -en '\x55\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\x03\xFD\xD4\x14\x01\x17\x00' > /dev/ttyUSB0

The hexdump terminal then should print

00000000  00 00 ff 00 ff 00 00 00  ff 02 fe d5 15 16 00     |...............|
0000000f

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.