I am trying to get a voltage reading from a MAX1142BCAP+ with a Raspberry Pi 4B. I am just using the default circuit at the bottom of the datasheet and this code for SPI in Python:
#!/usr/bin/python # -*- coding: utf-8 -*- import spidev # ams or aquisition mode select can either be 0 or 1, 1 being long, 0 being short spi = spidev.SpiDev() def adc_spi(ams): spi.open(0, 0) spi.max_speed_hz = 500000 spi.mode = 0b00 spi.writebytes2([0b11100000]) pressure = spi.readbytes(6) print(pressure) spi.close() adc_spi(0)
When I run this code I get these outputs in console without changing the voltage on Ain.
pi@gauge:~ $ python3 adc1.py [40, 0, 0, 0, 0, 0] pi@gauge:~ $ python3 adc1.py [64, 0, 0, 0, 0, 0] pi@gauge:~ $ python3 adc1.py [64, 0, 0, 0, 0, 0] pi@gauge:~ $ python3 adc1.py [80, 0, 0, 0, 0, 0] pi@gauge:~ $ python3 adc1.py [80, 0, 0, 0, 0, 0]
When I analyze the digital outputs with a logic analyzer I get outputs like these:
These outputs change each time I run this but the values don't match the voltage I give Ain. These outputs don't match what the datasheet says I should get, either.
Some things I think the problem could be:
- The fact I am not resetting between runs maybe.
- The SPI mode although I have read the datasheet quite a few times by now.
Other then that I have no clue.
I have reconnected everything several times and tested each of my jumpers. I have tried another chip just in case this one was broken. I know this is a noob question this is my first time using SPI any insight you could give for trouble shooting this would be appreciated. Or if you think its probably a lost cause and I should just buy a I2C ADC that would be helpful too.