Controlling an Si570 from Java and Matlab

I am experimenting with software-defined radio (SDR) code in Matlab. One of the things I wanted was to be able to do is set the frequency of the Si570 that clocks the Softrock Ensemble from Matlab. Rather than write Matlab code to do that, I wrote a Java code to do that; it’s trivial to call Java from Matlab.

The Si570 is controlled through I2C by an AVR microcontroller, which is controlled in turn by a PC through a USB connection. The AVR’s firmware was written by Fred Krom (based on earlier code by Tom Baier). To communicate with the AVR from PC programs, Fred uses libusb, a portable kernel driver and a library that allows user-mode programs to communicate with USB devices.,  Fortunately, there is a Java interface to libusb. All of this software is open source.

I downloaded the library and installed it on Windows XP. This included a jar file (Java library) and a Windows DLL that needs to be copied to c:\windows\system32. Libusb consists of a couple of other drivers that need to be in c:\windows\system32, but they were already there. The test program that comes with Java libusb worked and listed the Softrock’s USB device. I wrote a small class that tries to open the device and read the frequency it is set to. It failed.

The code failed to open the device because Java libusb complained that the device has no endpoints (endpoints are logical USB communication channels). The trouble was that Fred and Tom’s firmware communicate only through the control endpoint, the one endpoint that always exists. The Java library assumes that the device would define at least more endpoint, which is true for most devices. But not for the Softrock’s AVR. I downloaded the sources of Java libusb, found the spot where it checks for the existence of endpoints (other than the control endpoint), and removed this check. Now the code works. Andreas Schläpfer, the developer who wrote the code, wrote to me that he’s fix the library.

Calling my Java code from Matlab was a bit tricky. I had to do two things to get it to work. I had to add the location of the Java binaries to Matlab’s Java class path using the javaclasspath function, and to add c:\windows\system32 to Matlab’s binary search path, which is listed in $matlabroot/toolbox/local/librarypath.txt.

That was it. Now I can set and read the Si570’s frequency directly from Matlab (and from Java code). The firmware has many other features that can be controlled by the PC, but they are less important to me now so my code does not support them.

The Matlab code to receive signals is coming along. By carefully reading part 3 of Gerald Youngblood’s article Software Defined Radio for the Masses and the corresponding text in Steven Smith’s book The Scientist and Engineer’s Guide to Digital Signal Processing (the corresponding text consists of most of this book:-), I was able to implement code that demodulates an SSB signal in the passband of the Softrock. Both sources are available freely on the web.


8 Responses to Controlling an Si570 from Java and Matlab

  1. Benno Meier says:

    Hi Sivan,

    this is nice work! I’m working on a Python based control for this device constellation under Linux. I can access the AVR via PyUSB and also already ran into the endpoint issue. However I’ve not managed to communicate with the Si570 so far.

    Could you help me on this with your Matlab code?


  2. Sivan,

    I’ve just encountered the same problem with 0 endpoints that you had with libusbjava. Could you possibly send me your updated version of the code?


    • Sivan Toledo says:

      Andrew, my fix was to simply comment out the lines:
      //if (maxPacketSize <= 0) {
      // throw new USBException(
      // "xxx: No USB endpoints found. Check the device configuration");
      in the file in the package ch.ntb.usb.

  3. Chris Moulding says:

    Hi Sivan,

    I’m working on a simple SDR program using Java. It works well on AM, LSB and USB receive and USB and LSB transmit but I’m having to use Fred Krom’s CFGSR program to control the Si570 at the moment. Could you possibly share your Si570 code with me?



    • Sivan Toledo says:

      Hi Chris,

      I added a link to the java code in the post (search for “my Java code”). Let me know how it goes, and good luck with your Java-based radio program.

      Regards, Sivan

      • Chris Moulding says:

        Hi Sivan,

        Thanks for sharing the code! I like that you have made it possible for others to download it too. When I get it working I’ll let you know and I’ll post it on the internet so that others can tinker with it.



  4. John Cliff says:

    Hi Sivan.
    Great minds think alike – (fools seldom bother). just reading your post Sivan. Good work indeed and thank you for the very interesting info re Si570. I am in the process of building up Home-brew SDR equipment to use with HSDR and Multipsk software.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: