Jump to content
  • 0

issue running I2C & digital IO output on Discovery 3


liu

Question

Hi Attilia,

I am trying to run I2C (IO 3&4) and have digital output (IO 5&6) as clock together. I tested each function separately and run well (except  FDwfDigitalIOOutputEnableSet bahaves oppositely to the reference as in my previous question). Yet, when I put them together, I2C always works but the digital output will stop once there is a I2C write. Below is my code (in python). 

Also, I want to set IO 6 as low (or high)  and wonder if there is simpler way than using pulse as in the code?

And I want to set FDwfDigitalOutModeSet to PP but cannot find any reference or sample code on how to do that.

Thanks. 

Yisi

# setup digital IO for trigger pattern 
print("configuring trigger")
# enable output for DIO 5, disable 6 so it is low 
dwf.FDwfDigitalIOOutputEnableSet(hdwf, c_int(0x0000)) # 1<<1
pfsOutputEnable = (c_uint*16)()
dwf.FDwfDigitalIOOutputEnableGet(hdwf, byref(pfsOutputEnable))
print("FDwfDigitalIOOutputEnableGet", pfsOutputEnable)
# set value on enabled IO pins
dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x0000)) # DIO-5&6 low
dwf.FDwfDigitalIOConfigure(hdwf)
# dwf.FDwfDigitalOutTriggerSlopeSet(hdwf, c_int(0)) # 0: rise, 1: fall, 2: either

# configure and start clock
hzSys = c_double()
dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))
print("internal frequency: ", hzSys)
# 80 Hz pulse on DIO-5
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(5), c_int(1))
# prescaler to double, SystemFrequency/xHz/2
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(5), c_int(int(hzSys.value/80/2)))
# 50% duty cycle, 1 tick low, 1 tick high
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(5), c_int(1), c_int(1))
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))

# low Hz pulse on DIO-6
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(6), c_int(1))
# prescaler to double, SystemFrequency/xHz/2
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(6), c_int(int(hzSys.value/80/2)))
# 50% duty cycle, 1 tick low, 1 tick high
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(6), c_int(1), c_int(0))
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))

print("IO configured")
time.sleep(3)

# setup I2C
print("Configuring I2C...")
iNak = c_int()
dwf.FDwfDigitalI2cRateSet(hdwf, c_double(1e5)) # 100kHz
dwf.FDwfDigitalI2cSclSet(hdwf, c_int(3)) # SCL = DIO-0
dwf.FDwfDigitalI2cSdaSet(hdwf, c_int(4)) # SDA = DIO-1
dwf.FDwfDigitalI2cClear(hdwf, byref(iNak))
if iNak.value == 0:
    print("I2C bus error. Check the pull-ups.")
    # quit()
time.sleep(1)

rgTX = (c_ubyte*16)(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
rgRX = (c_ubyte*16)()

I2C_Addresses = ""
I2Cadd = [0xa,0xd,0x44,0x49,0x4a,0x4b]
# for i in range(8,119):
for i in I2Cadd:
    # print(c_int(i<<1))
    blnCheck = dwf.FDwfDigitalI2cWriteOne(hdwf, c_int(i<<1),None, byref(iNak))
    # blnCheck = dwf.FDwfDigitalI2cRead(hdwf, c_int(i<<1), rgRX, c_int(1), byref(iNak))
    print(i, blnCheck, iNak)
    if iNak.value == 0:
        I2C_Addresses = I2C_Addresses + str(i)+" "

print("I2C addresses: ", I2C_Addresses)

print("values of output pins: ", dwf.FDwfDigitalIOOutputGet(hdwf, 0x00))
time.sleep(0.1)

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi @liu

image.png

The protocols take control over digital-out and in device resource.
You can use the digital-io functions to control the DIOs.
You can use the trigger IOs to output a reference clock between 10-50MHz
You can also use the analog-out to generate digital clock with pulse signal 3.3V amplitude.

Link to comment
Share on other sites

  • 0

Thanks for the response.

So you mean I cannot have I2C and Digital Output at the same time. Is there a way to disable I2C after I setup my board so I can turn on Digital output? Which command should I use?

The frequency I am trying to generate is 100Hz so the trigger IO is way too fast for me. And I am already using the two analog-out channels for other functions. 

Best,

Yisi

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...