SHIFTIN function as slave

Hello,

I would like to read/spy the stream data from a shiftout like a slave mode.

It's not possible with Shiftin because the pins clock and latch are output. In this way we must have clock and latch as input too!

Is is a function for that?

Thanks

I would like to read/spy the stream data from a shiftout like a slave mode.

Why? You already know the data because you have sent it out.

There are two ways of doing this if you must:-

  1. Use the built in SPI interface and use the MISO pin to read back what is sent.
  2. Don't use the shift out function as such but do it by hand and when ever you output one bit you also shift in another. If you don't know how shift out works look it up in the source code for the Arduino.

Hi Grumpy_Mike,

No I don't know what the data out are; that is why I would like to listen it!

Easy why, connect the clock to and interrupt pin and read the data pin when the clock latches and do the shifting :slight_smile:

potzli:
Hi Grumpy_Mike,

No I don't know what the data out are; that is why I would like to listen it!

If you are using shift out you do know what the data is. If you don't then there is a whole lot of stuff you are not telling us.. We don't like that so come clean.

Probably my explanations were bad (as my english; sorry)

I would like to read serial data coming from an another processor. (I don't know the program) and would like to analyse what is coming out.

With the Septillion idea I wrote that:

int latchPin = 2;
int dataPin = 3;
int clockPin = 4;

int Strobe;
int npulse;

unsigned long Data_Shiftreg;

void setup() 
{
  pinMode(latchPin, INPUT);
  pinMode(clockPin, INPUT); 
  pinMode(dataPin, INPUT);
  Serial.begin(9600);
  Serial.println("Test");
  attachInterrupt(0, Strobe_In, HIGH); // STROBE interrupt on High.
}

void loop() 
{
  if (Strobe)
  {
    Strobe=0;
    detachInterrupt(1);  //stop ck interrupt
    Serial.print("n: ");
    Serial.println(npulse); 
    Serial.println(Data_Shiftreg,BIN); 
    attachInterrupt(1, Ck_In, HIGH); // CLOCK interrupt on High.
    Data_Shiftreg=0;
    npulse=0;
  }
}

void Strobe_In()
{
  Strobe=1;
}


void Ck_In()
{
  int a;
  
  a=digitalRead(dataPin);
  Data_Shiftreg = Data_Shiftreg || a;
  Data_Shiftreg >> 1UL;
  npulse++;
}

It count the pulses but unfortunately Data_Shiftreg stay at 0 or 1.
What is wrong ?

This line

Data_Shiftreg >> 1UL;

Wrong direction and the result is discarded instead of assigned back to Data_Shiftreg.

But please explain, why are you not using shiftIn() or SPI.transfer()?

Thanks PaulRB,

With << the result is the same.

It’s not possible using shiftin because the shiftin function give the clock and latch.

The processor (that I want to “listen”) speak to a real shift register. This processor give the clock and latch.

I want to be in parallel and “listen” the stream. For that clock and latch must be inputs.

Thanks

potzli:
With << the result is the same.

Yes it would be. You didn’t listen.

Try

 Data_Shiftreg = Data_Shiftreg << 1UL;

But you are correct to say shiftIn() will not work for this purpose. And the SPI library does not support slave mode. But the ATmega chip does support slave mode, so may be this will help you.

Thanks but

strange only one bit more!
0 or 10 !

Sorry, I only just spotted your other mistake:

  Data_Shiftreg = Data_Shiftreg || a;

You are getting the boolean-or operator "||" confused with the binary-or operator "|"

a beer for you!!!!

Thanks a lot!

wrong pins:
2 and 3, 2-latch pin(interrupt 0),3-clock pin (interruupt 1)

int latchPin = 2;//p/s
int dataPin = 4;//q8
int clockPin = 3;//clock



int Strobe;
int npulse;

unsigned long Data_Shiftreg;

void setup()
{
  pinMode(latchPin, INPUT);
  pinMode(clockPin, INPUT);
  pinMode(dataPin, INPUT);
  Serial.begin(115200);
  Serial.println("Test");
  attachInterrupt(0, Strobe_In, HIGH); // STROBE interrupt on High.(2pin)
}

void loop()
{
  if (Strobe)
  {
    detachInterrupt(1);  //stop ck interrupt

      Serial.print("n: ");
      Serial.println(npulse);
      Serial.println(Data_Shiftreg, BIN);
    
    attachInterrupt(1, Ck_In, HIGH); // CLOCK interrupt on High.(3pin)
    Data_Shiftreg = 0;
    npulse = 0;
  }
}

void Strobe_In()
{
  Strobe = 1;
}


void Ck_In()
{
  int a;

  a = digitalRead(dataPin);
  Data_Shiftreg = Data_Shiftreg | a;
  Data_Shiftreg = Data_Shiftreg << 1UL;
  npulse++;
}