@@ -48,7 +48,11 @@ void MFRC522::PCD_WriteRegister(PCD_Register reg, byte value) {
48
48
uint8_t data[2 ];
49
49
data[0 ] = reg;
50
50
data[1 ] = value;
51
+
52
+ ESP32CPP::GPIO::low ((gpio_num_t )_chipSelectPin); // Select slave
51
53
m_spi.transfer (data, 2 );
54
+ ESP32CPP::GPIO::high ((gpio_num_t )_chipSelectPin); // Release slave
55
+
52
56
} // End PCD_WriteRegister()
53
57
54
58
@@ -63,7 +67,11 @@ void MFRC522::PCD_WriteRegister(PCD_Register reg, byte count, byte* values) {
63
67
uint8_t * pData = new uint8_t [count + 1 ];
64
68
pData[0 ] = reg;
65
69
memcpy (pData + 1 , values, count);
70
+
71
+ ESP32CPP::GPIO::low ((gpio_num_t )_chipSelectPin); // Select slave
66
72
m_spi.transfer (pData, count + 1 );
73
+ ESP32CPP::GPIO::high ((gpio_num_t )_chipSelectPin); // Release slave
74
+
67
75
delete[] pData;
68
76
} // End PCD_WriteRegister()
69
77
@@ -77,7 +85,11 @@ byte MFRC522::PCD_ReadRegister(PCD_Register reg) {
77
85
uint8_t data[2 ];
78
86
data[0 ] = reg | 0x80 ;
79
87
data[1 ] = 0 ;
88
+
89
+ ESP32CPP::GPIO::low ((gpio_num_t )_chipSelectPin); // Select slave
80
90
m_spi.transfer (data, 2 );
91
+ ESP32CPP::GPIO::high ((gpio_num_t )_chipSelectPin); // Release slave
92
+
81
93
return data[1 ];
82
94
} // End PCD_ReadRegister()
83
95
@@ -97,6 +109,8 @@ void MFRC522::PCD_ReadRegister(PCD_Register reg, byte count, byte* values, byte
97
109
byte address = 0x80 | reg; // MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3.
98
110
byte index = 0 ; // Index in values array.
99
111
count--; // One read is performed outside of the loop
112
+
113
+ ESP32CPP::GPIO::low ((gpio_num_t )_chipSelectPin); // Select slave
100
114
m_spi.transferByte (address); // Tell MFRC522 which address we want to read
101
115
if (rxAlign) { // Only update bit positions rxAlign..7 in values[0]
102
116
// Create bit mask for bit positions rxAlign..7
@@ -112,6 +126,7 @@ void MFRC522::PCD_ReadRegister(PCD_Register reg, byte count, byte* values, byte
112
126
index ++;
113
127
}
114
128
values[index ] = m_spi.transferByte (0 ); // Read the final byte. Send 0 to stop reading.
129
+ ESP32CPP::GPIO::high ((gpio_num_t )_chipSelectPin); // Release slave
115
130
} // End PCD_ReadRegister()
116
131
117
132
@@ -181,6 +196,8 @@ MFRC522::StatusCode MFRC522::PCD_CalculateCRC(byte* data, byte length, byte* res
181
196
*/
182
197
void MFRC522::PCD_Init () {
183
198
// m_spi.setHost(VSPI_HOST);
199
+
200
+ ESP32CPP::GPIO::setOutput ((gpio_num_t )_chipSelectPin);
184
201
m_spi.init ();
185
202
186
203
bool hardReset = false ;
0 commit comments