Pi model: Pi 3 A+
Os: Raspbian GNU/Linux 9 (stretch) <- it's stretch lite
SPI: On
Loop back test:
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D | ......@....�..................�.
RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D | ......@....�..................�.
Code:
package main
import (
"log"
rpio "github.com/stianeikeland/go-rpio"
"golang.org/x/exp/io/spi"
)
const (
mosi = rpio.Pin(10) //physical 19
miso = rpio.Pin(9) //physical 21
clk = rpio.Pin(11) //physical 23
ce0 = rpio.Pin(8) //physical 24
ce1 = rpio.Pin(7) //physical 26
)
func main() {
if err := rpio.Open(); err != nil {
log.Println(err)
return
}
defer rpio.Close()
pins := []rpio.Pin{mosi, miso, clk, ce0, ce1}
for _, pin := range pins {
pin.Low()
}
dev, err := spi.Open(&spi.Devfs{
Dev: "/dev/spidev0.0", Mode: spi.Mode0, MaxSpeed: 500000})
if err != nil {
log.Println("SPI error", err)
log.Println("Did you forget to enable SPI interface?")
return
}
defer dev.Close()
out := []byte{1, 8 << 4, 0}
in := make([]byte, 3)
if err := dev.Tx(out, in); err != nil {
log.Println("SPI read/write error. ", err)
return
}
code := int(in[1]&3)<<8 + int(in[2])
log.Println(code)
}
Voltage on ch 0 is 1.49, no conversion done by the chip. Returns 0 on ch 0.
Checked Vdd and Vref with multimeter using the analog and digital grounds.
Voltage reads 3.3
A year and a half ago the setup above worked with a pizero on jessie lite.
I tested 3 different mcp3008 chips with the same result.
Also tested on a pizero, no success.
Where is my mistake?