Skip to content

Commit ca4dd38

Browse files
committed
read macc addr
1 parent 9dce627 commit ca4dd38

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

adafruit_esp32spi.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class ESP_SPIcontrol:
88
GET_CONN_STATUS_CMD = const(0x20)
99
GET_FW_VERSION_CMD = const(0x37)
10+
GET_MACADDR_CMD = const(0x22)
1011
START_CMD = const(0xE0)
1112
END_CMD = const(0xEE)
1213
ERR_CMD = const(0xEF)
@@ -72,18 +73,23 @@ def wait_for_slave_select(self):
7273

7374

7475
def send_command(self, cmd, params=None):
75-
num_params = 0 # default to no params
76-
if params:
77-
num_params = len(params)
78-
packet = bytearray(4+num_params)
79-
packet[0] = START_CMD
80-
packet[1] = cmd & ~REPLY_FLAG
81-
packet[2] = num_params
76+
if not params:
77+
params = []
78+
packet = []
79+
packet.append(START_CMD)
80+
packet.append(cmd & ~REPLY_FLAG)
81+
packet.append(len(params))
8282

8383
# handle parameters here
84-
85-
packet[3] = END_CMD
86-
self._spi.write(packet)
84+
for param in params:
85+
packet.append(len(param))
86+
packet += (param)
87+
88+
packet.append(END_CMD)
89+
print("packet len:", len(packet))
90+
while len(packet) % 4 != 0:
91+
packet.append(0xFF)
92+
self._spi.write(bytearray(packet))
8793
print("Wrote: ", [hex(b) for b in packet])
8894

8995
def get_param(self):
@@ -146,3 +152,15 @@ def get_firmware_version(self):
146152
resp = self.wait_response_cmd(GET_FW_VERSION_CMD, 1)
147153
self.slave_deselect()
148154
return ''.join([chr(c) for c in resp[0]])
155+
156+
def get_MAC(self):
157+
print("MAC address")
158+
self.wait_for_slave_select()
159+
self.send_command(GET_MACADDR_CMD, [[0xFF]])
160+
self.slave_deselect()
161+
162+
self.wait_for_slave_ready()
163+
self.spi_slave_select()
164+
resp = self.wait_response_cmd(GET_MACADDR_CMD, 1)
165+
self.slave_deselect()
166+
return resp[0]

0 commit comments

Comments
 (0)