This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Read / Write SPI register via WaveVision DLL

Other Parts Discussed in Thread: WAVEVISION5, ADC10D1000

Someone out there ever tried to write one of the SPI registers via the WaveVision DLL?

I'd like to write e.g. the Q-Channel Offset register of the ADC12D1800RFRB.

If I understand ...\WaveVision5\hardware\scripts\adc10d1000_xc4vlx25_adc12d1800rfrb.reg.xml correctly, the adress of the Q-Channel Offset register is "0x0a"  on the "spi" address space.

So I try the following:

const WvWord q_ch_ofs_addr = 0x0a;
WvWord q_ch_ofs_value = 123;

WvNewestHardwareWrite(0,0,WV_DEBUG_ACCESS_SPI,0,0,8,q_ch_ofs_addr,16,q_ch_ofs_value);

...with no success :-(

Anybody any ideas? Thanks a lot for your help!

  • Garelli,

    I think the issue is that you must first configure the Cypress controller to properly route the SPI commands to the ADC. I am attaching an implementation of the WV5 DLL in Python. Please see the SPITool class and function 'write_to_spi' near the bottom of the file. Note that the Cypress is configured before making the SPI command. Also note that there are two ways to implement the SPI command, through the generic function call WvNewestHardwareWrite, or through a series of calls to the same function which we consider as bit-banging.

    Regards, Josh

    3107.tools.zip

  • Hello Josh,

    I'm trying also to write the registers of the ADC through the SPI by using the dll.

    Hier is my code in matlab of your example. 

    data = 16;
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIINTCONFIGREG,8,uint32(data));
    pause(0.25);

    % Set Address example from TI set SPI ADDr HIGH register (0xD023-53283)
    % SPIACCESS = uint32(16777217);
    address= 53283;
    data = bin2dec('00000111');
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,SPIACCESS,board_index,uint32(0),8,uint32(address),8,uint32(data));

    The first command runs without problem (Microcontroller was prepared to write on the SPI) but  when i try to write to the SPI, as in your example by using the API, the following error appears on the debug:

    13/09/26:14:35:04.0124:CMD_API:==== Starting new command ====
    13/09/26:14:35:04.0124:CMD_API:Waiting for API
    13/09/26:14:35:04.0124:CMD_API:Posting command
    13/09/26:14:35:04.0139:CMD:Processing ...
    13/09/26:14:35:04.0139:CMD:Dll_Debug_Access_Write.
    13/09/26:14:35:04.0139:CMD:Addr: d023 Data: ff
    13/09/26:14:35:04.0139:XML_LIB:[Line:85c Element:interface] access method not found:spi_wr:0
    13/09/26:14:35:04.0139:XML_LIB:[Line:85c Element:interface] access method not found:spi_wr
    13/09/26:14:35:04.0139:GEN:Default SPI access not found in device-specific register file.
    13/09/26:14:35:04.0139:GEN:Load generic register file.
    13/09/26:14:35:04.0139:GEN:Parsing default.
    13/09/26:14:35:04.0139:GEN:Opening XML:hardware\scripts\adc10d1000_general_access.xml
    13/09/26:14:35:04.0139:GEN:XML not found:hardware\scripts\adc10d1000_general_access.xml
    13/09/26:14:35:04.0139:XML_LIB:[Line:85c Element:interface] access method not found:spi_wr
    13/09/26:14:35:04.0139:GEN:Debug: general access method not defined
    13/09/26:14:35:04.0139:CMD:return:DLL_COMMAND_RET_ERROR
    13/09/26:14:35:04.0155:CMD_API:Ack received. Releasing API.
    13/09/26:14:35:04.0155:CMD_API:==== Command complete ====

    As i can see, there is a problem with the acess method.

    Is the access method for the SPI correct (16777217)?

    Where is my error?

    Thanks for your help and best regards

  • Gustavo,

    It appears that maybe some files are not in the correct relative locations. The DLL requires access to the \hardware directory and that directory must be at the same level as the DLL file in the file system. I can see from your errors that the 'spi_wr' command is not found and that the XML file for the board is not found. These are flags in my mind that the DLL cannot find the necessary files that are stored in the \hardware directory.

    Regards, josh

  • Hi Josh,

    I have al the files that come with the wavevision on the hardware directory.

    but this one is not on my list.

    adc10d1000_general_access.xml

    Do you know where can i find it?

    Best regards and thanks for your help.

    Gustavo

  • Hi Gustavo,

    thanks for your PM. I will try and answer here, though.

    I wasn't able to get things to work, I finally gave up on setting the Q-Channel Offset register via Matlab.

    As a workaround I (manually) setup things with the WaveVision GUI, running my Matlab stuff afterwards.

    Anyhow, I attached my latest Matlab code, hoping it might help you somehow.

    If you can solve the SPI register access via Matlab it would be great if you would post your solution here!

    Cheers,
    Garelli

  • Hi Josh,

    I coud'nt manage to read and write the registers of the ADC via SPI by using the API so  I'm trying now to read at least a register by using bit baging.

    I want to read the FSR register of the Q channel (0xbh) that should be by default in (0100000000000000-800mV).

    But when I read it, the function says that the value is (1111111111111111). It is not possible, becaus, according to the datasheet, the MSB is always 0.

    Any idea where the problem is? do i have to activate something else to read/write the registers of the ADC via SPI?

    Hier is my matlab code, it is based on the example that you posted:

    address=bin2dec('1011'); %0XBh
    SCSB_pol='1';
    bitbang=1;
    reg_return=[];

    if bitbang==1
    command_r=['1' dec2bin(address) ];


    %Initialize SPI Manual control register variable, initialize bit fields

    SDO='0';
    SDI='0';
    SCLK='0'; %Start clock low
    SCSB=xor('1',SCSB_pol);
    SCSB=num2str(SCSB);
    OBEN='0'; %Start output buffer off
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);

    %configure SPI Interface Configuration register (0XD022) for manual
    %mode
    data = 0;%manual mode
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIINTCONFIGREG,8,uint32(data));
    if status==0
    disp('Error configuring SPI interface register')
    return
    end
    pause(0.25);

    %Enable the output buffer
    OBEN='1';
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));
    if status==0
    disp('Error configuring SPI manual control register')
    return
    end
    pause(0.25);

    %Assert SCLK (SCS High)
    SCLK='1';
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;%manual mode
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));
    if status==0
    disp('Error configuring SPI manual control register')
    return
    end
    pause(0.25);

    %Enable the device (SCS low and SCLK high)
    SCSB=xor('0',SCSB_pol);
    SCSB=num2str(SCSB);
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;%manual mode
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));
    if status==0
    disp('Error configuring SPI manual control register')
    return
    end
    pause(0.25);
    %Send Address
    for bit=1:length(command_r)
    %Assert the SDI line and deassert SCLK
    SDI=command_r(bit);
    SCLK='0';
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));

    %Assert SCLK (SCS High)
    SCLK='1';
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));
    end



    %Read SDO Line
    for bit=1:length(dec2bin(data_r))
    %Deassert SCLK

    SCLK='0';
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));

    %Assert SCLK
    SCLK='1';
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;%manual mode
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));

    %Read SDO value from SPI manual register
    ptr1 = libpointer('uint32Ptr',uint32(0));
    [status,Return] = calllib('wvdll','WvNewestHardwareRead',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,ptr1);

    %Get SDO and store char to reg_return
    SDO=dec2bin(Return);
    SDO=SDO(1);
    reg_return=[reg_return SDO];

    end



    %Deassert SCLK
    SCLK='0';
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;%manual mode
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));

    %Disable the device
    SCSB=xor('1',SCSB_pol);
    SCSB=num2str(SCSB);
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));

    %Disable the output buffer
    OBEN='0';
    reg_value=bin2dec([OBEN SCSB SCLK SDI SDO]);
    data = reg_value;%manual mode
    status = calllib('wvdll','WvNewestHardwareWrite',0,0,CYPRESSACCESS,board_index,dut_index,16,SPIMANREG,8,uint32(data));

    End

    Hier is the part of the debuging every time that i read one bit of the register:It seems to work.

    13/10/01:10:03:53.0448:CMD_API:==== Starting new command ====
    13/10/01:10:03:53.0448:CMD_API:Waiting for API
    13/10/01:10:03:53.0448:CMD_API:Posting command
    13/10/01:10:03:53.0448:CMD:Processing ...
    13/10/01:10:03:53.0448:CMD:Dll_Debug_Access_Write.
    13/10/01:10:03:53.0448:CMD:Addr: d021 Data: 17
    13/10/01:10:03:53.0448:CMD:return:DLL_COMMAND_RET_OK
    13/10/01:10:03:53.0448:CMD_API:Ack received. Releasing API.
    13/10/01:10:03:53.0448:CMD_API:==== Command complete ====

    13/10/01:10:03:53.0463:CMD_API:==== Starting new command ====
    13/10/01:10:03:53.0463:CMD_API:Waiting for API
    13/10/01:10:03:53.0463:CMD_API:Posting command
    13/10/01:10:03:53.0463:CMD:Processing ...
    13/10/01:10:03:53.0463:CMD:Addr: d021 Data: 16
    13/10/01:10:03:53.0463:CMD:return:DLL_COMMAND_RET_OK
    13/10/01:10:03:53.0463:CMD_API:Ack received. Releasing API.
    13/10/01:10:03:53.0463:CMD_API:==== Command complete ====

    Thanks for your help and best regards,

    Gustavo

  • Hello Josh and Garelli,

    I managed to write the registers of the ADC by using the SPI interface of the wavevision DLL and an interface with matlab.

    Hier you can find the code.

    @ Josh

    It works only with bit banging, and i have to say that your code in Phyton has some errors.

    The API function doesn'nt even work on the Wavevision 5. I tried to write and read the registers of the ADC with the panel control of wave vision 5, but there is always an error message.

    Hier you can find my code in Matlab.

    Best regards,

    Gustavo

    ADC_Project.rar
  • Gustavo,

    I'm trying to capture the data using MATLAB on the LM97600RB board and your code looks interesting. What potential changes should I keep in mind when working on a different board to the one that you've used ?

    Regards,

    Syed

  • Hi Syed,

    sorry for the late answer.

    If your board use the wave vision, then in theory you could use my code to drive your board with Matlab.

    You just have to take care about the configuration of the registers if you are going to use an external clock source as im my case (the registers in your ADC are different) and the configuration of the capture mode (non DES I+Q mode in my case).

    I hope it works also for you.

    Best regards,

    Gustavo

  • Thanks for the response. The board does use WaveVision. I tried using only the initialization part of your cgmode just to ensure that I'm able to interact with the board but I don't think the code is able to recognize the board being detected. I've pasted the output from the log:

    13/11/11:20:18:32.0251:SCRIPT_EP:__log.txt not found: Logs not enabled
    13/11/11:20:18:32.0252:SCRIPT_EP:CINT init params:cint -Ihardware\scripts\include -Ihardware\scripts -qlevel1 -Z0
    13/11/11:20:18:32.0315:BOARD_STATE:USB config: WINUSB_SUPPORT
    13/11/11:20:18:32.0315:UTILS:Simulator settings not found. Continuing.
    13/11/11:20:18:32.0315:UTILS:Looking for image map file:hardware\scripts\image_map.xml
    13/11/11:20:18:32.0319:UTILS:Image map load complete.
    13/11/11:20:18:32.0319:CMD:return:DLL_COMMAND_RET_OK
    13/11/11:20:18:32.0319:CMD_API:Ack received. Releasing API.
    13/11/11:20:18:32.0319:CMD_API:==== Command complete ====

    13/11/11:20:18:32.0331:CMD_API:==== Starting new command ====
    13/11/11:20:18:32.0331:CMD_API:Waiting for API
    13/11/11:20:18:32.0332:CMD_API:Posting command
    13/11/11:20:18:32.0332:CMD:Processing ...
    13/11/11:20:18:32.0332:CMD:DLL_Board_Enum
    13/11/11:20:18:32.0332:BOARD_STATE:Board count:0
    13/11/11:20:18:32.0332:GEN:Dll version:2.0.0.5
    13/11/11:20:18:32.0332:CMD:return:DLL_COMMAND_RET_OK
    13/11/11:20:18:32.0332:CMD_API:Ack received. Releasing API.
    13/11/11:20:18:32.0332:CMD_API:==== Command complete ====

    13/11/11:20:18:32.0335:CMD_API:==== Starting new command ====
    13/11/11:20:18:32.0335:CMD_API:Waiting for API
    13/11/11:20:18:32.0335:CMD_API:Posting command
    13/11/11:20:18:32.0336:CMD:Processing ...
    13/11/11:20:18:32.0336:CMD:Dll_Board_Open
    13/11/11:20:18:32.0336:BOARD_STATE:Internal error. User handle not found:0
    13/11/11:20:18:32.0336:BOARD_STATE:Internal error. user handle not valid
    13/11/11:20:18:32.0336:CMD:return:DLL_COMMAND_RET_ERROR
    13/11/11:20:18:32.0336:CMD_API:Ack received. Releasing API.
    13/11/11:20:18:32.0336:CMD_API:==== Command complete ====