SWI with Atmel Crypto ICs
We highly encourage everyone to use our new Python package which is packed with features. This library is still supported, but is not recommended for new design.
The following python script demonstrates how to use the SWI host Nova functionality of the Binho Multi-Protocol USB Host Adapter with the Atmel (now Microchip) ATSHA204A CryptoAuthentication IC. Communication with other devices from this family will be strikingly similar.
1
from binhoHostAdapter import binhoHostAdapter
2
from binhoHostAdapter import binhoUtilities
3
4
# change this to your COM port
5
binhoTesterCommPort = 'COM22'
6
7
# create the binhoHostAdapter object
8
binhoTester = binhoHostAdapter.binhoHostAdapter(binhoTesterCommPort)
9
10
print("Connecting to binho host adapter tester...")
11
print()
12
13
swiIndex = 0
14
15
binhoTester.setLEDColor('CYAN')
16
17
binhoTester.setOperationMode(0, 'SWI')
18
19
binhoTester.beginSWI(swiIndex, 0, True)
20
21
# Begin Wake/ID Example
22
binhoTester.sendTokenSWI(swiIndex, "WAKE")
23
24
print(binhoTester.receiveBytesSWI(swiIndex, 4))
25
26
# Begin Serial Number Example
27
binhoTester.setPacketOpCodeSWI(swiIndex, 0x02)
28
binhoTester.setPacketParam1SWI(swiIndex, 0x00)
29
binhoTester.setPacketParam2SWI(swiIndex, 0x0000)
30
31
binhoTester.sendPacketSWI(swiIndex)
32
33
print(binhoTester.receiveBytesSWI(swiIndex, 7))
34
35
binhoTester.setPacketOpCodeSWI(swiIndex, 0x02)
36
binhoTester.setPacketParam1SWI(swiIndex, 0x00)
37
binhoTester.setPacketParam2SWI(swiIndex, 0x0002)
38
39
binhoTester.sendPacketSWI(swiIndex)
40
41
print(binhoTester.receiveBytesSWI(swiIndex, 7))
42
43
binhoTester.setPacketOpCodeSWI(swiIndex, 0x02)
44
binhoTester.setPacketParam1SWI(swiIndex, 0x00)
45
binhoTester.setPacketParam2SWI(swiIndex, 0x0003)
46
47
binhoTester.sendPacketSWI(swiIndex)
48
49
print(binhoTester.receiveBytesSWI(swiIndex, 7))
50
51
# Begin MAC Challenge Example
52
53
print('clearing buffer')
54
print(binhoTester.clearPacketSWI(0))
55
56
data = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF]
57
58
print(binhoTester.writeToBuffer(0, 0, data))
59
60
print(binhoTester.setPacketOpCodeSWI(swiIndex, 0x08))
61
print(binhoTester.setPacketParam1SWI(swiIndex, 0x00))
62
print(binhoTester.setPacketParam2SWI(swiIndex, 0x0000))
63
64
print(binhoTester.setPacketDataFromBufferSWI(swiIndex, 32, "BUF0"))
65
66
print(binhoTester.sendPacketSWI(swiIndex))
67
68
#these first two will return NG because not enough time passed for the execution of the above command
69
binhoTester.receiveBytesSWI(swiIndex, 0x23)
70
binhoTester.receiveBytesSWI(swiIndex, 0x23)
71
72
# this one will actually return the response we are looking for
73
print(binhoTester.receiveBytesSWI(swiIndex, 0x23))
74
75
print(binhoTester.setPacketOpCodeSWI(swiIndex, 0x08))
76
print(binhoTester.setPacketParam1SWI(swiIndex, 0x00))
77
print(binhoTester.setPacketParam2SWI(swiIndex, 0x0000))
78
79
binhoTester.setPacketDataSWI(swiIndex, 0, 0x00)
80
binhoTester.setPacketDataSWI(swiIndex, 1, 0x11)
81
binhoTester.setPacketDataSWI(swiIndex, 2, 0x22)
82
binhoTester.setPacketDataSWI(swiIndex, 3, 0x33)
83
binhoTester.setPacketDataSWI(swiIndex, 4, 0x44)
84
binhoTester.setPacketDataSWI(swiIndex, 5, 0x55)
85
binhoTester.setPacketDataSWI(swiIndex, 6, 0x66)
86
binhoTester.setPacketDataSWI(swiIndex, 7, 0x77)
87
binhoTester.setPacketDataSWI(swiIndex, 8, 0x88)
88
binhoTester.setPacketDataSWI(swiIndex, 9, 0x99)
89
binhoTester.setPacketDataSWI(swiIndex, 10, 0xAA)
90
binhoTester.setPacketDataSWI(swiIndex, 11, 0xBB)
91
binhoTester.setPacketDataSWI(swiIndex, 12, 0xCC)
92
binhoTester.setPacketDataSWI(swiIndex, 13, 0xDD)
93
binhoTester.setPacketDataSWI(swiIndex, 14, 0xEE)
94
binhoTester.setPacketDataSWI(swiIndex, 15, 0xFF)
95
binhoTester.setPacketDataSWI(swiIndex, 16, 0x00)
96
binhoTester.setPacketDataSWI(swiIndex, 17, 0x11)
97
binhoTester.setPacketDataSWI(swiIndex, 18, 0x22)
98
binhoTester.setPacketDataSWI(swiIndex, 19, 0x33)
99
binhoTester.setPacketDataSWI(swiIndex, 20, 0x44)
100
binhoTester.setPacketDataSWI(swiIndex, 21, 0x55)
101
binhoTester.setPacketDataSWI(swiIndex, 22, 0x66)
102
binhoTester.setPacketDataSWI(swiIndex, 23, 0x77)
103
binhoTester.setPacketDataSWI(swiIndex, 24, 0x88)
104
binhoTester.setPacketDataSWI(swiIndex, 25, 0x99)
105
binhoTester.setPacketDataSWI(swiIndex, 26, 0xAA)
106
binhoTester.setPacketDataSWI(swiIndex, 27, 0xBB)
107
binhoTester.setPacketDataSWI(swiIndex, 28, 0xCC)
108
binhoTester.setPacketDataSWI(swiIndex, 29, 0xDD)
109
binhoTester.setPacketDataSWI(swiIndex, 30, 0xEE)
110
binhoTester.setPacketDataSWI(swiIndex, 31, 0xFF)
111
112
print(binhoTester.sendPacketSWI(swiIndex))
113
114
#these first two will return NG because not enough time passed for the execution of the above command
115
binhoTester.receiveBytesSWI(swiIndex, 0x23)
116
binhoTester.receiveBytesSWI(swiIndex, 0x23)
117
118
# this one will actually return the response we are looking for
119
print(binhoTester.receiveBytesSWI(swiIndex, 0x23))
120
121
binhoTester.close()
Copied!
A special shout out to our friends at Sparkfun who produced a similar example above for their ATSHA204 Arduino Library many, many moons ago. This demo is built to match their example.
Last modified 8mo ago
Copy link