AlejandroHuerta
Help communicating to a MAX31855 over hardware SPI
Hey everyone, I’m new to working with hardware and decided to learn by interfacing with some MAX31855 thermocouple sensors. I’ve successfully read temperatures from them using a software SPI, basically doing all of the CLK switching manually, and decided to give the hardware SPI a try but I’m unsure how to correctly interface with it.
I’m using the Circuits.SPI library. I’ve connected the MAX31855 pins according to this layout
DO → SPI_MISO
CLK → SPI_SCLK
CS → SPI_CE0
I’ve done Circuits.SPI.bus_name which returns ["spidev0.0", "spidev0.1"] I assume spidev0.0 corresponds to CE0, so I then proceeded to do SPI.open("spidev0.0", speed_hz: 5_000_000, delay_ns: 100) The opts I’ve added by looking at the MAX31855 datasheet (https://datasheets.maximintegrated.com/en/ds/MAX31855.pdf). I’m really not sure what to do from here, I’ve tried, as a test, SPI.transfer(ref, <<0>>) and it just returns {:ok, <<0>>}.
Any help would be appreciated as I’m pretty lost here since the example for Circuits.SPI is interfacing with an ADC.
Most Liked
ConnorRigby
I’ve never used this device myself, but couple things i notice here.. SPI usually requires more wires.
The main signals are
- MISO - Master In Slave Out
- MOSI - Master Out Slave In
- CLK - Clock
Optional signals will be
- CS - Cable Select
- CE - Chip Enable
And occasionally you will have
*INT - interups
As far as i know the Linux driver will not operate CS or CE themselves. You usually will need to use
Circuits.GPIO to toggle these. You will probably want to use spidev0.0, but it depends on the bus you used. If you are on Raspberry pi, the 0.0 bus is the top one. You will also want to look at your data sheet to see how to use CS or CE. (It looks like you have CS). CS needs to be set high or low for a SPI device to know that it is it’s turn to use the bus. if you have a CE, it tells the chip to be on or off. You will need to look at the datasheet to tell for sure. You also need to get another data line for MOSI (master out, slave in) this is the wire that will be transmitting data TO the device from Nerves
AlejandroHuerta
Just replying to say that I was able to use 2 sensors without issue, using the same method, with the second sensors CS pin connected to SPI_CS1. It seems like the Circuits.SPI library handles the CS/CE switching.
mmmries
Thanks for posting this! I’m still trying to wrap my head around how to talk over an SPI interface and found it helpful to read through your posts
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









