0

Question, SPI with CircuitPython
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Question, SPI with CircuitPython

by rrii on Thu Sep 13, 2018 7:34 am

I wanted to test the SPI SRAM. With CircuitPython.
But I could not make it work.
(When directly connecting MOSI and MISO, it was confirmed that SPI communication is operating normally.)

I suspect SPI SRAM breakdown, I thought so, we did a similar test with micro: bit.
The result was behavior as expected.


My code is as follows.
I need your advice! Thank you.


micro:bit microPython
Code: Select all | TOGGLE FULL SIZE
import microbit as m
m.spi.init(sclk=pin13,mosi=pin15,miso=pin14)

m.pin1.write_digital(1) #CS high

m.pin1.write_digital(0) #CS low
m.spi.write(bytes([2,0,0,0x55])) # write data 0x55 to address 0x0000
m.pin1.write_digital(1)

m.pin1.write_digital(0)
m.spi.write(bytes([3,0,0])) #set read address 0x0000
data = m.spi.read(1) #read data, 1byte
print(data)
m.pin1.write_digital(1)


Adafruit CircuitPython 2.3.1 on 2018-05-07; Adafruit Feather M0 Adalogger with samd21g18
Code: Select all | TOGGLE FULL SIZE
import busio,board,digitalio
cs = digitalio.DigitalInOut(board.D5)
cs.switch_to_output()
cs.value = True # CS High

spi = busio.SPI(clock=board.SCK,MOSI=board.MOSI,MISO=board.MISO)
while not spi.try_lock():
   pass

cs.value = False
spi.write(bytes([2,0,0,0x55])) #write data
cs.value = True

#read test 1
res = bytearray(1)
cs.value = False
spi.write(bytes([3,0,0]))
spi.readinto(res)
print(res)
cs.value = True

#read test 2
res2 = bytearray([3,0,0,0])
spi.write_readinto(res2,res2,out_end=2,in_start=2)
print(res2)
cs.value = True

rrii
 
Posts: 9
Joined: Tue Jan 10, 2017 1:39 pm

Re: Question, SPI with CircuitPython

by adafruit_support_carter on Thu Sep 13, 2018 1:39 pm

Post a photo showing your Feather setup with everything connected.

adafruit_support_carter
 
Posts: 6208
Joined: Tue Nov 29, 2016 2:45 pm

Re: Question, SPI with CircuitPython

by rrii on Thu Sep 13, 2018 2:42 pm

Okay, I took a picture.
But it is hard to understand.
Wiring is. . .

Adalogger / spi sram(23k256)
SCK - 6 SCK
MOSI - 5 SI
MISO - 2 SO
D5 - 1 CS
NA - 3 NC
GND - 4 GND -> BAT(-)
3V3 - 8 VCC
NA - 7 HOLD -> BAT(+)

and... I tried with LEDs that MOSI and D5 are output.
Attachments
adalogger.jpg
adalogger.jpg (52.61 KiB) Viewed 46 times

rrii
 
Posts: 9
Joined: Tue Jan 10, 2017 1:39 pm

Re: Question, SPI with CircuitPython

by adafruit_support_carter on Thu Sep 13, 2018 7:37 pm

That generally seems OK. Do you have some other SPI devices you could use to verify that the basic SPI comms are working on the Feather?

The SPI bus is also used by the SD card on the Adalogger, but you should be able to share it like your are trying to do - with a separate CS pin for the external device.

What are the additional connections to battery for?
GND - 4 GND -> BAT(-)
3V3 - 8 VCC
NA - 7 HOLD -> BAT(+)

adafruit_support_carter
 
Posts: 6208
Joined: Tue Nov 29, 2016 2:45 pm

Re: Question, SPI with CircuitPython

by rrii on Fri Sep 14, 2018 5:54 am

I wanted to try holding the memory with SPI SRAM battery, with CircuitPython.
That which is connected to the SPI SRAM is, as you can see, is a coin battery.
Memory holding operation of SPI SRAM was confirmed with micro: bit.


I can read and write SD card with Feather, I am also confirming that write_readinto works by connecting MOSI and MISO directly.

I have several other SPI devices, but it seems that it will take time to prepare the test code.
I heard that it is necessary for me to be patient.

rrii
 
Posts: 9
Joined: Tue Jan 10, 2017 1:39 pm

Re: Question, SPI with CircuitPython

by rrii on Fri Sep 14, 2018 9:13 am

Hello.
After that, I reviewed the wiring and tried accessing SPI SRAM on another board.
I tried to tell if baudrate is too fast.

From the conclusion.
SPI SRAM worked in CircuitPython.

I could not pursue what I could not do, but it working anyway.
The intended memory backup also works well.

Because I am a bit tired, I want to pursue another opportunity again.
I also found that my oscilloscope is not useful for SAMD at all (speed does not catch up). It was a good study.

Thank you.

rrii
 
Posts: 9
Joined: Tue Jan 10, 2017 1:39 pm

Re: Question, SPI with CircuitPython

by adafruit_support_carter on Fri Sep 14, 2018 11:38 am

Sounds like maybe it was just a wiring issue on the breadboard. That can happen. Glad you got it working.

adafruit_support_carter
 
Posts: 6208
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.