Basic SSI Slave on Arduino DUE

Hey there guys!

I am using an Arduino DUE and I have to hook it up to a really simple communication protocol.

This protocol (I analyzed it using data sheets and oscilloscopes) has the following characteristics:

-Clock idle mode HIGH, Read on clock RISING EDGE -Clock Frequency: 2 MHz -Word length (how many bits are transferred each time?): up to 25 bit. -wait time between 2 words: long enough^^... (like at least 16 µs=32 clock cycles).

So its really basic! It has no Chip selects or what so ever. It just transfers the sensor value bit-by-bit with a clock on the side... It is like a really simple version of SPI Master (from the sensors point of view).

There must be an easy way to use an Arduino to just take this master clock from the sensor and read in the bits... Isnt there? I have read a lot on SPI so far but it just seems like an overkill to my problem... The frequency of 2 MHz cannot changed though... so pure software does not work I think.

I though about using ShiftIn but the problem is that the clock comes from the sensor... And of course I do not know when the sensor is gonna send!

Thank you!! Swampy

Swampy:
Hey there guys!

I am using an Arduino DUE and I have to hook it up to a really simple communication protocol.

This protocol (I analyzed it using data sheets and oscilloscopes) has the following characteristics:

-Clock idle mode HIGH, Read on clock RISING EDGE
-Clock Frequency: 2 MHz
-Word length (how many bits are transferred each time?): up to 25 bit.
-wait time between 2 words: long enough^^… (like at least 16 µs=32 clock cycles).

So its really basic! It has no Chip selects or what so ever. It just transfers the sensor value bit-by-bit with a clock on the side… It is like a really simple version of SPI Master (from the sensors point of view).

There must be an easy way to use an Arduino to just take this master clock from the sensor and read in the bits… Isnt there? I have read a lot on SPI so far but it just seems like an overkill to my problem… The frequency of 2 MHz cannot changed though… so pure software does not work I think.

I though about using ShiftIn but the problem is that the clock comes from the sensor… And of course I do not know when the sensor is gonna send!

Thank you!!
Swampy

You will have to build you own input routine, I would suggest connecting the clock line to pin2 and using an interrupt ISR to monitor the ‘data’ line.

#define DATAPIN 3
#define CLKPIN 2
#define INTERRUPT 0  // which actually on pin 2

volatile unsigned long readLong;
volatile unsigned long lastMicro;
volatile unsigned long prior;
volatile bool newRead;
void ClockLow(){
if(micros()-lastMicro>25){// dead time for clock to mark new reading
  if(!newRead) prior = readLong; // was read in main loop
  newRead=true;
  readlong=0;
  }
readlong = readlong << 1; // shift up
if(digitalRead(DATAPIN) readlong = readlong | 1;
lastMicro = micros();
}

void setup(){
pinMode(DATAPIN,INPUT);
pinMode(CLKPIN,INPUT);
attachInterrupt(INTERRUPT,ClockLow,RISING);
}

void loop(){
if(newRead){
  Serial.print(prior,HEX);
  newRead=false;
  }

}

Something like this. Now, I don’t know if my ISR is fast enough to catch all of your clock translations.

Chuck.

chucktodd:
You will have to build you own input routine, I would suggest connecting the clock line to pin2 and using an interrupt ISR to monitor the ‘data’ line.

I don’t think my code will be fast enough, with a 2mhz input, you will probably have to use SPI in SLAVE mode.

you might have to add some logic to produce a SS signal to sync the SPI shift register.

Another problem using SPI, The Shift register is clocked on 8bits. I don’t know how you would use it with 26bits of data? You could get the first 24 ok, the last two? I don’t know.

Chuck.