Jump to content
  • 0

scripting several protocols in waveforms


Klars

Question

I would like to write a javascript for waveforms where I control my Digital discovery from a PC via UART, the controllable functions is to write and read to some I2C slaves

Have tried using the "protocol" tool with the I2C tab and scripting. I write the script in the "sensor" tab, I found that this tab works differently from the "Custom" tab.

I2C stuff work allright but when I try to init the UART I get error "ReferenceError: Can't find variable: Protocol line: nn"

function initUart(){
    //if(!('Protocol' in this)) throw "Please open the Protocol instrument";
    Protocol.Mode.text = "UART"; // make sure UART tab is selected
    Protocol.UART.TX.value = 0; // Set up UART TX pin on Digilent AD2 :: DIO_0 Pin
    Protocol.UART.RX.value = 1; // Set up UART RX pin on Digilent AD2 :: DIO_1 Pin
    Protocol.UART.Bits.value=8; // Sets or gets the UART number of bits.
    Protocol.UART.Parity.text="None" ;// Sets or gets the parity setting: “None”, “Even”, “Odd”, “Mark (High)”, “Space (Low)”.
    Protocol.UART.Rate.value=9600;   // Sets or gets the baud rate setting
    Protocol.config(); // apply configuration changes now
    Protocol.UART.Receiver(); // reset receiver - that is too start receiving data
    if(!FileAppendLine(logfile, "UART init completed")) return "File write failed";
}

Am I trying to do something that is impossible or am I using the waveforms tool wrong?

 

Regards,

Klars

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

thank you for the help, I have progressed and am now able to initialize UART and I2C without errors. I cannot configure the pins correctly though.

Id like to use pins 24 and 25 for I2C, when setting the pins thusly they end up being 15(decimal) when read back.

I cant find any good information on the capabilities of the different ports. Can the High-speed inputs be used as outputs? I tried this but the pins are not outputting data or clock. Or perhaps there are some other way to configure pins for the Digital Discovery ( compared to the analog discovery ).

I am also unclear weather I need to use the I2C reset.

function i2c_initialise()
{
    if(!('Protocol' in this)) throw "Please open the Protocol tool window";
  //************************************************************
    // Script using Protocol I2C.
    // i2C BUS Set up 
    //************************************************************

    var I2C_reset_AD2_DIO_port =  3 ;  // Set to AD2 DIO Port which controls I2C /Reset io line
        Protocol.Mode.text = "I2C"; // make sure SPI tab is selected
        Protocol.I2C.Mode.value = 1;                       //Set the I2C Protocol tool into Master Mode
//      Protocol.I2C.SCL.setValue(24)
        Protocol.I2C.SCL.value = 24;                        //Set the SCL pin to be DIO 0
        Protocol.I2C.SDA.value = 25;                        //Set the SDA pin to be DIO 1
        Protocol.I2C.SCL.Frequency.value = 100000;         //Set the SCL clock frequency to 100 kHz
        
        //  Do not use clock stretching unless your really need it 
        // Protocol.I2C.Clockstretching.value = 1;           //Enable Clock Stretching�..  This line is  not functioning    
        // Protocol.I2C.ClockStretching.enable;                  // This is the replacement lines 
        
        Protocol.I2C.ClockStretching.value = 0;          // Disable I2C clock stretching 

        Protocol.config() // apply configuration changes now
        
        // flip the active low reset line set low then set high 
        
        set_static_io_pin(I2C_reset_AD2_DIO_port,0);
        wait(0.1); // wait 100 milli second before next instruction.
        set_static_io_pin(I2C_reset_AD2_DIO_port,1);
        wait(0.1); // wait 100 milli second before next instruction.

        // ref  https://forum.digilentinc.com/topic/4942-i2c-subaddress-not-working-properly-in-the-script-tool/    
        // Ref  https://forum.digilentinc.com/topic/21906-how-to-measure-scope-and-protocol/
        // ref  https://forum.digilentinc.com/topic/18944-reading-i2c-via-script-displays-wrong-data/
        
     print(" I2C initialised " + "\n\r" );
     print(" I2C SCL connect to DD DIO Port    " + Protocol.I2C.SCL.value + "\n\r" ) ;
     print(" I2C SDA connect to DD DIO Port    " + Protocol.I2C.SDA.value + "\n\r" ) ;
     print(" I2C /RESET port connect to DD DIO Port    "  + I2C_reset_AD2_DIO_port  + "\n\r" ) ;
     if (Protocol.I2C.ClockStretching.value==0) 
        { 
            print(" I2C Clock Stretching functionality disabled" +  "\n\r" ) ; 
        } 
        else 
        {
            print(" I2C Clock Stretching functionality enabled"+  "\n\r" ) ;
        }
     print("\n\r"+" I2C initialisation complete " + "\n\r" ) ;
}

Printed result:

Starting power supply 


 Power supply is UP
 I2C initialised 


 I2C SCL connect to DD DIO Port    15


 I2C SDA connect to DD DIO Port    15

Any tips? is there a link for scripting reference for Digital Discovery somewhere?

Edit:

Found info on DD pins:

"The Digital Discovery has 24 digital inputs (DIN 0-23) and 16 digital I/Os (DIO 24-39)."

So, I *have to* use pins 24 or above. How do I do this via script?

All the best,

Klars

Edited by Klars
found more info
Link to comment
Share on other sites

  • 0

Hi @attila,

thank you kindly for your support. I now have a stable serial terminal that allows me to control the I2C bus from putty or similar.

New obstacle: How can I script ( javascript) the restart condition for reading from a slaves subadress? Reading subadresses works nicely in the 'protocol' window but I cannot find any good javascript-info in the examples or forum.

Please advice.

 

Best Regards,

Klars

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...