nanoframework / Home

:house: The landing page for .NET nanoFramework repositories.
https://www.nanoframework.net
MIT License
845 stars 75 forks source link

MFRC522: Unable to write data to MIFARE Classic 1K card #1226

Closed AlexanderMaleckij closed 1 year ago

AlexanderMaleckij commented 1 year ago

Library/API/IoT binding

nanoFramework.Iot.Device.Mfrc522 NuGet package

Visual Studio version

No response

.NET nanoFramework extension version

No response

Target name(s)

No response

Firmware version

No response

Device capabilities

No response

Description

Transceive method does not work properly when called with a command to write data. It also affects the WriteDataBlock method from the MifareCard class that uses it. According to datasheet (section 11.3), 2 separate commands must be sent to write a data block, while in the current implementation, only one command is sent.

WriteDataBlock under the hood calls 1 time Transceive method of the CardTransceiver abstract class, with the dataToSend parameter having the following format:

dataToSend parameter (SpanByte)
Byte № 0 1 2...
Value 0xA0 (160) BlockNumber Data

Transceive method implementation under the hood calls SendWithCrc method, which by itself works great.

The Transceive method can behave differently and call different private methods depending on the value of the command byte (byte №0 of the dataToSend parameter), so a new private method could be introduced to handle the write command, which would call the SendWithCrc method 2 times.

How to reproduce

No response

Expected behaviour

No response

Screenshots

No response

Sample project or code

No response

Aditional information

No response

Ellerbach commented 1 year ago

@AlexanderMaleckij there has been quite few improvements in the cards on the .NET IoT repository. See latest PR here https://github.com/dotnet/iot/pull/2028 and here https://github.com/dotnet/iot/pull/2027 which seems to fix those kind of issues.

So feel free to take those changes, incorporate them into the IoT Device repository here https://github.com/nanoframework/nanoFramework.IoT.Device

And then you'll help a lot of people with this fix :-) Thanks in advance!