VM205 communication protocol using the wiringPiSPI library


#1

Hello every body;

I’m traying to do an spi communication between my raspberry PI 2 and the oscilloscope and logic analyzer shield for raspberry Pi VM205.

The spi protocol to reading the data can be desribed as follows :

[color=#FF0000]To reset the system and to start the data acquisition, send byte 0x81 to the SPI port. Then check if the data acquisition is
complete:
1. Wait 20ms.
2. Send byte 0x82 to the SPI port
3. Read the response from the SPI port.
If the response is 0x02, the data acquisition is complete.
If the response is 0x00, the data acquisition is not yet complete.
In this case repeat the sequence 1-3 above.[/color]

After getting response 0x02, the acquired data can be read. Send 801 times 0x01 to the SPI port and read the response. You’ll get 800 values containing the oscilloscope data.

Then send 801 times 0x02 to the SPI port and read the response. You’ll now get 800 values containing the logic analyzer data for
the eight first channels.

Then send 801times 0x03 to the SPI port and read the response. You’ll now get 800 values containing the logic analyzer data for
the channels 9 and 10. Bit #0 is channel 9 data and bit #1 is channel 10 data.

In the logic analyzer data each bit corresponds the input channel state:
bit value 0 = input state low
bit value 1 = input state high

We can found the all protocol here :
vellemanprojects.eu/download … _vm205.pdf

So I implemeted the following code using the wiringPiSPI library to start the communication (just the first paragraph selected in red) and to see if I will have response :

#include
#include <wiringPiSPI.h>
#include <wiringPi.h>
#include <errno.h>
#include <unistd.h>

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

static int myFd;

int main()
{
int speed = 1000000;

int spi_chan = 0;

if ((myFd = wiringPiSPISetup (spi_chan, speed)) < 0)
{
    cout << (stderr, "Can't open the SPI bus: %s\n", strerror (errno)) << endl;
    exit (EXIT_FAILURE) ;
}

unsigned char byte = 0x81;
wiringPiSPIDataRW(spi_chan, &byte, spi_chan); /*reset the system and start the data acquisition*/

unsigned char reponse = 0x82;
bool out = false;

while((reponse == 0x00)&&(out == false)){
    usleep(20000);
    unsigned char reponse = 0x82;
    wiringPiSPIDataRW(spi_chan, &reponse, spi_chan);
    cout << int(reponse) << endl;
    if (reponse == 0x02){out = true;}
}

}

But the problem now is, I don’t have any response about my card vm205.
So if you can give some helps ….
thank you


#2

The VM205 is using SPI mode 2:
Clock Polarity (CPOL) = 1
Clock Phase (CPHA) = 0

wiringPiSPISetup opens the SPI device and set it up in the default MODE 0.
(For more info please see wiringPiSPI.c code.)

It is also important to set the trigger off in the VM205 to get some data even if there is no input signal.
In this code example the SPI and the VM205 are configured without using the WiringPi SPI library:

[code]#include <fcntl.h> //Needed for SPI port
#include <sys/ioctl.h> //Needed for SPI port
#include <linux/spi/spidev.h> //Needed for SPI port
#include <stdio.h>
#include <stdlib.h>
#include
#include
#include

using namespace std;

int fd;
unsigned char spi_mode;
unsigned char spi_bitsPerWord;
unsigned int spi_speed;

void SpiOpenPort (int spi_device)
{
//----- SET SPI MODE -----
//SPI_MODE_0 (0,0) CPOL=0 , CPHA=0
//SPI_MODE_1 (0,1) CPOL=0 , CPHA=1
//SPI_MODE_2 (1,0) CPOL=1 , CPHA=0
//SPI_MODE_3 (1,1) CPOL=1 , CPHA=1
spi_mode = SPI_MODE_2;

//----- SET BITS PER WORD -----
spi_bitsPerWord = 8;

//----- SET SPI BUS SPEED -----
spi_speed = 1000000;		//1000000 = 1MHz  

fd = open(std::string("/dev/spidev0.0").c_str(), O_RDWR);

ioctl(fd, SPI_IOC_WR_MODE, &spi_mode);
ioctl(fd, SPI_IOC_RD_MODE, &spi_mode);
ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bitsPerWord);
ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &spi_bitsPerWord);
ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed);
ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &spi_speed);

}

int SpiWriteAndRead (unsigned char data)
{
unsigned char rxDat;
struct spi_ioc_transfer spi;

spi.tx_buf        = (unsigned long)&data; // transmit from "data"
spi.rx_buf        = (unsigned long)&rxDat; // receive into "rxDat"
spi.len           = 1 ;
spi.delay_usecs   = 0 ;
spi.speed_hz      = spi_speed ;
spi.bits_per_word = spi_bitsPerWord ;
spi.cs_change = 0;
spi.pad = 0;

ioctl(fd, SPI_IOC_MESSAGE(1), &spi) ;

return rxDat;

}

int main(void)
{
int i,h;
unsigned char data;
SpiOpenPort (0);

data= 0x93; 			// Time/Div setting
SpiWriteAndRead (data);
data= 0x0c; 			// 1MS/s
SpiWriteAndRead (data);
data= 0x94; 			// Trigger setting
SpiWriteAndRead (data);
data= 0x02; 			// Trigger Off
SpiWriteAndRead (data);

data= 0x81; 
SpiWriteAndRead (data);
h = 0;
i = 0;
do
{
	data= 0x82; 
	usleep (20000);
	h = SpiWriteAndRead (data); 
	cout << "The Result is: " << int(h) << endl;
	i++;
}
while (h != 2  && i < 1000);

for (i=0; i<802; i++)
{
	data= 0x01; 
	h = SpiWriteAndRead (data); 
	if (i<10)
		cout << "Data [" << int(i) << "] is: " << int(h) << endl;	
}

for (i=0; i<802; i++)
{
	data= 0x02; 
	h = SpiWriteAndRead (data);
	if (i<10)		
		cout << "Data [" << int(i) << "] is: " << int(h) << endl;		
}

for (i=0; i<802; i++)
{
	data= 0x03; 
	h = SpiWriteAndRead (data); 			
}

close(fd);
return 0;

}
[/code]


#3

Hello

Thank you for your response, it’s working well!!

Hakim


#4

Hello,

I’m trying to use the VM205 oscilloscope to do an acquisition in real time, but i’ve a problem when retrieving the buffer data. I can only get one buffer (800 points), but i don’t know how to properly get the next buffer. I’ve tried to reset (data=0x81), which forces the system to get the new buffer, but unfortunately, a part of the data are lost. Without a reset, the buffer is never refreshed…

So my question is simple : what is the clean way to retrieve the next buffer? Is it possible to retrieve the next buffer without a reset?

Best regards
Hakim


#5

[quote]So my question is simple : what is the clean way to retrieve the next buffer? Is it possible to retrieve the next buffer without a reset?[/quote]I’m sorry, the reset is the only way to start the next data acquisition cycle.


#6

thank again for your response.