Commit ce236814 authored by Paolo Baesso's avatar Paolo Baesso

First example of switching LED on/off

parent 21b8530c
# -*- coding: utf-8 -*-
import uhal
from I2CuHal import I2CCore
import time
#import miniTLU
from si5345 import si5345
from AD5665R import AD5665R
from PCA9539PW import PCA9539PW
from E24AA025E48T import E24AA025E48T
manager = uhal.ConnectionManager("file://./TLUconnection.xml")
hw = manager.getDevice("tlu")
# hw.getNode("A").write(255)
reg = hw.getNode("version").read()
hw.dispatch()
print "CHECK REG= ", hex(reg)
# #First I2C core
print ("Instantiating master I2C core:")
master_I2C= I2CCore(hw, 10, 5, "i2c_master", None)
master_I2C.state()
#
# #######################################
enableCore= False #Only need to run this once, after power-up
if (enableCore):
mystop=True
print " Write RegDir to set I/O[7] to output:"
myslave= 0x21
mycmd= [0x01, 0x7F]
nwords= 1
master_I2C.write(myslave, mycmd, mystop)
mystop=False
mycmd= [0x01]
master_I2C.write(myslave, mycmd, mystop)
res= master_I2C.read( myslave, nwords)
print "\tPost RegDir: ", res
#DAC CONFIGURATION BEGIN
if (False):
zeDAC1=AD5665R(master_I2C, 0x1C)
zeDAC1.setIntRef(intRef= False, verbose= True)
zeDAC1.writeDAC(0x0, 7, verbose= True)#7626
if (True):
# #I2C EXPANDER CONFIGURATION BEGIN
IC6=PCA9539PW(master_I2C, 0x76)
#BANK 0
IC6.setInvertReg(0, 0x00)# 0= normal
IC6.setIOReg(0, 0x00)# 0= output <<<<<<<<<<<<<<<<<<<
IC6.setOutputs(0, 0x00)
res= IC6.getInputs(0)
print "IC6 read back bank 0: 0x%X" % res[0]
#
#BANK 1
IC6.setInvertReg(1, 0x00)# 0= normal
IC6.setIOReg(1, 0x00)# 0= output <<<<<<<<<<<<<<<<<<<
IC6.setOutputs(1, 0x00)
res= IC6.getInputs(1)
print "IC6 read back bank 1: 0x%X" % res[0]
# # #
IC7=PCA9539PW(master_I2C, 0x77)
#BANK 0
IC7.setInvertReg(0, 0x00)# 0= normal
IC7.setIOReg(0, 0x00)# 0= output <<<<<<<<<<<<<<<<<<<
IC7.setOutputs(0, 0x00)
res= IC7.getInputs(0)
print "IC7 read back bank 0: 0x%X" % res[0]
#
#BANK 1
IC7.setInvertReg(1, 0x00)# 0= normal
IC7.setIOReg(1, 0x00)# 0= output <<<<<<<<<<<<<<<<<<<
IC7.setOutputs(1, 0x00)
res= IC7.getInputs(1)
print "IC7 read back bank 1: 0x%X" % res[0]
# #I2C EXPANDER CONFIGURATION END
......@@ -101,10 +101,42 @@ class TLU:
self.IC7.setInvertReg(1, 0x00)# 0= normal, 1= inverted
self.IC7.setIOReg(1, 0x00)# 0= output, 1= input
self.IC7.setOutputs(1, 0xB0)# If output, set to XX
#Display
self.DISP=CFA632(self.TLU_I2C, 0x2A) #
#Power/Led Module
dac_addr_module= int(parsed_cfg.get(section_name, "I2C_DACModule_Addr"), 16)
self.zeDAC_pwr=AD5665R(self.TLU_I2C, dac_addr_module)
self.zeDAC_pwr.setIntRef(self.intRefOn, self.verbose)
print "BOH"
self.writeThreshold(self.zeDAC_pwr, -1, 0, self.verbose)
self.writeThreshold(self.zeDAC_pwr, -1, 1, self.verbose)
self.writeThreshold(self.zeDAC_pwr, -1, 2, self.verbose)
self.writeThreshold(self.zeDAC_pwr, -1, 3, self.verbose)
exp1_addr= int(parsed_cfg.get(section_name, "I2C_EXP1Module_Addr"), 16)
self.ledExp1=PCA9539PW(self.TLU_I2C, exp1_addr)
self.ledExp1.setInvertReg(0, 0x00)# 0= normal, 1= inverted
self.ledExp1.setIOReg(0, 0x00)# 0= output, 1= input
self.ledExp1.setOutputs(0, 0x1F)# If output, set to XX
self.ledExp1.setInvertReg(1, 0x00)# 0= normal, 1= inverted
self.ledExp1.setIOReg(1, 0x00)# 0= output, 1= input
self.ledExp1.setOutputs(1, 0x1D)# If output, set to XX
exp2_addr= int(parsed_cfg.get(section_name, "I2C_EXP2Module_Addr"), 16)
self.ledExp2=PCA9539PW(self.TLU_I2C, exp1_addr)
self.ledExp2.setInvertReg(0, 0x00)# 0= normal, 1= inverted
self.ledExp2.setIOReg(0, 0x00)# 0= output, 1= input
self.ledExp2.setOutputs(0, 0x85)# If output, set to XX
self.ledExp2.setInvertReg(1, 0x00)# 0= normal, 1= inverted
self.ledExp2.setIOReg(1, 0x00)# 0= output, 1= input
self.ledExp2.setOutputs(1, 0x3E)# If output, set to XX
print "BLAH"
print self.ledExp2.getOutputs(1)
##################################################################################################################################
##################################################################################################################################
......
......@@ -25,6 +25,13 @@ I2C_ID_Addr = 0x50
I2C_EXP1_Addr = 0x74
#I2C address of 2st expander PCA9539PW
I2C_EXP2_Addr = 0x75
#I2C address of AD5665R on powermodule
I2C_DACModule_Addr = 0x1C
#I2C address of 1st expander PCA9539PW on powermodule
I2C_EXP1Module_Addr = 0x76
#I2C address of 2nd expander PCA9539PW on powermodule
I2C_EXP2Module_Addr = 0x77
##CONFCLOCK 0= skip clock configuration, 1= configure si5345
CONFCLOCK= 0
......
......@@ -240,7 +240,7 @@ if __name__ == "__main__":
###TLU.stop(False, False)
# Start interactive prompt
print "=+=================================================================="
print "===================================================================="
print "==========================TLU TEST CONSOLE=========================="
print "+==================================================================="
print "===================================================================="
prompt.cmdloop("Type 'help' for a list of commands.")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment