Skip to content

Commit 2921b43

Browse files
committed
Added rough-and-ready Gain control. Not certain if it has an effect
1 parent 1c401ec commit 2921b43

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

mfrc522.py

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
class MFRC522:
77

8+
GAIN_REG = 0x26
9+
MAX_GAIN = 0x07
10+
811
OK = 0
912
NOTAGERR = 1
1013
ERR = 2
@@ -189,8 +192,10 @@ def init(self):
189192
self._wreg(0x2C, 0)
190193
self._wreg(0x15, 0x40)
191194
self._wreg(0x11, 0x3D)
195+
self.set_gain(self.MAX_GAIN)
192196
self.antenna_on()
193197

198+
194199
def reset(self):
195200
self._wreg(0x01, 0x0F)
196201

@@ -258,6 +263,13 @@ def halt_a(self):
258263
def stop_crypto1(self):
259264
self._cflags(0x08, 0x08)
260265

266+
def set_gain(self, gain):
267+
assert gain <= self.MAX_GAIN
268+
# clear bits
269+
self._cflags(self.GAIN_REG, 0x07<< 4)
270+
# set bits according to gain
271+
self._sflags(self.GAIN_REG, gain << 4)
272+
261273
def read(self, addr, into = None):
262274
buf = self.regBuf
263275
buf[0]=0x30

0 commit comments

Comments
 (0)