nfc-tools / libnfc

Platform independent Near Field Communication (NFC) library
http://nfc-tools.org
GNU Lesser General Public License v3.0
1.69k stars 440 forks source link

serial speed for pn532 #708

Open paweljasinski opened 8 months ago

paweljasinski commented 8 months ago

Are serial speeds other than 115200 supported when using pn532? Both: device.connstring = "pn532_uart:/dev/ttyUSB0:57600 and device.connstring = "pn532_uart:/dev/ttyUSB0:460800 produce a code dump.

NFC-funs commented 7 months ago

hi,paweljasinski: Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed); It's in the file “uart.c”. But 115200 is the PN532's default value. If you want to use other baud, you must use "SetSerialBaudRate" command first. image

paweljasinski commented 6 months ago

To be sure I am not misunderstanding anything.

NFC-funs commented 6 months ago

Please refer to the diagram: image To be sure that the baud rate-"Real HSU Freq" error is not greater than 4%: image

PN532 User Manual V0.2.pdf PN532_C1.pdf

paweljasinski commented 6 months ago

already have a basic communication with 230.4.

To be sure that the baud rate-"Real HSU Freq" error is not greater than 4%: Do I have to adjust registers value (HSU_CNT and HSU_PRE) myself, or it happens as part of SetSerialBaudRate?

I have another question: Once the comm speed is changed from default, it is persistent until reset or power cycle. For now I am coding with assumption that libnfc works with the board after reset and starts with 115200 and changes to requested speed. The code is not trying to reestablished communication after program terminated but board did not get reset and is still using the altered speed. Is this something you would considered to be acceptable in PR?

NFC-funs commented 6 months ago

Poll the command "SAMConfiguration" at different baud rates before communication, such as: 55 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF 03 FD D4 14 01 17 00, and receive the right ACK.