Skip to content

Commit 01e672f

Browse files
committed
spi: bitbang tests use 3 bytes addresses for the SRAM
1 parent 726de70 commit 01e672f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/scala/spi/SerialSpiTest.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ class SerialSpiTest(id: Int, portName: String = "/dev/tty.usbserial-210292B40860
137137
csHigh()
138138
}
139139

140+
// TODO: is this really the way to do it? Anas hae a different solution, sending 3 bytes of address.
140141
def readSram(addr: Int) = {
141142
csLow()
142143
writeByte(0x03)
144+
writeByte((addr >> 16) & 0xff)
143145
writeByte((addr >> 8) & 0xff)
144146
writeByte(addr & 0xff)
145147
val v = readByte()
@@ -148,6 +150,16 @@ class SerialSpiTest(id: Int, portName: String = "/dev/tty.usbserial-210292B40860
148150
v
149151
}
150152

153+
def writeSram(addr: Int, data: Int) = {
154+
csLow()
155+
writeByte(0x02)
156+
writeByte((addr >> 16) & 0xff)
157+
writeByte((addr >> 8) & 0xff)
158+
writeByte(addr & 0xff)
159+
writeByte(data)
160+
csHigh()
161+
}
162+
151163
def writeCmd(v: Int) = {
152164
csLow()
153165
writeByte(v)
@@ -235,4 +247,10 @@ object SerialSpiTest extends App {
235247
print(spi.writeReadSerial(spi.setCmd(4))) // all CS high
236248
spi.out.close()
237249
spi.port.closePort()
250+
251+
252+
println("SRAM test")
253+
val sram = new SerialSpiTest(2) // SRAM
254+
sram.writeSram(0, 0x55)
255+
sram.readSram(0)
238256
}

0 commit comments

Comments
 (0)