SPI VDIP1

Hello all. Jeremy here. First time poster, long timer lurker.

I bought this vdip1 module about a month back and after going thru getting setup interfacing via pseudo-UART to my Diecimila I began reading posts about the realized throughput to a USB drive. I want to use this unit in "IMU" datalogger. I know that I might not realize the 10 samples per second write, but I would like to say that I can get more than one sample per second. I have read many posts saying that without handshaking, instability was likely. I definitely don't want that. However, I am a novice, and without examples I have not been able to emulate these instructions.

So being the lurker I am, I am trying SPI now, and once again hit a stumbling block. I've tried searching and searching til my fingers hurt for an example that applies directly to the Arduino/Wiring and the vdip on spi.

This is the closest I have come... http://www.mcuspace.com/mcuforum/viewtopic.php?t=29

But what I translate and what actually needs to be done, eludes me.

Any help would be appreciated.

Thanks MHR

I glanced at SPI for the VDIP to avoid using RS232 (you [u]will[/u] have problems without handshaking, and the non-MEGA arduinos have only one UART). Their SPI is a bit weird; IIRC, there are no even 8 bit transfers, which makes using the ATmega SPI hardware problematic, or maybe even impossible.

If you come up with an SPI implementation, I hope you'll share it - I'm sure I am not the only one who would like to take advantage of it. :)

-j

So this isn’t making use of the hardware spi interface of the arduino, but it is an example of bit banging my way to using the VDIP1.

I am a beginner, so please take it easy on me. Now I’m on to issuing commands to the module…wish me luck.

MHR

#define CS_SELPIN 10 //Selection Pin
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 13//Clock
int readvalue;
int statusbit;

void setup(){
//set pin modes
pinMode(CS_SELPIN, OUTPUT);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK, OUTPUT);
//disable device to start with
digitalWrite(CS_SELPIN,LOW);
digitalWrite(DATAOUT,LOW);
digitalWrite(SPICLOCK,LOW);

Serial.begin(9600);
}

int read_vdip(int channel){
int vdipvalue = 0;
byte commandbits = B11000000; //command bits - start, mode, addr

//allow address selection
commandbits|=((channel-1)<<1);

digitalWrite(CS_SELPIN,HIGH); //Select vdip1

// setup bits to be written
for (int i=7; i>=5; i–){
digitalWrite(DATAOUT,commandbits&1<<i);
//cycle clock
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
}

//read bits from adc
for (int i=7; i>=0; i–){
vdipvalue+=digitalRead(DATAIN)<<i;
//cycle clock
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
}
statusbit = digitalRead(DATAIN);
digitalWrite(CS_SELPIN, LOW); //turn off device
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);

// Serial.println(statusbit);
return vdipvalue;
}

void loop() {
readvalue = read_vdip(1);
Serial.print(readvalue,BYTE);
// readvalue = read_vdip(2);
// Serial.println(readvalue,DEC);
// Serial.println(" ");
delay(20);
}

I am having trouble with my VDIP1 and writing commands to it. So far I did get bit-banging for the first read accomplished, but I am having no success with writing to the VDIP1.

So far this is what I have…

#define CS_SELPIN 10 //Selection Pin
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 13//Clock

int readvalue;
int statusbit;
int incomingByte = 0;

void setup(){
//set pin modes
pinMode(CS_SELPIN, OUTPUT);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK, OUTPUT);
//disable device to start with
digitalWrite(CS_SELPIN,LOW);
digitalWrite(DATAOUT,LOW);
digitalWrite(SPICLOCK,LOW);

Serial.begin(9600);
delay(2000);
init_vdip();
// ping_vdip();
delay(200);
}

int init_vdip(){
write_vdip(73);//I
write_vdip(80);//P
write_vdip(65);//A
write_vdip(13);

Serial.print("Init: ");
Serial.println(statusbit);
}

void ping_vdip(){
// write_vdip(char(69));//E
write_vdip(char(13));
// Serial.print("Echo: ");
Serial.println(statusbit);
}

int read_vdip(int byteaddr){
int vdipvalue = 0;
byte commandbits = B11000000; //command bits - start, mode, addr

//allow channel selection
commandbits|=((byteaddr-1)<<1);

digitalWrite(CS_SELPIN,HIGH); //Select vdip1

// setup bits to be written
for (int i=7; i>=5; i–){
digitalWrite(DATAOUT,commandbits&1<<i);
//cycle clock
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
}

//read bits from adc
for (int i=7; i>=0; i–){
vdipvalue+=digitalRead(DATAIN)<<i;
//cycle clock
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
}
statusbit = digitalRead(DATAIN);
digitalWrite(CS_SELPIN, LOW); //turn off device
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);

// Serial.println(statusbit);
return vdipvalue;
}

int write_vdip(int commandbyte){
Serial.println(commandbyte);
int vdipvalue = 0;
byte commandbits = B10000000; //command bits - start, mode, addr

digitalWrite(CS_SELPIN,HIGH); //Select vdip1

// setup command bits to be written
for (int i=7; i>=5; i–){
digitalWrite(DATAOUT,commandbits&1<<i);
//cycle clock
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
}

//write byte to vdip
for (int i=7; i<=0; i++){
digitalWrite(DATAOUT,commandbyte&1<<i);
//cycle clock
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
}

//get status bit
statusbit = digitalRead(DATAIN);
digitalWrite(CS_SELPIN, LOW); //turn off device
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);

// Serial.println(statusbit);
return statusbit;
}

void loop() {
// ping_vdip();
boolean linefeed = 0;
while (Serial.available() > 0) {
// read the incoming byte:
linefeed = 1;
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
write_vdip(incomingByte);

}
if (linefeed){linefeed = 0; write_vdip(13);}

readvalue = read_vdip(1);
Serial.print(readvalue,BYTE);
// readvalue = read_vdip(2);
// Serial.println(readvalue,DEC);
// Serial.println(" ");
delay(200);
}

I do not know where I am making a mistake. If anyone could help me see my errors, I would greatly appreciate the learning experience.

MHR

MHR,

I’m glad you’ve tackled this. I’ve been researching Vinculum, but haven’t purchased one yet. FYI, I did find this related post regarding VMUSIC2, rather than VDIP1, but the principles should be the same.

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=60425&view=next

It doesn’t give code, but it does give an algorithm for using the hardware Arduino/AVR SPI, rather than bit-banging. Although I haven’t tried it, I’m passing it on to you in the hope that it helps, or at least gives you an alternate view of the problem.

Best of luck to you!

–jb.

There are SPI program sample using Propeller.

http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/27937/List/0/SortField/4/ProductID/434/Default.aspx

Maybe you can give it a try,too.

Is there any WORKING example of the vdip1 using SPI?

Yes, VDIP1 works with standard SPI library, but this way is a little tricky. I will post my code when I clear all issue. For a while only example of vdipRead() function.

unsigned char vdipRead(void) // Returns Data read
{
unsigned char i,j;
digitalWrite(csPin,HIGH); // Chip select HIGH
i=SPI.transfer(0xC0); // Data read from Data register first 5 bit
j=SPI.transfer(0x0); // Dummy byte to read left 3 bits
digitalWrite(csPin,LOW);
SPI.transfer(0x0); // Dummy byte to toggle CLK when CS is LOW
return((i<<3|j>>5));
}