Examples of scripts for SP1000G

In this section, you will see how to generate a UART, I2C and SPI sentence/bus. To do so, we’ll use scripts concerning these protocols, and more precisely their Objet Builder.

It would be better to have read the previous section - about the structure of a script for a SP1000G series device, in addition to the construction of an Object Builder in Signal Builder chapter.

UART

UART in a nutshell

Here is some information about UART (Universal Asynchronous Reception and Transmission) :

  • Serial communication protocol : uses one or two transmission lines to send and receive data, and that data is continuously sent and received one bit at a time,

  • Bidirectional and full-duplex : allows data transfer in both directions and simultaneously, so it can transmit data in three ways :
    • In both directions simultaneously,
    • In both directions but not simultaneously,
    • In one direction.
  • Asynchronous : transmission doesn’t require a clock,

  • Exclusive : there is only one wire passing all the data bits, and a master can only discuss with a single slave per wire,

  • Communication is carried out by two lines :
    • to transmit data (TX),
    • to receive data (RX).
  • A frame is composed of :
    • A start bit always at 0: used for synchronization of the receiver,
    • Data size is between 5 and 9 bits, with bits sent from LSB to MSB,
    • A parity bit,
    • A stop bit, always at 1.
  • Example : communication between PC and USB.

Script

  • First, you have to set your UART channel. Here, we’ll call it ch_uart and initialize it on the first channel :
function on_pattern_generate()
{
    var ch_uart = 0 ;
}
  • Then, you must set these channels electrically. For instance, you can have :
    • Output voltage : 3300 mV,
    • Idle state : 0,
    • Output type : push_pull.
function on_pattern_generate()
{
    //...
    ScanaStudio.builder_set_out_voltage(ch_uart, 3300);
    ScanaStudio.builder_set_idle_state(ch_uart, 1);
    ScanaStudio.builder_set_io(ch_uart, ScanaStudio.io_type.push_pull);
}
  • Then, we’ll use a Builder Object, which is a group of “helper functions” used to build signals for a specific protocol or application. Here, the point is not to create a Builder Object but to use one.

    The ability to instantiate several objects - here with the object uart_builder - gives a lot of flexibility and allows easy code recycling. One big advantage of this method is that you may load different builder objects from different files, hence building very sophisticated signals using few, simple, easy to read lines of code.

    Making use of an existing builder object from another script implies calling the function ScanaStudio.load_builder_object(script). Therefore, we will create a get_builder_object() function that will call the UART’s Builder Object, which already exists in the script “uart.js”, and that returns an UART’s Builder Object called builder.

    Thus, we’ll call this function to create uart_builder.

function on_pattern_generate()
{
    //...
    var uart_builder = get_builder_object() ;
}

function get_builder_object()
{
    var builder = ScanaStudio.load_builder_object("uart.js") ;
    return builder ;
}
  • Then, you have to configure this object by filling in the parameters. To know the parameters you have to write the configuration (and their order), you can look in the script how the Builder Object is constructed (here in uart.js, at the end of the script).

    Here, for the SPI’s builder, you have to set the following parameters :

    • Channel,
    • Bauds,
    • Number of bits per transfer
    • Parity bit (0 for no parity bit, 1 for odd parity, 2 for even parity),
    • Stop bit (1, 1.5 or 2 stop bits),
    • Bit order (0 for LSB first, 1 for MSB first),
    • Inverted logic (0 for not inverted logic, 1 for all signals inverted, 2 for only data inverted)
    • Sample rate.

    In this example, we will set the parameters as shown below :

function on_pattern_generate()
{
    //...
    uart_builder.config(
          /*PLEASE SET CHANNEL*/
          /*0 to 17*/
          ch_uart,
          /*PLEASE SET BAUD*/
          9600,
          /*PLEASE SET NUMBER OF BITS PER TRANSFER*/
          8,
          /*PLEASE SET PARITY BIT*/
          /*=0 for no parity bit, =1 for odd parity bit, =2 for even parity bit*/
          0,
          /*PLEASE SET STOP BITS BIT VALUE*/
          /*=1, 1,5 or 2 stop bits*/
          1,
          /*PLEASE SET BIT ORDER*/
          /* =0 for LSB first, =1 for MSB first*/
          0,
          /*PLEASE SET INVERTED LOGIC OR NOT*/
          /*=0 for not inverted logic, =1 for all signals inverted, =2 for only data inverted*/
          0,
          /*SAMPLE RATE*/
          Number(ScanaStudio.builder_get_sample_rate())
    );
}
  • Then, we can create a sentence, and thanks to the Builder Object’s function, the sentence will be sent :
function on_pattern_generate()
{
    //...
    var sentence = "Hello world, please enter a sentence here !" ; // enter the sentence to send
    uart_builder.put_str(sentence) ;
}
  • Finally, you have finished to add all the samples you wanted to build your signal (made in Builder Object), so you can send the chunk :
function on_pattern_generate()
{
    //...
    ScanaStudio.builder_set_repeat_count(1) ;
    ScanaStudio.builder_start_chunk() ;
    ScanaStudio.builder_wait_done(500) ;
    ScanaStudio.console_info_msg("Last chunk sent") ;

    return ;
}
  • Now, we will add on_draw_gui_pattern_generator() and on_eval_gui_pattern_generator() entry point functions to show when they are displayed on your screen. To resume, the script of this example will be :
function on_draw_gui_pattern_generator()
{

}

function on_eval_gui_pattern_generator()
{
    return "";
}

function on_pattern_generate()
{
    /*ELECTRICAL SETTINGS*/

    var ch_uart = 0;

    ScanaStudio.builder_set_out_voltage(ch_uart, 3300);
    ScanaStudio.builder_set_idle_state(ch_uart, 1);
    ScanaStudio.builder_set_io(ch_uart, ScanaStudio.io_type.push_pull);
    ScanaStudio.builder_add_samples(ch_uart, 1, 100);

    /*OBJECT BUILDER*/

    var uart_builder = get_builder_object();

    uart_builder.config(
          /*PLEASE SET CHANNEL*/
          /*0 to 17*/
          ch_uart,
          /*PLEASE SET BAUD*/
          9600,
          /*PLEASE SET NUMBER OF BITS PER TRANSFER*/
          8,
          /*PLEASE SET PARITY BIT*/
          /*=0 for no parity bit, =1 for odd parity bit, =2 for even parity bit*/
          0,
          /*PLEASE SET STOP BITS BIT VALUE*/
          /*=1, 1,5 or 2 stop bits*/
          1,
          /*PLEASE SET BIT ORDER*/
          /* =0 for LSB first, =1 for MSB first*/
          0,
          /*PLEASE SET INVERTED LOGIC OR NOT*/
          /*=0 for not inverted logic, =1 for all signals inverted, =2 for only data inverted*/
          0,
          /*SAMPLE RATE*/
          Number(ScanaStudio.builder_get_sample_rate())
    );

    /*SENTENCE TO SEND*/

    var sentence = "Hello world, please enter a sentence here !" ; // enter the sentence to send
    uart_builder.put_str(sentence);

    /*SENDTO SP1018G*/

    ScanaStudio.builder_set_repeat_count(1);
    ScanaStudio.builder_start_chunk();
    ScanaStudio.builder_wait_done(500);
    ScanaStudio.console_info_msg("Last chunk sent");

    return;
}

function get_builder_object()
{
    var builder = ScanaStudio.load_builder_object("uart.js");
    return builder;
}
  • You can finally launch it on ScanaStudio and add UART protocol. Moreover, you can see your sentence in View, then HexView :

SPI example for Pattern Generator

I2C

I2C in a nutshell

Here is some information about I2C (Inter-Integrated Circuit) :

  • Serial communication protocol : uses one or two transmission lines to send and receive data, and that data is continuously sent and received one bit at a time,

  • Bidirectional and half-duplex : allows data transmission in both directions but not simultaneously,

  • Synchronous : clock transmission,

  • Not exclusive : data exchange takes place between a master and one or more slaves (up to 128),

  • Communication is carried out by two lines :
    • The bidirectional data line (SDA),
    • Bidirectional synchronization clock line (SCL),
    • Electrical reference signal (Ground).
  • A frame is composed of :
    • At rest : SDA and SCL are at level 1, no circuit is transmitting,
    • Start : SDA goes to 0 when SCL = 1,
    • Address : From the moment SCL goes to 0, the 7 bits of the slave address are set, validated by the 7 SCL clock ticks,
    • R/W : The 8th clock tick indicates to the slave whether the master will read (R=1) or write (W=0),
    • ACK : The 9th stroke of the clock validates the request from the master, which awaits the response,
    • Data : If the response is sent by the slave, the 8 data bits arrive followed by an ACK if it is the end of the slave transmission,
    • Stop : SCL then goes to 1 followed by SDA and we return to idle.
  • Examples : used for communication between several different parts like : sensors, drivers, modules…

Script

  • First, you have to initialize two channels :
    • SDA (data) : ch_sda, we’ll set it to 0,
    • SCL (clock) : ch_scl, we’ll set it to 1,
function on_pattern_generate()
{
    var ch_sda = 0 ;     //for data
    var ch_scl = 1 ;     // for clock
}
  • Then, you must set these channels electrically. For instance, you can set :
    • Output voltage : 3300 mV,
    • Idle state : 0,
    • Output type : push_pull.
function on_pattern_generate()
{
    //...
    ScanaStudio.builder_set_out_voltage(ch_sda, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_sda, 0) ;
    ScanaStudio.builder_set_io(ch_sda, ScanaStudio.io_type.push_pull) ;

    ScanaStudio.builder_set_out_voltage(ch_scl, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_scl, 0) ;
    ScanaStudio.builder_set_io(ch_scl, ScanaStudio.io_type.push_pull) ;
}
  • Then, we’ll use a Builder Object, which is a group of “helper functions” used to build signals for a specific protocol or application. Here, the point is not to create a Builder Object but to use one.

    The ability to instantiate several objects - here with the object i2c_builder - gives a lot of flexibility and allows easy code recycling. One big advantage of this method is that you may load different builder objects from different files, hence building very sophisticated signals using few, simple, easy to read lines of code.

    Making use of an existing builder object from another script implies calling the function ScanaStudio.load_builder_object(script). Therefore, we will create a get_builder_object() function that will call the I2C’s Builder Object, which already exists in the script “i2c.js”, and that returns an I2C’s Builder Object called builder.

    Thus, we’ll call this function to create i2c_builder.

function on_pattern_generate()
{
    //...
    var i2c_builder = get_builder_object() ;
}

function get_builder_object()
{
    var builder = ScanaStudio.load_builder_object("i2c.js") ;
    return builder ;
}
  • Then, you have to configure this object by filling in the parameters. To know the parameters you have to write the configuration (and their order), you can look in the script how the Builder Object is constructed (here in i2c.js, at the end of the script).

    Here, for the I2C’s builder, you have to set the following parameters :

    • SDA channel,
    • SCL channel,
    • Clock frequency.

    In this example we will set the parameters as shown below :

function on_pattern_generate()
{
    //...
    var i2c_f = ScanaStudio.builder_get_sample_rate()/100 ; //clock frequency
    i2c_builder.config(ch_scl,ch_sda,i2c_f) ;
}
  • Then, based on the on_build_demo_signals() entry point function of i2c.js script, we can write a random signal, by using the Object Builder’s functions :
function on_pattern_generate()
{
    //...
    i2c_builder.put_silence(2048);  //enter a value

    i2c_builder.put_start();        //start when SCA goes to 0 and SCL goes to 1
    i2c_builder.put_byte(0xF7,0);   //10b address
    i2c_builder.put_byte(0xFF,0);
    i2c_builder.put_byte(0x55,1);   //stop when SCA goes to 1 and SCL goes to 1
    i2c_builder.put_stop();         //stop when SCA goes to 1 and SCL goes to 1
    i2c_builder.put_silence(2048);

    i2c_builder.put_start();
    i2c_builder.put_byte(0x00,0);   //General call address
    i2c_builder.put_byte(0xA1,0);
    i2c_builder.put_byte(0x55,1);
    i2c_builder.put_stop();
    i2c_builder.put_silence(2048);

    i2c_builder.put_start();
    i2c_builder.put_byte(0x01,0);   //Star byte call address
    i2c_builder.put_start();
    i2c_builder.put_byte(0xA1,0);
    i2c_builder.put_byte(0x55,1);
    i2c_builder.put_stop();
    i2c_builder.put_silence(2048);

    i2c_builder.put_start();
    i2c_builder.put_byte(0x08,0);   //HS mode
    i2c_builder.put_start();
    i2c_builder.put_byte(0xA1,0);
    i2c_builder.put_byte(0x55,1);
    i2c_builder.put_stop();
    i2c_builder.put_silence(2048);

    i2c_builder.put_start();
    i2c_builder.put_byte(0x07,0);   //RFU
    i2c_builder.put_byte(0xA1,0);
    i2c_builder.put_byte(0x55,1);
    i2c_builder.put_stop();
    i2c_builder.put_silence(2048);
}
  • Finally, you have finished to add all the samples you wanted to build your signal (made in Builder Object), so you can send the chunk :
function on_pattern_generate()
{
    //...
    ScanaStudio.builder_set_repeat_count(1) ;
    ScanaStudio.builder_start_chunk() ;
    ScanaStudio.builder_wait_done(500) ;
    ScanaStudio.console_info_msg("Last chunk sent") ;

    return ;
}
  • Now, we will add on_draw_gui_pattern_generator() and on_eval_gui_pattern_generator() entry point functions to show when they are displayed on your screen. To resume, the script of this example will be :
function on_draw_gui_pattern_generator()
{

}

function on_eval_gui_pattern_generator()
{
  return ""; //All good.
}

function on_pattern_generate()
{
    /*OUTPUT SETTINGS*/

    /*PLEASE ENTER A CHANNEL FOR SDA AND SCL*/
    /*0 to 17*/

    var ch_sda = 0 ;     //for data
    var ch_scl = 1 ;     // for clock

    ScanaStudio.builder_set_out_voltage(ch_sda, 3300);
    ScanaStudio.builder_set_idle_state(ch_sda, 0);
    ScanaStudio.builder_set_io(ch_sda, ScanaStudio.io_type.push_pull);

    ScanaStudio.builder_set_out_voltage(ch_scl, 3300);
    ScanaStudio.builder_set_idle_state(ch_scl, 0);
    ScanaStudio.builder_set_io(ch_scl, ScanaStudio.io_type.push_pull);

    /*BUILDER OBJECT*/

    var i2c_f = ScanaStudio.builder_get_sample_rate()/100; //clock frequency

    var i2c_builder = get_builder_object();
    i2c_builder.config(ch_scl,ch_sda,i2c_f);

    /*BUS*/

    //address : even = write, odd=read

    i2c_builder.put_silence(2048);  //enter a value

    i2c_builder.put_start();        //start when SCA goes to 0 and SCL goes to 1
    i2c_builder.put_byte(0xF7,0);   //10b address
    i2c_builder.put_byte(0xFF,0);
    i2c_builder.put_byte(0x55,1);   ////stop when SCA goes to 1 and SCL goes to 1
    i2c_builder.put_stop();         //stop when SCA goes to 1 and SCL goes to 1
    i2c_builder.put_silence(2048);

    i2c_builder.put_start();
    i2c_builder.put_byte(0x00,0); //General call address
    i2c_builder.put_byte(0xA1,0);
    i2c_builder.put_byte(0x55,1);
    i2c_builder.put_stop();
    i2c_builder.put_silence(2048);

    i2c_builder.put_start();
    i2c_builder.put_byte(0x01,0); //Star byte call address
    i2c_builder.put_start();
    i2c_builder.put_byte(0xA1,0);
    i2c_builder.put_byte(0x55,1);
    i2c_builder.put_stop();
    i2c_builder.put_silence(2048);

    i2c_builder.put_start();
    i2c_builder.put_byte(0x08,0); //HS mode
    i2c_builder.put_start();
    i2c_builder.put_byte(0xA1,0);
    i2c_builder.put_byte(0x55,1);
    i2c_builder.put_stop();
    i2c_builder.put_silence(2048);

    i2c_builder.put_start();
    i2c_builder.put_byte(0x07,0); //RFU
    i2c_builder.put_byte(0xA1,0);
    i2c_builder.put_byte(0x55,1);
    i2c_builder.put_stop();
    i2c_builder.put_silence(2048);

    /*SENDING TO SP1018G*/

    ScanaStudio.builder_set_repeat_count(1);
    ScanaStudio.builder_start_chunk();
    ScanaStudio.builder_wait_done(500);
    ScanaStudio.console_info_msg("Last chunk sent");

    return ;
}

function get_builder_object()
{
    var builder = ScanaStudio.load_builder_object("spi.js") ;
    return builder ;
}
  • You can finally launch it on ScanaStudio and add UART protocol :

SPI example for Pattern Generator

SPI

SPI in a nutshell

Here is some information about SPI (Serial Peripheral Interface) :

  • Serial communication protocol : uses one or two transmission lines to send and receive data, and that data is continuously sent and received one bit at a time,

  • Bidirectional and full-duplex : allows data transfer in both directions and simultaneously,

  • Synchronous : clock transmission,

  • Not exclusive : communicate according to a master-slave scheme. Several slaves can coexist on the same bus, and the recipient is selected thanks to a dedicated line between the master and the slave called Chip Select (CS),

  • Communication is carried out by two lines :
    • Master Output Slave Input (MOSI), generated by the master,
    • Master Input Slave Output (MISO), generated by the slaves,
    • SPI serial clock (SCK),
    • The slaves are identified thanks to the signal of their SS (Slave Select) line, linked to Chip Select (CS).
  • Examples : for applications that require a high data rate (for instance, to read a memory).

Script

  • First, you have to initialize four channels :
    • MOSI : ch_mosi, we’ll set it to 0,
    • MISO : ch_miso, we’ll set it to 1,
    • SCK : ch_sck, we’ll set it to 2,
    • CS : ch_cs, we’ll set it to 3.
function on_pattern_generate()
{
    var ch_mosi = 0;
    var ch_miso = 1;
    var ch_clock = 2;
    var ch_cs = 3;
}
  • Then, you must set these channels electrically. For instance, you can set :
    • Output voltage : 3300 mV,
    • Idle state : 0,
    • Output type : push_pull.
function on_pattern_generate()
{
    //...
    ScanaStudio.builder_set_out_voltage(ch_mosi, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_mosi, 0) ;
    ScanaStudio.builder_set_io(ch_mosi, ScanaStudio.io_type.push_pull) ;

    ScanaStudio.builder_set_out_voltage(ch_miso, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_miso, 0) ;
    ScanaStudio.builder_set_io(ch_miso, ScanaStudio.io_type.push_pull) ;

    ScanaStudio.builder_set_out_voltage(ch_clock, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_clock, 0) ;
    ScanaStudio.builder_set_io(ch_clock, ScanaStudio.io_type.push_pull) ;

    ScanaStudio.builder_set_out_voltage(ch_cs, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_cs, 0) ;
    ScanaStudio.builder_set_io(ch_cs, ScanaStudio.io_type.push_pull) ;
}
  • Then, we’ll use a Builder Object, which is a group of “helper functions” used to build signals for a specific protocol or application. Here, the point is not to create a Builder Object but to use one.

    The ability to instantiate several objects - here with the object spi_builder - gives a lot of flexibility and allows easy code recycling. One big advantage of this method is that you may load different builder objects from different files, hence building very sophisticated signals using few, simple, easy to read lines of code.

    Making use of an existing builder object from another script implies calling the function ScanaStudio.load_builder_object(script). Therefore, we will create a get_builder_object() function that will call the SPI’s Builder Object, which already exists in the script “spi.js”, and that returns an SPI’s Builder Object called builder.

    Thus, we’ll call this function to create spi_builder.

function on_pattern_generate()
{
    //...
    var spi_builder = get_builder_object() ;
}

function get_builder_object()
{
    var builder = ScanaStudio.load_builder_object("spi.js") ;
    return builder ;
}
  • Then, you have to configure this object by filling in the parameters. To know the parameters you have to write the configuration (and their order), you can look in the script how the Builder Object is constructed (here in spi.js, at the end of the script).

    Here, for the SPI’s builder, you have to set the following parameters :

    • MOSI channel,
    • MISO channel,
    • Clock channel,
    • CS channel,
    • Bit order (0 for MSB first, 1 for LSB first),
    • Clock polarity (0 for clock LOW when inactive, 1 for clock HIGH when inactive),
    • Clock phase (0 for data samples on leading edge, 1 for data samples on trailing edge),
    • Number of bits per word,
    • Chip select (0 for active LOW, 1 for active HIGH),
    • Sample rate (can be obtained with ScanaStudio.builder_get_sample_rate()),
    • Clock frequency.

    In this example we will set the parameters as shown below :

function on_pattern_generate()
{
    //...
    spi_builder.config(
        /*PLEASE SET CHANNEL (0 TO 17)*/
        /*for MOSI channel*/
        ch_mosi,
        /*for MISO channel*/
        ch_miso,
        /*for CLOCK channel*/
        ch_clock,
        /*for CS channel*/
        ch_cs,
        /*PLEASE SET BIT ORDER*/
        /*=0 for MSB first, =1 for LSB first*/
        1,
        /*PLEASE SET CLOCK POLARITY*/
        /*=0 for clock LOW when inactive, =1 for clock HIGH when inactive*/
        0,
        /*PLEASE SET CLOCK PHASE*/
        /*=0 for data samples on leading edge, =1 for data samples on trailing edge*/
        0,
        /*PLEASE SET NUMBER OF BITS PER WORD*/
        8,
        /*PLEASE SET CHIP SELECT*/
        /*=0 for active LOW, =1 for active HIGH*/
        0,
        /*SAMPLING RATE*/
        ScanaStudio.builder_get_sample_rate(),
        /*cLOCK FREQUENCY*/
        ScanaStudio.builder_get_sample_rate()/100
    ) ;
}
  • Then, based on the on_build_demo_signals() entry point function of spi.js script, we can write a random signal :
function on_pattern_generate()
{
    //...
    var random_mosi, random_miso, random_size, w ;
    spi_builder.put_silence(10e-6) ;
    random_size = Math.floor(Math.random()*10) + 1 ;
    spi_builder.put_start() ;
    spi_builder.put_silence(1e-6) ; //1 us


    for (w = 0; w < random_size; w++)
    {
        random_mosi = Math.floor(Math.random()*(Math.pow(2,8))) ;
        random_miso = Math.floor(Math.random()*(Math.pow(2,8))) ;
        spi_builder.put_word(random_mosi,random_miso) ;
        spi_builder.put_silence(1e-6) ; //1 us
    }

    spi_builder.put_stop() ;
    spi_builder.put_silence(1e-6) ;

    if (ScanaStudio.abort_is_requested())
    {
        break ;
    }
}
  • Finally, you have finished to add all the samples you wanted to build your signal (made in Builder Object), so you can send the chunk :
function on_pattern_generate()
{
    //...
    ScanaStudio.builder_set_repeat_count(1) ;
    ScanaStudio.builder_start_chunk() ;
    ScanaStudio.builder_wait_done(500) ;
    ScanaStudio.console_info_msg("Last chunk sent") ;

    return ;
}
  • Now, we will add on_draw_gui_pattern_generator() and on_eval_gui_pattern_generator() entry point functions to show when they are displayed on your screen. To resume, the script of this example will be :
function on_draw_gui_pattern_generator()
{

}

function on_eval_gui_pattern_generator()
{
    return "" ; //All good.
}

function on_pattern_generate()
{

    /*INITIALIZE CHANNELS*/

    var ch_mosi = 0;
    var ch_miso = 1;
    var ch_clock = 2;
    var ch_cs = 3;


    /*ELECTRICAL SETTINGS*/

    ScanaStudio.builder_set_out_voltage(ch_mosi, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_mosi, 0) ;
    ScanaStudio.builder_set_io(ch_mosi, ScanaStudio.io_type.open_drain) ;

    ScanaStudio.builder_set_out_voltage(ch_miso, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_miso, 0) ;
    ScanaStudio.builder_set_io(ch_miso, ScanaStudio.io_type.open_drain) ;

    ScanaStudio.builder_set_out_voltage(ch_clock, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_clock, 0) ;
    ScanaStudio.builder_set_io(ch_clock, ScanaStudio.io_type.open_drain) ;

    ScanaStudio.builder_set_out_voltage(ch_cs, 3300) ;
    ScanaStudio.builder_set_idle_state(ch_cs, 0) ;
    ScanaStudio.builder_set_io(ch_cs, ScanaStudio.io_type.open_drain) ;


    /*OBJECT BUILDER*/

    var spi_builder = get_builder_object() ;

    spi_builder.config(
        /*PLEASE SET CHANNEL (0 TO 17)*/
        /*for MOSI channel*/
        ch_mosi,
        /*for MISO channel*/
        ch_miso,
        /*for CLOCK channel*/
        ch_clock,
        /*for CS channel*/
        ch_cs,
        /*PLEASE SET BIT ORDER*/
        /*=0 for MSB first, =1 for LSB first*/
        1,
        /*PLEASE SET CLOCK POLARITY*/
        /*=0 for clock LOW when inactive, =1 for clock HIGH when inactive*/
        0,
        /*PLEASE SET CLOCK PHASE*/
        /*=0 for data samples on leading edge, =1 for data samples on trailing edge*/
        0,
        /*PLEASE SET NUMBER OF BITS PER WORD*/
        8,
        /*PLEASE SET CHIP SELECT*/
        /*=0 for active LOW, =1 for active HIGH*/
        0,
        /*SAMPLING RATE*/
        ScanaStudio.builder_get_sample_rate(),
        /*cLOCK FREQUENCY*/
        ScanaStudio.builder_get_sample_rate()/100
    );


      /*SIGNAL EXAMPLE*/

      var random_mosi, random_miso, random_size, w ;
      spi_builder.put_silence(10e-6) ;
      random_size = Math.floor(Math.random()*10) + 1 ;
      spi_builder.put_start() ;
      spi_builder.put_silence(1e-6) ; //1 us


      for (w = 0; w < random_size; w++)
      {
          random_mosi = Math.floor(Math.random()*(Math.pow(2,8))) ;
          random_miso = Math.floor(Math.random()*(Math.pow(2,8))) ;
          spi_builder.put_word(random_mosi,random_miso) ;
          spi_builder.put_silence(1e-6) ; //1 us
      }

      spi_builder.put_stop() ;
      spi_builder.put_silence(1e-6) ;

      if (ScanaStudio.abort_is_requested())
      {
          break ;
      }


    /*SENDING TO SP1018G*/

    ScanaStudio.builder_set_repeat_count(1) ;
    ScanaStudio.builder_start_chunk() ;
    ScanaStudio.builder_wait_done(500) ;
    ScanaStudio.console_info_msg("Last chunk sent") ;

    return ;
}

function get_builder_object()
{
    var builder = ScanaStudio.load_builder_object("spi.js") ;
    return builder ;
}
  • You can finally launch it on ScanaStudio and add SPI protocol :

SPI example for Pattern Generator