Uncategorized

ADS1256 Programming Notes V0.3

6:12pm Wed. 2/26/2020

3:25pm Wed. 2/26/2020

ADS1256 ADC Programming Notes V0.4

penzu link: https://penzu.com/p/d0716f85


Contents

(1) References

(2) Appendices

Appendix B – Harry Singh ADS1256 Programming Notes V0.3

Appendix A – ADXL345 Programming Notes V0.3


References

ADS1256 Datasheet – TI

[ADS1256] Measuring Single-Ended 0- to 5-V Signals with Differential Delta-Sigma ADCs Application Report – TI 2015may

[ADS1256] How delta-sigma ADCs work, Part 1 – TI

How can ADS1256 Read Negative Values?

How can ADS1256 Read Full Scale Values?

ADS1256 Python Libraries

C library for Broadcom BCM 2835 [GPIO] as used in Raspberry Pi [v1.59 2012 26 pin Rpi 2]

WaveShare ADS1250 ADC Module Tutorial

WaveShare ADS1250 ADC Module Schematic

Waveshare/High-Precision-AD-DA-Board Python 3 Demo Program

AliExpress ADS1256 24 Bit ADC Modules

AliExpress ADS1256IDB ADC Module – US$30


5:36pm Wed. 2/26/2020

Appendix B – Harry Singh ADS1256 Programming Notes V0.3

ADS1256 Program by Harry Singh

Wed. 2/26/2020

by Harry singh

import config
import RPi.GPIO as GPIO
ScanMode = 0
# gain channel
ADS1256_GAIN_E = {‘ADS1256_GAIN_1’ : 0, # GAIN   1
‘ADS1256_GAIN_2’ : 1,    # GAIN   2
‘ADS1256_GAIN_4’ : 2,    # GAIN   4
‘ADS1256_GAIN_8’ : 3,    # GAIN   8
‘ADS1256_GAIN_16’ : 4,# GAIN  16
‘ADS1256_GAIN_32’ : 5,# GAIN  32
‘ADS1256_GAIN_64’ : 6,# GAIN  64
}

# data rate
ADS1256_DRATE_E = {‘ADS1256_30000SPS’ : 0xF0, # reset the default values
‘ADS1256_15000SPS’ : 0xE0,
‘ADS1256_7500SPS’ : 0xD0,
‘ADS1256_3750SPS’ : 0xC0,
‘ADS1256_2000SPS’ : 0xB0,
‘ADS1256_1000SPS’ : 0xA1,
‘ADS1256_500SPS’ : 0x92,
‘ADS1256_100SPS’ : 0x82,
‘ADS1256_60SPS’ : 0x72,
‘ADS1256_50SPS’ : 0x63,
‘ADS1256_30SPS’ : 0x53,
‘ADS1256_25SPS’ : 0x43,
‘ADS1256_15SPS’ : 0x33,
‘ADS1256_10SPS’ : 0x20,
‘ADS1256_5SPS’ : 0x13,
‘ADS1256_2d5SPS’ : 0x03
}

# registration definition
REG_E = {‘REG_STATUS’ : 0,  # x1H
‘REG_MUX’ : 1,     # 01H
‘REG_ADCON’ : 2,   # 20H
‘REG_DRATE’ : 3,   # F0H
‘REG_IO’ : 4,      # E0H
‘REG_OFC0’ : 5,    # xxH
‘REG_OFC1’ : 6,    # xxH
‘REG_OFC2’ : 7,    # xxH
‘REG_FSC0’ : 8,    # xxH
‘REG_FSC1’ : 9,    # xxH
‘REG_FSC2’ : 10,   # xxH
}

# command definition
CMD = {‘CMD_WAKEUP’ : 0x00,     # Completes SYNC and Exits Standby Mode 0000  0000 (00h)
‘CMD_RDATA’ : 0x01,      # Read Data 0000  0001 (01h)
‘CMD_RDATAC’ : 0x03,     # Read Data Continuously 0000   0011 (03h)
‘CMD_SDATAC’ : 0x0F,     # Stop Read Data Continuously 0000   1111 (0Fh)
‘CMD_RREG’ : 0x10,       # Read from REG rrr 0001 rrrr (1xh)
‘CMD_WREG’ : 0x50,       # Write to REG rrr 0101 rrrr (5xh)
‘CMD_SELFCAL’ : 0xF0,    # Offset and Gain Self-Calibration 1111    0000 (F0h)
‘CMD_SELFOCAL’ : 0xF1,   # Offset Self-Calibration 1111    0001 (F1h)
‘CMD_SELFGCAL’ : 0xF2,   # Gain Self-Calibration 1111    0010 (F2h)
‘CMD_SYSOCAL’ : 0xF3,    # System Offset Calibration 1111   0011 (F3h)
‘CMD_SYSGCAL’ : 0xF4,    # System Gain Calibration 1111    0100 (F4h)
‘CMD_SYNC’ : 0xFC,       # Synchronize the A/D Conversion 1111   1100 (FCh)
‘CMD_STANDBY’ : 0xFD,    # Begin Standby Mode 1111   1101 (FDh)
‘CMD_RESET’ : 0xFE,      # Reset to Power-Up Values 1111   1110 (FEh)
}

class ADS1256:
def __init__(self):
self.rst_pin = config.RST_PIN
self.cs_pin = config.CS_PIN
self.drdy_pin = config.DRDY_PIN

# Hardware reset
def ADS1256_reset(self):
config.digital_write(self.rst_pin, GPIO.HIGH)
config.delay_ms(200)
config.digital_write(self.rst_pin, GPIO.LOW)
config.delay_ms(200)
config.digital_write(self.rst_pin, GPIO.HIGH)

def ADS1256_WriteCmd(self, reg):
config.digital_write(self.cs_pin, GPIO.LOW)#cs  0
config.spi_writebyte([reg])
config.digital_write(self.cs_pin, GPIO.HIGH)#cs 1

def ADS1256_WriteReg(self, reg, data):
config.digital_write(self.cs_pin, GPIO.LOW)#cs  0
config.spi_writebyte([CMD[‘CMD_WREG’] | reg, 0x00, data])
config.digital_write(self.cs_pin, GPIO.HIGH)#cs 1

def ADS1256_Read_data(self, reg):
config.digital_write(self.cs_pin, GPIO.LOW)#cs  0
config.spi_writebyte([CMD[‘CMD_RREG’] | reg, 0x00])
data = config.spi_readbytes(1)
config.digital_write(self.cs_pin, GPIO.HIGH)#cs 1

return data

def ADS1256_WaitDRDY(self):
for i in range(0,400000,1):
if(config.digital_read(self.drdy_pin) == 0):

break
if(i >= 400000):
print (“Time Out …\r\n”)

def ADS1256_ReadChipID(self):
self.ADS1256_WaitDRDY()
id = self.ADS1256_Read_data(REG_E[‘REG_STATUS’])
id = id[0] >> 4
# print ‘ID’,id
return id

#The configuration parameters of ADC, gain and data rate
def ADS1256_ConfigADC(self, gain, drate):
self.ADS1256_WaitDRDY()
buf = [0,0,0,0,0,0,0,0]
buf[0] = (0<<3) | (1<<2) | (0<<1)
buf[1] = 0x08
buf[2] = (0<<5) | (0<<3) | (gain<<0)
buf[3] = drate

config.digital_write(self.cs_pin, GPIO.LOW)#cs  0
config.spi_writebyte([CMD[‘CMD_WREG’] | 0, 0x03])
config.spi_writebyte(buf)

config.digital_write(self.cs_pin, GPIO.HIGH)#cs 1
config.delay_ms(1)

def ADS1256_SetChannal(self, Channal):
if Channal > 7:
return 0
self.ADS1256_WriteReg(REG_E[‘REG_MUX’], (Channal<<4) | (1<<3))

def ADS1256_SetDiffChannal(self, Channal):
if Channal == 0:
self.ADS1256_WriteReg(REG_E[‘REG_MUX’     ], (0 << 4) | 1)     #DiffChannal  AIN0-AIN1
elif Channal == 1:
self.ADS1256_WriteReg(REG_E[‘REG_MUX’], (2 << 4) | 3)     #DiffChannal   AIN2-AIN3
elif Channal == 2:
self.ADS1256_WriteReg(REG_E[‘REG_MUX’], (4 << 4) | 5)     #DiffChannal    AIN4-AIN5
elif Channal == 3:
self.ADS1256_WriteReg(REG_E[‘REG_MUX’], (6 << 4) | 7)     #DiffChannal   AIN6-AIN7

def ADS1256_SetMode(self, Mode):
ScanMode = Mode

def ADS1256_init(self):
if (config.module_init() != 0):
return -1
self.ADS1256_reset()
id = self.ADS1256_ReadChipID()
if id == 3 :
print(“ID Read success  “)
else:
print(“ID Read failed   “)
return -1
self.ADS1256_ConfigADC(ADS1256_GAIN_E[‘ADS1256_GAIN_1’], ADS1256_DRATE_E[‘ADS1256_30000SPS’])
return 0

def ADS1256_Read_ADC_Data(self): #READING DATA
self.ADS1256_WaitDRDY()
config.digital_write(self.cs_pin, GPIO.LOW)#cs  0
config.spi_writebyte([CMD[‘CMD_RDATA’]])
# config.delay_ms(10)

buf = config.spi_readbytes(3)
config.digital_write(self.cs_pin, GPIO.HIGH)#cs 1
read =  (buf[0]<<16) & 0xff0000
read |= (buf[1]<<8) & 0xff00
read |= (buf[2]) & 0xff
twoscompl =(read & (1<<23) != 0) #TWOS COMPLIMENT
if twoscompl:
read&=0x7fffff
read-= (1<< 23)
#read=~read
#print(hex(buf[0]),hex(buf[1]),hex(buf[2]),read*5.0/0x7fffff)
print(read*5.0/0x7fffff)

if (read & 0x800000):
read &= 0xF000000

return read

def ADS1256_GetChannalValue(self, Channel):
if(ScanMode == 0):# 0  Single-ended input  8 channel1 Differential input  4 channe
if(Channel>=8):
return 0
self.ADS1256_SetChannal(Channel)
self.ADS1256_WriteCmd(CMD[‘CMD_SYNC’])
# config.delay_ms(10)
self.ADS1256_WriteCmd(CMD[‘CMD_WAKEUP’])
# config.delay_ms(200)
Value = self.ADS1256_Read_ADC_Data()
else:
if(Channel>=4):
return 0
self.ADS1256_SetDiffChannal(Channel)
self.ADS1256_WriteCmd(CMD[‘CMD_SYNC’])
# config.delay_ms(10)
self.ADS1256_WriteCmd(CMD[‘CMD_WAKEUP’])
# config.delay_ms(10)
Value = self.ADS1256_Read_ADC_Data()
return Value

def ADS1256_GetAll(self):
ADC_Value = [0,0,0,0,0,0,0,0]
for i in range(0,8,1):
ADC_Value[i] = self.ADS1256_GetChannalValue(i)
return ADC_Value
### END OF FILE ###



Appendix A – ADXL345 Programming Notes V0.3


ADXL345 Config Functions

def generalConfig(deviceNickName, generalConfigByteName):
adxl345WriteReadRegOneByte(deviceNickName, ‘DataFormatReg’, generalConfigByteName)
moduleDictDict[‘Adxl345’][deviceNickName][‘CurrentConfigName’] = generalConfigByteName
return

def interruptConfig(deviceInckName, interruptConfigByteName):
adxl345WriteReadRegOneByte(deviceInckName, ‘InterruptConfigReg’,     interruptConfigByteName)

    return


Function to convert variable number of byes 2’s Compliment to signed 

def convertTwoCompNumToDecNum(twoCompNum, numBytes):
twoCompNumStr = bin(twoCompNum)
val = int(twoCompNumStr, numBytes)
b = val.to_bytes(numBytes, byteorder=sys.byteorder, signed = False)
decNum = int.from_bytes(b, byteorder = sys.byteorder, signed = True)
return decNum


ADXL345 Test Functions

def checkDeviceId(deviceName):
readByte = adxl345ReadRegOneByte(deviceName, ‘DevIdReg’)
fprint.printTitleOneByteNum(‘DevIdRegister Contests =’, fprint.indentFormat640,     readByte)
return

def adxl345Test(deviceNickName, configByteName):
fprint.printBeginExecFunction()
checkDeviceId(deviceNickName)
generalConfig(deviceNickName, configByteName)
interruptConfig(deviceNickName, ‘InterruptDataReadyDisable’)
measurementResultsList = getRepeatMeasurementResultsList(deviceNickName, 4, 0.01)
printMeasurementResults(deviceNickName, measurementResultsList)
fprint.printEndExecFunction()
return


Test Results 

********************************************************************************

     Begin Execute Function adxl345Test  2019-12-30 22:37                            

       Function Name                           = adxl345Test
DevIdRegister Contests =                = 0x00
ADXL345 Device Name                     = Jacky
BusName                                 = SpiBus00
ConfigName                              = DefaultConfig16G13BitSelfTest

———————————————————————-
Time                          =  X value   Y Value   Z Value
———————————————————————-
0   2019-12-30 22:37:06.731070          =      128     -2053     10469
1   2019-12-30 22:37:06.745782          =    -8467     -9289     10469
2   2019-12-30 22:37:06.760857          =    20196    -13933     10443
3   2019-12-30 22:37:06.776350          =     8177    -14365    -30493
———————————————————————-

     End   Execute Function adxl345Test  2019-12-30 22:37  

********************************************************************************


Complete Program Listing

# fspi241.py  tlfong01 2020jan03hkt2141

# Note – Loop back test OK, repeat send bytes OK, adxl345 basic test OK – tlfong01 2020jan10htk1653
# Thonny 3.7.7 Rpi4B buster 2019sep26 release

# ******************************************************************************************************
# *** Import ***
# ******************************************************************************************************

from    time          import sleep
import  spidev
import  os
import  sys
from    datetime      import datetime
from    signal        import pause
import  fprint220     as fprint
import  fmnu220       as fmnu

# ******************************************************************************************************
# *** SPI Bus Config for ADXL345 Only ***
# ******************************************************************************************************

#initBusMode  = 0b00  # default, for adxl355
initBusMode  = 0b11   # WARNING! – Mode 1, and Mode 3 does not work for Spi1, which can do Mode 0 and Mode 2 only

initBusSpeed = 100000 # 100kHz

spiBus00              = spidev.SpiDev()
spiBus00.open(0,0)
spiBus00.mode         = initBusMode
spiBus00.max_speed_hz = initBusSpeed

spiBus01              = spidev.SpiDev()
spiBus01.open(0,1)
spiBus01.mode         = initBusMode
spiBus01.max_speed_hz = initBusSpeed

# Warning Spi1,0, 1, 12, can not use Mode 1 and Mode3, ONLY Mode0 and Mode 2 ***
spiBus10              = spidev.SpiDev()
spiBus10.open(1,0)
#spiBus10.mode         = initBusMode
spiBus10.mode         = 0b00
spiBus10.max_speed_hz = initBusSpeed

spiBus11              = spidev.SpiDev()
spiBus11.open(1,1)
#spiBus11.mode         = initBusMode
spiBus11.mode         = 0b00
spiBus11.max_speed_hz = initBusSpeed

spiBus12              = spidev.SpiDev()
spiBus12.open(1,2)
#spiBus12.mode         = initBusMode
spiBus12.mode         = 0b00
spiBus12.max_speed_hz = initBusSpeed

spiBusDict = {
‘SpiBus00’: spiBus00,
‘SpiBus01’: spiBus01,
‘SpiBus10’: spiBus10,
‘SpiBus11’: spiBus11,
‘SpiBus12’: spiBus12,
}

spiControlByteDict = {
‘TestByte0x5a’            :     0x5a,
‘TestByte0x5b’            :     0x5b,
‘TestByte0x5c’            :     0x5c,
‘TestByte0x5d’            :     0x5d,
‘TestByte0x5e’            :     0x5e,
‘TestByte0x5f’            :     0x5f,
‘TestByte0x55’            :     0x55,
‘TestByte0x66’            :     0x66,
‘RepeatTimes100’          :      100,
‘RepeatTimes1000’         :     1000,
‘RepeatTimes10000’        :    10000,
‘RepeatTimes1000000’      :  1000000,
‘RepeatTimes10000000’     : 10000000,
‘PauseMilliSeconds10’     :     0.01,
‘OneThousandTimes’        : 1000,
‘TenThousandTimes’        : 10000,
‘TenMillionTimes’         : 10000000,
‘TenMilliSeconds’         : 0.01,
‘OneMilliSecond’          : 0.001,
}

# ******************************************************************************************************
# *** System Functions ***
# ******************************************************************************************************

def getSystemConfigInfo():
# *** General ***
print(‘*** General System Config ***’)
os.system(‘date’)
os.system(‘cat /etc/issue.net’)
os.system(‘uname -a’)
os.system(‘cat /proc/cpuinfo’)
os.system(‘grep model /proc/cpuinfo’)
os.system(‘grep Hardware /proc/cpuinfo’)
os.system(‘grep Revision /proc/cpuinfo’)
os.system(‘grep Serial /proc/cpuinfo’)
os.system(‘grep MemTotal /proc/meminfo’)
os.system(‘lsusb’)

# *** SPI ***
print(‘*** grep /boot/config.txt ***’)
os.system(‘grep dtparam=spi /boot/config.txt’)
os.system(‘grep dtoverlay=spi1-3cs /boot/config.txt’)
print(‘*** $ ls /dev/spi* ***’)
os.system(‘ls /dev/spi*’)

# *** I2C***
print(‘*** grep I2c /boot/config.txt) ***’)
os.system(‘grep dtparam=i2c /boot/config.txt’)
print(‘*** I2C dtoverlay ***’)
os.system(‘grep dtoverlay=i2c /boot/config.txt’)
print(‘*** $ ls /dev/i2c* ***’)
os.system(‘ls /dev/i2c*’)
print(‘*** i2cdetect -y 1 ***’)
os.system(‘i2cdetect -y 1’)
print(‘*** i2cdetect -y 3 ***’)
os.system(‘i2cdetect -y 3’)
#os.system(‘i2cdetect -y 4’) # Clashes with SPI1 CE1 !!!
#os.system(‘i2cdetect -y 5’) # Not working !!!
#os.system(‘i2cdetect -y 6’) # Not working !!!
print(‘*** End of System, SPI, and I2C Config Summary ***’)
return

def setSpiPortSpeed(spiBus, busSpeed):
spiBus.max_speed_hz = busSpeed
return

def closeSpi(spiBus):
spiBus.close()
return

# ******************************************************************************************************
# *** SPI Send/Recv Functions ***
# ******************************************************************************************************

# *** SPI Send/Receive 1/2/3 Bytes ***

def spiSendRecvOneByte(spiBus, sendByte):
sendByteArray = [sendByte]
recvByteArray = spiBus.xfer2(sendByteArray)
return recvByteArray

def spiSendRecvTwoBytes(spiBus, sendByte1, sendByte2):
sendByteArray = [sendByte1, sendByte2]
recvByteArray = spiBus.xfer2(sendByteArray)
return recvByteArray

def spiSendRecvThreeBytes(spiBus, sendByte1, sendByte2, sendByte3):
sendByteArray = [sendByte1, sendByte2, sendByte3]
recvByteArray = spiBus.xfer2(sendByteArray)
return recvByteArray

# *** SPI Write/Read Device Register One Byte (general app, NOT for Adxl345, which use Bit7 to denote Read/Write ***

def writedDevRegOneByte(spiBusName, devRegAddrDict, devRegName, controlByteDict, writeByteName):
spiBus         = spiBusDict[spiBusName]
devRegAddr     = devRegAddrDict[devRegName]
writeDevRegAddr = devRegAddr << 1
writeByte = controlByteDict[writeByteName]
spiSendRecvTwoBytes(spiBus, writeDevRegAddr, writeByte)
return

def readDevRegOneByte(spiBusName, devRegAddrDict, devRegName):
spiBus         = spiBusDict[spiBusName]
devRegAddr     = devRegAddrDict[devRegName]
readDevRegAddr = (devRegaddr << 1) | 0x01
dummyByte      = 0x00
recvByteArray  = spiSendRecvTwoBytes(spiBus, readDevRegAddr, dummyByte)
readByte       = recvByteArray[1]
return readByte

# ******************************************************************************************************
# *** SPI Loopback Functions ***
# ******************************************************************************************************

def loopbackOneByte(spiBusName, spiBus, testByteName, testByte):
fprint.printBeginExecFunction()
fprint.printTitleString(‘spiBusName’, fprint.indentFormat640, spiBusName)
fprint.printTitleString(‘testByteName’, fprint.indentFormat640, testByteName)
recvByteArray     = spiSendRecvOneByte(spiBus, testByte)
recvByte          = recvByteArray[0]
fprint.printTitleOneByteNum(‘sendByte’, fprint.indentFormat640, testByte)
fprint.printTitleOneByteNum(‘recvByte’, fprint.indentFormat640, recvByte)
fprint.printEndExecFunction()
return

def loopBackOneByteNoPrint(spiBusName, spiBus, testByteName, testByte):
#fprint.printBeginExecFunction()
recvByteArray     = spiSendRecvOneByte(spiBus, testByte)
recvByte          = recvByteArray[0]
#fprint.printTitleOneByteNum(‘sendByte’, fprint.indentFormat640, sendByte)
#fprint.printTitleOneByteNum(‘recvByte’, fprint.indentFormat640, recvByte)
#fprint.printEndExecFunction()
return

def loopbackTwoBytes(spiBus, sendByte1, sendByte2):
fprint.printBeginExecFunction()
recvByteArray     = spiSendRecvTwoBytes(spiBus, sendByte1, sendByte2)
recvByte1          = recvByteArray[0]
recvByte2          = recvByteArray[1]
sendBytes = fprint.convertOneByteNumToFourCharStr(sendByte1) + ‘ ‘ + fprint.convertOneByteNumToFourCharStr(sendByte2)
fprint.printTitleString(‘sendBytes’, fprint.indentFormat640, sendBytes)
recvBytes = fprint.convertOneByteNumToFourCharStr(recvByte1) + ‘ ‘ + fprint.convertOneByteNumToFourCharStr(recvByte2)
fprint.printTitleString(‘sendBytes’, fprint.indentFormat640, recvBytes)
fprint.printEndExecFunction()
return

def loopbackThreeBytes(spiBus, sendByte1, sendByte2, sendByte3):
fprint.printBeginExecFunction()
recvByteArray      = spiSendRecvThreeBytes(spiBus, sendByte1, sendByte2, sendByte3)
recvByte1          = recvByteArray[0]
recvByte2          = recvByteArray[1]
recvByte3          = recvByteArray[2]
sendBytes = fprint.convertOneByteNumToFourCharStr(sendByte1) + ‘ ‘ + fprint.convertOneByteNumToFourCharStr(sendByte2) + ‘ ‘ + \
fprint.convertOneByteNumToFourCharStr(sendByte3)
fprint.printTitleString(‘sendBytes’, fprint.indentFormat640, sendBytes)

recvBytes = fprint.convertOneByteNumToFourCharStr(recvByte1) + ‘ ‘ + fprint.convertOneByteNumToFourCharStr(recvByte2) + ‘ ‘ + \
fprint.convertOneByteNumToFourCharStr(recvByte3)
fprint.printTitleString(‘sendBytes’, fprint.indentFormat640, recvBytes)
fprint.printEndExecFunction()
return

# ******************************************************************************************************
# *** Test SPI Loopback 1/2/3 bytes ***
# ******************************************************************************************************

def testLoopBackOneByte(spiBusName, testByteName):
spiBus = spiBusDict[spiBusName]
testByte = spiControlByteDict[testByteName]
loopbackOneByte(spiBusName, spiBus, testByteName, testByte)
return

def testLoopBackOneByteNoPrint(spiBusName, testByteName):
spiBus = spiBusDict[spiBusName]
testByte = spiControlByteDict[testByteName]
loopBackOneByteNoPrint(spiBusName, spiBus, testByteName, testByte)
return

def testLoopbackTwoBytes(spiBusName, testByteName1, testByteName2):
spiBus = spiBusDict[spiBusName]
testByte1 = spiControlByteDict[testByteName1]
testByte2 = spiControlByteDict[testByteName1]
loopbackTwoBytes(spiBus, testByte1, testByte2)
return

def testLoopbackThreeBytes(spiBusName, testByteName1, testByteName2, testByteName3):
spiBus = spiBusDict[spiBusName]
testByte1 = spiControlByteDict[testByteName1]
testByte2 = spiControlByteDict[testByteName2]
testByte3 = spiControlByteDict[testByteName3]
loopbackThreeBytes(spiBus, testByte1, testByte2, testByte3)
return

# ******************************************************************************************************
# *** Test SPI Loopback 1/2/3 bytes ***
# ******************************************************************************************************

def testRepeatSendOneByte(spiBusName, testByteName, repeatTimesName, pauseMilliSecondsName):
fprint.printBeginExecFunction()
spiBus = spiBusDict[spiBusName]
testByte = spiControlByteDict[testByteName]
repeatTimes = spiControlByteDict[repeatTimesName]
pauseMilliSeconds = spiControlByteDict[pauseMilliSecondsName]
for count in range(repeatTimes):
spiSendRecvOneByte(spiBus, testByte)
sleep(pauseMilliSeconds)
fprint.printEndExecFunction()
return

def testRepeatSendTwoBytes(spiBusName, testByteName1, testByteName2, repeatTimesName, pauseMilliSecondsName):
fprint.printBeginExecFunction()
spiBus = spiBusDict[spiBusName]
testByte1 = spiControlByteDict[testByteName1]
testByte2 = spiControlByteDict[testByteName2]
repeatTimes = spiControlByteDict[repeatTimesName]
pauseMilliSeconds = spiControlByteDict[pauseMilliSecondsName]
for count in range(repeatTimes):
spiSendRecvTwoBytes(spiBus, testByte1, testByte2)
sleep(pauseMilliSeconds)
fprint.printEndExecFunction()
return

def testRepeatSendThreeBytes(spiBusName, testByteName1, testByteName2, testByteName3, repeatTimesName, pauseMilliSecondsName):
fprint.printBeginExecFunction()
spiBus = spiBusDict[spiBusName]
testByte1 = spiControlByteDict[testByteName1]
testByte2 = spiControlByteDict[testByteName2]
testByte3 = spiControlByteDict[testByteName3]
repeatTimes = spiControlByteDict[repeatTimesName]
pauseMilliSeconds = spiControlByteDict[pauseMilliSecondsName]
for count in range(repeatTimes):
spiSendRecvThreeBytes(spiBus, testByte1, testByte2, testByte3)
sleep(pauseMilliSeconds)
fprint.printEndExecFunction()
return

# *********************************************************************************************************
# *** More loopback and repeat sending byte tests
# *********************************************************************************************************

# *** SPI Tests ***

def spiBus00LoopbackOneByte():
testLoopBackOneByte(‘SpiBus00’, ‘TestByte0x5a’)
return

def spiBus00LoopbackTwoBytes():
testLoopbackTwoBytes(‘SpiBus00’, ‘TestByte0x5a’, ‘TestByte0x5b’)
return

def spiBus00LoopbackThreeBytes():
testLoopbackThreeBytes(‘SpiBus00’, ‘TestByte0x5a’, ‘TestByte0x5b’, ‘TestByte0x5c’)
return

def spiBus00RepeatLoopbackOneByte():
fprint.printBeginExecFunction()
for count in range(100):
testLoopBackOneByte(‘SpiBus00’, ‘TestByte0x5a’)
fprint.printEndExecFunction()
return

def spiBus00RepeatLoopbackOneByteNoPrint():
fprint.printBeginExecFunction()
for count in range(100):
loopBackOneByteNoPrint(‘SpiBus00’, ‘TestByte0x5a’)
fprint.printEndExecFunction()
return

# *********************************************************

def testSpiLoopbackOneByte(spiBusName, testByteName):

testLoopBackOneByte(spiBusName, testByteName)

#testLoopBackOneByte(‘SpiBus01’, ‘TestByte0x5b’)
#testLoopBackOneByte(‘SpiBus10’, ‘TestByte0x5c’)
#testLoopBackOneByte(‘SpiBus11’, ‘TestByte0x5d’)
#testLoopBackOneByte(‘SpiBus12’, ‘TestByte0x5e’)

# *** Test loopbcak 1/2/3 Bytes for spiBus00 ***
#testLoopBackOneByte(‘SpiBus00’, ‘TestByte0x5a’)
#testLoopbackTwoBytes(‘SpiBus00’, ‘TestByte0x5a’, ‘TestByte0x5b’)
#testLoopbackThreeBytes(‘SpiBus00’, ‘TestByte0x5a’, ‘TestByte0x5b’, ‘TestByte0x5c’)

# *** Test repeat send on byte for spiBus00 ***
#testRepeatSendOneByte(‘SpiBus00’, ‘TestByte0x5a’, ‘RepeatTimes100’, ‘PauseMilliSeconds10’)
#testRepeatSendTwoBytes(‘SpiBus00’, ‘TestByte0x5a’, ‘TestByte0x5b’, ‘RepeatTimes100’, ‘PauseMilliSeconds10’)
#testRepeatSendThreeBytes(‘SpiBus00’, ‘TestByte0x5a’, ‘TestByte0x5b’, ‘TestByte0x5c’, ‘RepeatTimes100’, ‘PauseMilliSeconds10’)
return

def testRepeatSpiLoopbackOneByte(spiBusName, testByteName, pauseTimeName, totalCountName):
fprint.printBeginExecFunction()
fprint.printTitleString(‘spiBusName’, fprint.indentFormat640, spiBusName)
fprint.printTitleString(‘testByteName’, fprint.indentFormat640, testByteName)
fprint.printTitleString(‘totalCountName’, fprint.indentFormat640, totalCountName)

for count in range(spiControlByteDict[totalCountName]):
testLoopBackOneByteNoPrint(spiBusName, testByteName)
sleep(spiControlByteDict[pauseTimeName])
fprint.printEndExecFunction()
return

”’ *** Old Tests ***

#getSystemConfigInfo()

testSpiLoopbackOneByte(‘SpiBus00’, ‘TestByte0x5b’)
#testSpiLoopbackOneByte(‘SpiBus01’, ‘TestByte0x5c’)
#testSpiLoopbackOneByte(‘SpiBus10’, ‘TestByte0x5d’)
#testSpiLoopbackOneByte(‘SpiBus11’, ‘TestByte0x5e’)
#testSpiLoopbackOneByte(‘SpiBus12’, ‘TestByte0x5f’)

#testRepeatSpiLoopbackOneByte(‘SpiBus00’, ‘TestByte0x5b’, ‘OneMilliSecond’, ‘OneThousandTimes’, )
#testRepeatSpiLoopbackOneByte(‘SpiBus00’, ‘TestByte0x5c’, ‘OneMilliSecond’, ‘TenThousandTimes’, )
#testRepeatSpiLoopbackOneByte(‘SpiBus00’, ‘TestByte0x5d’, ‘OneMilliSecond’, ‘TenMillionTimes’, )

#testRepeatSendOneByte(‘SpiBus00’, ‘TestByte0x5b’, ‘TenMillionTimes’, ‘OneMilliSecond’)
#testRepeatSendOneByte(‘SpiBus01’, ‘TestByte0x5b’, ‘TenMillionTimes’, ‘OneMilliSecond’)
#testRepeatSendOneByte(‘SpiBus10’, ‘TestByte0x5b’, ‘TenMillionTimes’, ‘OneMilliSecond’)
#testRepeatSendOneByte(‘SpiBus11’, ‘TestByte0x5b’, ‘TenMillionTimes’, ‘OneMilliSecond’)
testRepeatSendOneByte(‘SpiBus12’, ‘TestByte0x5b’, ‘TenMillionTimes’, ‘OneMilliSecond’)

”’

# *********************************************************************************************************
# *** Adxl345 Functions *** !!! Warning (1) Adxl345 SPI must be mode 3, (2) SPI 1,1, 1,3 mode 3 not working
# *********************************************************************************************************

adxl345ModuleDict = \
{
‘ModuleType’        : ‘ADXL345’,
‘ModuleHelp’        : ‘Adxl345AccelerometerHelp’,
‘RegAddrDict’       : ‘Adxl345RegAddrDict’,
‘ControlByteDict’   : ‘Adxl345ControlByteDict’,
‘DevIdRegName’      : ‘DevIdReg’,
‘DevIdByteName’     : ‘DevIdByte’,

‘Jacky’             : {‘SpiBusName’         : ‘SpiBus00’,
‘CurrentConfigName’  : ‘Temp’,
},
‘Katie’             : {‘SpiBusName’         : ‘SpiBus01’,
‘CurrentConfigName’  : ‘Temp’,
},
‘Lucy’              : {‘SpiBusName’  : ‘SpiBus10’,
},
‘Maggi’             : {‘SpiBusName’  : ‘SpiBus11’,
},
‘Nancy’             : {‘SpiBusName’  : ‘SpiBus12’,
},
}

adxl345RegAddrDict = \
{
‘DevIdReg’                   : 0x00,
‘DataFormatReg’              : 0x31,
‘PowerControlReg’            : 0x2d,
‘InterruptConfigReg’         : 0x2e,
‘DataX0’                     : 0x32,
‘DataX1’                     : 0x33,
‘DataY0’                     : 0x34,
‘DataY1’                     : 0x35,
‘DataZ0’                     : 0x36,
‘DataZ1’                     : 0x37,
}

adxl345ControlByteDict = \
{
‘DevIdByte’                              : 0xe5,
‘DefaultConfig16G13BitRealTest’          : 0x0B, # 0b 0000 1011
‘DefaultConfig16G13BitSelfTest’          : 0x8B, # 0b 1000 1011
‘StartMeasurement’                       : 0x08,
‘InterruptDataReadyEnable’               : 0x80,
‘InterruptDataReadyDisable’              : 0x00,
‘SelfTestDisable’                        : 0x00 << 7,
‘SelfTestEnable’                         : 0x01 << 7,
‘Spi4Wire’                               : 0x00 << 6,
‘InterruptActiveLow’                     : 0x01 << 5,
‘FullReslutionMode’                      : 0x01 << 3,
‘RightJustifyMode’                       : 0x00 << 2,
‘Range2g’                                : 0x00 << 0,
‘Range4g’                                : 0x01 << 0,
‘Range8g’                                : 0x10 << 0,
‘Range16g’                               : 0x11 << 0,
}

# *** Module Dict Dict ***

moduleDictDict = {
‘Adxl345’  : adxl345ModuleDict,
}

# *** Test ADXL345 Accelerometer ***

def adxl345WritedDevRegOneByte(spiBusName, devRegAddrDict, devRegName, controlByteDict, writeByteName):
spiBus         = spiBusDict[spiBusName]
devRegAddr     = devRegAddrDict[devRegName]
writeDevRegAddr = devRegAddr | 0x00 # WARNING: for Adxl345 only. For default = devRegaddr << 1
writeByte = controlByteDict[writeByteName]
spiSendRecvTwoBytes(spiBus, writeDevRegAddr, writeByte)
return

def adxl345ReadDevRegOneByte(spiBusName, devRegAddrDict, devRegName):
spiBus         = spiBusDict[spiBusName]
devRegAddr     = devRegAddrDict[devRegName]
readDevRegAddr = devRegAddr | 0x80  # WARNING: for Adxl345 only. For adxl355 or default = (devRegaddr << 1) | 0x01
dummyByte      = 0x00
recvByteArray  = spiSendRecvTwoBytes(spiBus, readDevRegAddr, dummyByte)
readByte       = recvByteArray[1]
return readByte

def adxl345ReadRegOneByte(deviceNickName, devRegName):
#fprint.printBeginExecFunction()

moduleTypeName     = ‘Adxl345’
moduleDict         = moduleDictDict[‘Adxl345’]
spiBusName         = moduleDict[deviceNickName][‘SpiBusName’]
devRegAddrDict     = adxl345RegAddrDict

spiBus         = spiBusDict[spiBusName]
devRegAddr     = devRegAddrDict[devRegName]

readByte       = adxl345ReadDevRegOneByte(spiBusName, devRegAddrDict, devRegName)

#fprint.printTitleString(‘BusName’,            fprint.indentFormat640, spiBusName) # For debugging
#fprint.printTitleString(‘DevIdRegName’,       fprint.indentFormat640, devRegName) # For debugging
#fprint.printTitleOneByteNum(‘DevRegAddr’,     fprint.indentFormat640, devRegAddr) # For debugging
#fprint.printTitleOneByteNum(‘DevReg Contents’,fprint.indentFormat640, readByte)   # For debugging

#fprint.printEndExecFunction()
return readByte

def adxl345WriteReadRegOneByte(deviceNickName, devRegName, writeByteName):
#fprint.printBeginExecFunction()

moduleTypeName  = ‘Adxl345’
moduleDict      = moduleDictDict[‘Adxl345’]
spiBusName      = moduleDict[deviceNickName][‘SpiBusName’]
devRegAddrDict  = adxl345RegAddrDict
controlByteDict = adxl345ControlByteDict
spiBus          = spiBusDict[spiBusName]
devRegAddr      = devRegAddrDict[devRegName]
writeByte       = controlByteDict[writeByteName]

adxl345WritedDevRegOneByte(spiBusName, devRegAddrDict, devRegName, controlByteDict, writeByteName)
readByte        = adxl345ReadDevRegOneByte(spiBusName, devRegAddrDict, devRegName)

#fprint.printTitleString(‘BusName’,            fprint.indentFormat640, spiBusName)    # For debugging
#fprint.printTitleString(‘DevIdRegName’,       fprint.indentFormat640, devRegName)    # For debugging
#fprint.printTitleOneByteNum(‘DevRegAddr’,     fprint.indentFormat640, devRegAddr)    # For debugging
#fprint.printTitleString(‘WriteByteName’,      fprint.indentFormat640, writeByteName) # For debugging
#fprint.printTitleOneByteNum(‘WriteByte’,      fprint.indentFormat640, writeByte)     # For debugging
#fprint.printTitleOneByteNum(‘Read Back Byte’, fprint.indentFormat640, readByte)      # For debugging

#fprint.printEndExecFunction()
return

# ******************************************************************************************************
# *** Adxl345 Test Functions ***
# ******************************************************************************************************

def checkDeviceId(deviceName):
readByte = adxl345ReadRegOneByte(deviceName, ‘DevIdReg’)
fprint.printTitleOneByteNum(‘DevIdRegister Contests =’, fprint.indentFormat640, readByte)
return

def generalConfig(deviceNickName, generalConfigByteName):
adxl345WriteReadRegOneByte(deviceNickName, ‘DataFormatReg’, generalConfigByteName)
moduleDictDict[‘Adxl345’][deviceNickName][‘CurrentConfigName’] = generalConfigByteName
return

def interruptConfig(deviceInckName, interruptConfigByteName):
adxl345WriteReadRegOneByte(deviceInckName, ‘InterruptConfigReg’, interruptConfigByteName)

return

def convertTwoCompNumToDecNum(twoCompNum, numBytes):
twoCompNumStr = bin(twoCompNum)
val = int(twoCompNumStr, numBytes)
b = val.to_bytes(numBytes, byteorder=sys.byteorder, signed = False)
decNum = int.from_bytes(b, byteorder = sys.byteorder, signed = True)
return decNum

def getXyzDecimalValuesList(deviceNickName):
# *** Read Two’s Compliment Raw Results ***
x0 = adxl345ReadRegOneByte(deviceNickName, ‘DataX0’)
x1 = adxl345ReadRegOneByte(deviceNickName, ‘DataX1’)
y0 = adxl345ReadRegOneByte(deviceNickName, ‘DataY0’)
y1 = adxl345ReadRegOneByte(deviceNickName, ‘DataY1’)
z0 = adxl345ReadRegOneByte(deviceNickName, ‘DataZ0’)
z1 = adxl345ReadRegOneByte(deviceNickName, ‘DataZ1’)

# *** Convert To Decimal Results List ***
xTwoComp  = (x1 << 8) | x0
yTwoComp  = (y1 << 8) | y0
zTwoComp  = (z1 << 8) | z0

xDecNum = convertTwoCompNumToDecNum(xTwoComp, 2)
yDecNum = convertTwoCompNumToDecNum(yTwoComp, 2)
zDecNum = convertTwoCompNumToDecNum(zTwoComp, 2)

xyzDecimalValuesList = (xDecNum, yDecNum, zDecNum)
return xyzDecimalValuesList

def getRepeatMeasurementResultsList(deviceNickName, repeatTimes, pauseSeconds):
outputListStrList = [‘dummy’, ‘dummy’, ‘dummy’, ‘dummy’]
count = 0
for count in range(repeatTimes):
# *** Start Measurement ***
adxl345WriteReadRegOneByte(deviceNickName, ‘PowerControlReg’,    ‘StartMeasurement’)
# *** Get Decimal Values List ***
xyzDecimalValuesList = getXyzDecimalValuesList(deviceNickName)
outputListStr = ‘       ‘ + str(count).ljust(4) + str(datetime.now()).ljust(20) + ‘          = ‘ + \
str(xyzDecimalValuesList[0]).rjust(8)     + ‘  ‘ + \
str(xyzDecimalValuesList[1]).rjust(8)     + ‘  ‘ + \
str(xyzDecimalValuesList[2]).rjust(8)
outputListStrList[count] = outputListStr
sleep(pauseSeconds)
return outputListStrList

def printMeasurementResults(deviceNickname, measurementResultsList):
# *** Print Title ***

fprint.printTitleString (‘ADXL345 Device Name’, fprint.indentFormat640, deviceNickname)
fprint.printTitleString (‘BusName’, fprint.indentFormat640, moduleDictDict[‘Adxl345’][deviceNickname][‘SpiBusName’])
fprint.printTitleString (‘ConfigName’, fprint.indentFormat640, moduleDictDict[‘Adxl345’][deviceNickname][‘CurrentConfigName’])
print(‘ ‘)
print(‘       ———————————————————————-‘)
fprint.printTitleString(‘          Time’, fprint.indentFormat640, ‘ X value   Y Value   Z Value’)
print(‘       ———————————————————————-‘)

# *** Repeat Print Measurement Results ***
for measurementResults in measurementResultsList:
print(measurementResults)

print(‘       ———————————————————————-‘)
return

def adxl345Test(deviceNickName, configByteName):
fprint.printBeginExecFunction()
checkDeviceId(deviceNickName)
generalConfig(deviceNickName, configByteName)
interruptConfig(deviceNickName, ‘InterruptDataReadyDisable’)
measurementResultsList = getRepeatMeasurementResultsList(deviceNickName, 4, 0.01)
printMeasurementResults(deviceNickName, measurementResultsList)
fprint.printEndExecFunction()
return

# *** Old ADXL345 Tests ***

#adxl345Test(‘Jacky’, ‘DefaultConfig16G13BitRealTest’  )
#adxl345Test(‘Katie’, ‘DefaultConfig16G13BitRealTest’  )
#adxl345Test(‘Jacky’, ‘DefaultConfig16G13BitSelfTest’  )
#adxl345Test(‘Katie’, ‘DefaultConfig16G13BitSelfTest’  )

# ******************************************************************************************************
# *** Main Test Functions ***
# ******************************************************************************************************

# *** adxl345 Tests ***

# *** dummy function ***

def exit():
pass
return

# *** Menu Config ***

def readMainMenu():
fprint.printBeginExecFunction()
fmnu.execMenuList(mainMenu)
fprint.printEndExecFunction()
return

def readSpiMenu():
fprint.printBeginExecFunction()
fmnu.execMenuList(spiMenu)
fprint.printEndExecFunction()
return

def readAdxl345Menu():
fprint.printBeginExecFunction()
fmnu.execMenuList(adxl345Menu)
fprint.printEndExecFunction()
return

def readMoreMenu():
fprint.printBeginExecFunction()
print(‘Not yet ready!!!’)
fprint.printEndExecFunction()
return

# *** Menu Config ***

mainMenu = [‘########## Main Menu ##############################################################’,
[[‘0’,  [‘SPI Bus Tests’,  readSpiMenu]],
[‘1’,  [‘ADXL345 Tests’,  readAdxl345Menu]],
[‘2’,  [‘More Tests’,     readMoreMenu]],
[‘x’,  [‘exitMenu()’,     exit]],
]
]

spiMenu = [‘########## SPI Tests Menu ##########################################################’,
[[‘0’,  [‘spiBus00LoopxbackOneByte()’, spiBus00LoopbackOneByte]],
[‘1’,  [‘spiBus00LoopbackTwoBytes()’, spiBus00LoopbackTwoBytes]],
[‘2’,  [‘spiBus00LoopbackThreeBytes()’, spiBus00LoopbackThreeBytes]],
[‘x’,  [‘exitMenu()’,    exit]],
]
]

adxl345Menu = [‘########## ADXL345 Tests Menu ##################################################’,
[[‘0’,  [‘adxl345Test()’, adxl345Test]],
[‘1’,  [‘adxl345Test()’, adxl345Test]],
[‘2’,  [‘adxl345Test()’, adxl345Test]],
[‘x’,  [‘exitMenu()’,    exit]],
]
]

# *** MCP3008 Test Functions ***

def spiSendRecvThreeBytesV001(spiBus, sendByte1, sendByte2, sendByte3):
sendByteArray = [sendByte1, sendByte2, sendByte3]
recvByteArray = spiBus.xfer2(sendByteArray)
return recvByteArray

def loopbackThreeBytesV001(spiBus, sendByte1, sendByte2, sendByte3):
fprint.printBeginExecFunction()
recvByteArray      = spiSendRecvThreeBytesV001(spiBus, sendByte1, sendByte2, sendByte3)
recvByte1          = recvByteArray[0]
recvByte2          = recvByteArray[1]
recvByte3          = recvByteArray[2]
sendBytes = fprint.convertOneByteNumToFourCharStr(sendByte1) + ‘ ‘ + fprint.convertOneByteNumToFourCharStr(sendByte2) + ‘ ‘ + \
fprint.convertOneByteNumToFourCharStr(sendByte3)
fprint.printTitleString(‘sendBytes’, fprint.indentFormat640, sendBytes)

recvBytes = fprint.convertOneByteNumToFourCharStr(recvByte1) + ‘ ‘ + fprint.convertOneByteNumToFourCharStr(recvByte2) + ‘ ‘ + \
fprint.convertOneByteNumToFourCharStr(recvByte3)
fprint.printTitleString(‘recvBytes’, fprint.indentFormat640, recvBytes)
fprint.printEndExecFunction()
return

def loopbackThreeBytesV002(spiBus, commandByte1, commandByte2, dummyByte):
#fprint.printBeginExecFunction()

recvByteArray      = spiSendRecvThreeBytesV001(spiBus, commandByte1, commandByte2, dummyByte)

recvByte1          = recvByteArray[0]
recvByte2          = recvByteArray[1]
recvByte3          = recvByteArray[2]

#sendBytes = fprint.convertOneByteNumToFourCharStr(sendByte1) + ‘ ‘ + fprint.convertOneByteNumToFourCharStr(sendByte2) + ‘ ‘ + \
#            fprint.convertOneByteNumToFourCharStr(sendByte3)
#fprint.printTitleString(‘sendBytes’, fprint.indentFormat640, sendBytes)

#recvBytes = fprint.convertOneByteNumToFourCharStr(recvByte1) + ‘ ‘ + fprint.convertOneByteNumToFourCharStr(recvByte2) + ‘ ‘ + \
#            fprint.convertOneByteNumToFourCharStr(recvByte3)
#fprint.printTitleString(‘recvBytes’, fprint.indentFormat640, recvBytes)
#fprint.printEndExecFunction()

adcResultsArray = [recvByteArray[1], recvByteArray[2]]

#fprint.printEndExecFunction()
return adcResultsArray

def pingMcp3208(spiBus):
fprint.printBeginExecFunction()

commandByte1 = 0b00000110 # leading five zeros, start bit = 0b1, D2 = 0b0
commandByte2 = 0b00000000 # D1, D0 = 0b00, followed by 6 zeros
dummyByte    = 0x55

adcResultsArray = loopbackThreeBytesV002(spiBus, commandByte1, commandByte2, dummyByte)
fprint.printTitleOneByteNum(‘Adc results byte 1 =’, fprint.indentFormat640, adcResultsArray[0])
fprint.printTitleOneByteNum(‘Adc results byte 2 =’, fprint.indentFormat640, adcResultsArray[1])

fprint.printEndExecFunction()
return

”’ Old Tests
#testSpiLoopbackOneByte(‘SpiBus00’, ‘TestByte0x5b’)
#adxl345Test(‘Jacky’, ‘DefaultConfig16G13BitRealTest’  )
#loopbackThreeBytesV001(spiBus00, 0x5a, 0x5b, 0x5c) # three arbitrary bytes
#loopbackThreeBytesV002(spiBus00, 0x5a, 0x5b, 0x5c)
#pingMcp3208(spiBus00)
”’

# *** Main Tests ***

def main():
loopbackThreeBytesV001(spiBus00, 0x06, 0x00, 0x55) # mcp3208 (1) Start/D2 byte, (2) D1/D0 byte, (3) Dummy byte
return

# ******************************************************************************************************
# *** Main ***
# ******************************************************************************************************

if __name__ == ‘__main__’:
main()

# .END

”’ *** Ping MCP3208 Sample Output ***

>>> %Run fspi239.py

********************************************************************************

Begin Execute Function loopbackThreeBytesV001  2020-01-03 21:39

Function Name                           = loopbackThreeBytesV001
sendBytes                               = 0x06 0x00 0x55
recvBytes                               = 0x00 0x00 0x00

End   Execute Function loopbackThreeBytesV001  2020-01-03 21:39

********************************************************************************

>>> %Run fspi239.py

********************************************************************************

Begin Execute Function loopbackThreeBytesV001  2020-01-03 21:40

Function Name                           = loopbackThreeBytesV001
sendBytes                               = 0x06 0x00 0x55
recvBytes                               = 0x00 0x0f 0xfd

End   Execute Function loopbackThreeBytesV001  2020-01-03 21:40

********************************************************************************

>>> %Run fspi238.py

********************************************************************************

Begin Execute Function loopbackThreeBytesV001  2020-01-02 22:57

Function Name                           = loopbackThreeBytesV001
sendBytes                               = 0x5a 0x5b 0x5c
recvBytes                               = 0x5a 0x5b 0x5c

End   Execute Function loopbackThreeBytesV001  2020-01-02 22:57

********************************************************************************
********************************************************************************

Begin Execute Function pingMcp3208  2020-01-02 22:57

Function Name                           = pingMcp3208
Adc results byte 1 =                    = 0x00
Adc results byte 2 =                    = 0x55

End   Execute Function pingMcp3208  2020-01-02 22:57

********************************************************************************

>>>
”’

”’ *** Old sample output ***

>>> %Run fspi231.py

     ********************************************************************************

     Begin Execute Function adxl345Test  2019-12-30 22:37                            

       Function Name                           = adxl345Test
DevIdRegister Contests =                = 0xe5
ADXL345 Device Name                     = Jacky
BusName                                 = SpiBus00
ConfigName                              = DefaultConfig16G13BitRealTest
testLoopbackThreeBytes(‘SpiBus00’, ‘TestByte0x5a’, ‘TestByte0x5b’, ‘TestByte0x5c’)
———————————————————————-
Time                          =  X value   Y Value   Z Value
———————————————————————-
0   2019-12-30 22:37:06.539422          =    12261    -13365     10469
1   2019-12-30 22:37:06.554168          =    16660     16705     16705
2   2019-12-30 22:37:06.569127          =     4369      4369    -30703
3   2019-12-30 22:37:06.584167          =     8466      8481      8481
———————————————————————-

     End   Execute Function adxl345Test  2019-12-30 22:37                            

     ********************************************************************************
********************************************************************************

Begin Execute Function adxl345Test  2019-12-30 22:37

Function Name                           = adxl345Test
DevIdRegister Contests =                = 0x01
ADXL345 Device Name                     = Katie
BusName                                 = SpiBus01
ConfigName                              = DefaultConfig16G13BitRealTest

———————————————————————-
Time                          =  X value   Y Value   Z Value
———————————————————————-
0   2019-12-30 22:37:06.631418          =    12261         0         0
1   2019-12-30 22:37:06.646169          =        0         0         0
2   2019-12-30 22:37:06.661151          =        0         0         0
3   2019-12-30 22:37:06.676500          =        0         0         0
———————————————————————-

End   Execute Function adxl345Test  2019-12-30 22:37

********************************************************************************
********************************************************************************

     Begin Execute Function adxl345Test  2019-12-30 22:37                            

       Function Name                           = adxl345Test
DevIdRegister Contests =                = 0x00
ADXL345 Device Name                     = Jacky
BusName                                 = SpiBus00
ConfigName                              = DefaultConfig16G13BitSelfTest

———————————————————————-
Time                          =  X value   Y Value   Z Value
———————————————————————-
0   2019-12-30 22:37:06.731070          =      128     -2053     10469
1   2019-12-30 22:37:06.745782          =    -8467     -9289     10469
2   2019-12-30 22:37:06.760857          =    20196    -13933     10443
3   2019-12-30 22:37:06.776350          =     8177    -14365    -30493
———————————————————————-

     End   Execute Function adxl345Test  2019-12-30 22:37  

********************************************************************************
********************************************************************************

Begin Execute Function adxl345Test  2019-12-30 22:37

Function Name                           = adxl345Test
DevIdRegister Contests =                = 0x01
ADXL345 Device Name                     = Katie
BusName                                 = SpiBus01
ConfigName                              = DefaultConfig16G13BitSelfTest

———————————————————————-
Time                          =  X value   Y Value   Z Value
———————————————————————-
0   2019-12-30 22:37:06.829574          =    12261         0         0
1   2019-12-30 22:37:06.844307          =        0         0         0
2   2019-12-30 22:37:06.859281          =        0         0         0
3   2019-12-30 22:37:06.874499          =        0         0         0
———————————————————————-

End   Execute Function adxl345Test  2019-12-30 22:37

********************************************************************************

>>>
”’

”’ *** Old /boot/config.txt ***

/boot/config.txt

# config2019dec3001.txt

# *** Display ***

disable_overscan=1
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

# *** Audio ***

dtparam=audio=on

# *** UART ***

enable_uart=1

# *** I2C ***

dtparam=i2c_arm=on,i2c_arm_baudrate=50000

dtoverlay=i2c1,pins_2_3  (board pins 3, 5)
dtoverlay=i2c3,pins_4_5  (board pins 7, 29)
dtoverlay=i2c4,pins_6_7  (board pins 31, 26)
dtoverlay=i2c5,pins_12_13 (board pins 32, 33)
dtoverlay=i2c6,pins_22_23 (board pins 15, 16)

# *** SPI ***

dtparam=spi=on
dtoverlay=spi1-3cs

# *** End of config.txt ***

”’

”’
pi@raspberrypi:~ $ date
Mon 30 Dec 2019 10:39:29 PM HKT
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux
pi@raspberrypi:~ $ ls /dev/spi*
/dev/spidev0.0  /dev/spidev0.1  /dev/spidev1.0  /dev/spidev1.1  /dev/spidev1.2
pi@raspberrypi:~ $

”’

# *** End of program and sample outputs ***


.END

6:12pm Wed. 2/26/2020

6:16pm Wed. 2/26/2020

.END

 

 

Categories: Uncategorized

1 reply »

  1. Hi I try to run your code but it is giving error

    Traceback (most recent call last):
    File “test.py”, line 22, in
    import fprint220 as fprint
    ImportError: No module named fprint220

    Can you help

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.