Reading only zero value from ADC board, why?
You mentioned that you already tested serial loopback. So I studied you program to see how you send and received bytes. I found one thing wierd - you setup GPIO MOSI, and MISO to output mode, input mode and so on. But I never did that, because the serial module will take care of that. You might like to read my loopback program below and run it to see how I don't need to set input/output mode but still can do loopback.
You might also like to refer to my answer to the following question.
How to check if SPI is enabled and functional on Raspi 3b+?
And how come your program takes care of MISO but forgets MOSI?
Now that we have checked that the Rpi SPI can do loopback, we can connect the CLK, MOSI, MISO wires to LPT1867 and talk to it.
Earlier I recommended you to read the post about how to red the scary timing diagram of MCP3008. Actually there are only three big steps: (1) write byte to tell ADC which channel, single or differential, etc. (For LPT1867, you make also need to wake it up. But the basic pattern is more or less the same. ), (2) Read the binary results at the same time (yes, for SPI, you write and read at the same time) (3) Convert binary result to decimal for human eyes to read. And day is done.
Now you need to compare your LPT1867 with the simpler MCP3008, to know the difference.
LPT1867 is similar to MCP3208, though more complicated, eg, 16-bit resolution compared to MCP3208's 12 bit, polarity selection, sleep mode bit etc. The start and read ADC result is basically the same. You may like check out MCP3208 timing diagram below. And you can google for Rp python MCP3208 programs and 'translate' it to LPT1867.
I forgot to remind you the following:
The loopback test is only a preliminary test, to make sure that the SPI thing is more or less setup OK. However two important checkouts
are missing: (a) CS0 and CS1 are not tested. You need a scope to see
the CSn waveforms are more or less noise free, and not too
I vaguely remember that you set SPI to 5MHz. I almost always set a very low speed for testing, eg. UART 96008N1, I2C 100kHz, SPI 100kHz. Low speed usually has less problems,
Sometimes for SPI I set to 400kHz, but almost never higher. I am
doing hobbyist Micky Mouse projects, and I used to have a low
bandwidth scope which cannot handle industrial communication speeds.
I am revising my MCP3008/MCP3201/MCP3208 ADT programs. You might like to see what I am doing in the following post (from update 2019may03hkt1056)
Calibrate PH-4502C pH meter
You can see that I only once use the lower level command xfer(). Once debugged, I never look back and forget it for good (Low level things are trouble makers!). Similarly I also debugged my higher level programs write/read one/two/three bytes. Again, once debugged I never look back, or make it a python module so that I won't carelessly mess them up.
With the write/read functions, then I move on to write/read two/three bytes to ADC, and everything boils down to this two big steps, and talking at high level, which is concise and not so error prone ...
Now I am trying to do one MCP3208 ADC by doing the following:
Write 3 bytes to MCP3208, first byte is the command byte for MCP3208, second and third byte are dummy bytes.
At the same time, read 3 bytes from MCP3208. These read 3 bytes contains the raw data. I need to extract the raw data and translate it into decimal values.
The LPT1867 seems similar. You also write 3 bytes and read back 3 bytes which contains raw data results.
/ to continue, ...
Python repeat send and loopback program
# spi_test05 tlfong01 2019apr07hkt2043 ***
# Computer = Rpi3B+
# Linux = $ hostnamectl = raspberrypi Raspbian GNU/Linux 9 (stretch) Linux 4.14.34-v7+ arm
# Python = >>> sys.version = 3.5.3 Jan 19 2017
# Test 1 - repeatSendByte() - SPI port repeatedly send out single bytes.
# Function - Repeat many times sending a byte, pause after each byte.
# Test 2 - loopBackTest() - SPI port send and receive one byte.
# Function - Send one byte to MSOI and read it back from MISO.
# Setup - Connet MOSI pin to MISO pin to form a loop.
from time import sleep
spiPort0 = spidev.SpiDev()
spiPort0.max_speed_hz = 100000
def spiSendRecvOneByte(spiPort, sendByte):
sendByteArray = [sendByte]
recvByteArray = spiPort.xfer(sendByteArray)
def repeatSendOneByte(spiPort, sendByte, pauseTimeBetweenBytes, repeatCount):
for i in range(repeatCount):
def loopBackOneByte(spiPort, sendByte):
recvByteArray = spiSendRecvOneByte(spiPort, sendByte)
recvByte = recvByteArray
print(' sendByte = ', hex(sendByte))
print(' recvByte = ', hex(recvByte))
repeatSendOneByte(spiPort0, 0x5b, 0.0001, 20000000)
''' Smple output tlfong 01 2019apr07hkt2047
sendByte = 0x5b
recvByte = 0x5b
# *** End ***