Trinket M0 + MCP41010 via SPI

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
GeorgeM987
 
Posts: 3
Joined: Thu Nov 25, 2021 8:12 am

Trinket M0 + MCP41010 via SPI

Post by GeorgeM987 »

Hi All,

Just started with the likes of trinket boards and CircuitPython in general and as a project I kind of want to migrate from the Arduino world would be controlling a digipot(i.e. MCP41010) with the Trinket M0 via SPI.

MCP41010:
https://docs.rs-online.com/e6b5/0900766b81380c8b.pdf

I guess want I'm really interested in, is if anyone had any experience trying to control a device via SPI with the Trinket M0?!
I've tried doing it manually and with the library with no luck:

Code: Select all

from adafruit_bus_device.spi_device import SPIDevice
Regards,
George M.

User avatar
GeorgeM987
 
Posts: 3
Joined: Thu Nov 25, 2021 8:12 am

Re: Trinket M0 + MCP41010 via SPI

Post by GeorgeM987 »

And this is the code for the manual setup:

Code: Select all

import board
import busio
import digitalio
from time import sleep


cs = digitalio.DigitalInOut(board.D2)
cs.direction = digitalio.Direction.OUTPUT

spi = busio.SPI(board.SCK, board.MOSI)

while not spi.try_lock():
    pass
try:
    spi.configure(baudrate=5000000, phase=0, polarity=0)
    cs.value = False
    result = bytearray(256)
    spi.write(result)
    sleep(1)
    cs.value = True
finally:
    spi.unlock()
...and with the library:

Code: Select all

import board
import busio
import digitalio
from time import sleep
from adafruit_bus_device.spi_device import SPIDevice

SIZE = [0, 128, 256] 

spi = busio.SPI(board.SCK, board.MOSI)
cs = digitalio.DigitalInOut(board.D2)
cs.direction = digitalio.Direction.OUTPUT
cs.value = False

device = SPIDevice(spi, cs, baudrate=100000, polarity=0, phase=0)


with device:
    spi.write(bytearray(256))
    sleep(1)
    cs.value = True
    

User avatar
GeorgeM987
 
Posts: 3
Joined: Thu Nov 25, 2021 8:12 am

Re: Trinket M0 + MCP41010 via SPI

Post by GeorgeM987 »

Also tried a software SPI version with no success:

Code: Select all

import board
import digitalio
from adafruit_bitbangio import adafruit_bitbangio as bitbangio
from time import sleep


SIZE = [0, 128, 256] 

SCLK_PIN = board.D4
MOSI_PIN = board.D3
CS_PIN = board.D2

cs = digitalio.DigitalInOut(CS_PIN)
cs.switch_to_output(value=True)
spi = bitbangio.SPI(SCLK_PIN, MOSI_PIN)
cs.value = 0

while not spi.try_lock():
    pass
spi.write([0xD0])
sleep(1)
spi.unlock()
cs.value = 1

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”