Timing issue?: Problem with "sniffing" on Shift Register's SerIN & Clock

I am currently working on hacking an old snack vending machine.
The motor matrix for the dispense is controlled by a 5890 and a 5842, both regular shift registers.
(the 2 form a cascade)

I wanna keep using the existing vending machine’s controller board with the motor drivers.
Now the first step is intercepting the signals sent to the shift registers by the original microcontroller in order to later replace it by an arduino and do a kind of “capture and replay”.

When I connect a LogicAnalyzer(OLS/Arduino), i get nice results(see picture), but somehow my Arduino sketch, which should just
decode the sent signal.

The arduino console output for the same signal as on the picture is


…which just can’t be right…

Here’s my code:

#define CLCK 2
#define DATA 3
#define OE   5

volatile int master_count = 0; // universal count

volatile uint16_t in_buffer =0;

void setup() { 
  pinMode(DATA, INPUT);
  pinMode(OE, INPUT);

void loop() {
       master_count = 0;
       in_buffer = 0;

  attachInterrupt(0, interrupt, RISING);  
  // interrupt 0 digital pin 2 positive edge trigger
        *in_buffer =0;

void interrupt() {
        boolean read = digitalRead(DATA);


//function that also prints leading zeros
void printBIN(volatile uint16_t* binary)
  for(int i=15;i!=-1;i--)
    else Serial.print('0');

I was thinking that it might be a timing issue, but the shift register is being sent to with about 100khz, and the arduino is running at 16mhz, so between to edges on the clock signal there is space for about 160 instructions on the Arduino, which should be fine, rihgt?

Thanks, Robert

You seem to be doing some very weird things with pointers.
In the loop you do this:

*in_buffer =0;

But in_buffer isn't a pointer, why are you dereferencing it?

void printBIN(volatile uint16_t* binary)

Why are you using a pointer here when you don't change binary and it isn't an array. Why not just do:

void printBIN(uint16_t binary)

You don't need the volatile either as it's not going to change.

You also don't need to (nor should) call noInterrupts() and interrupts() inside your interrupt routine - interrupts are disabled during an ISR by the CPU.

The final thing I suggest is that you look up how to use the SPI hardware of the ATMega328 as a Slave. That way you don't have to do the weird things you are doing with interrupts and you are more likely to catch the data correctly.

You would essentially have to wire:

can any1 of u help me ???
i m interfacing cc1101 and aurdino… atmega328p…

i m configuring the cc1101 ic with aurdino… we need to configure the cc1101 registers and set frequency and power by configuring its register… i m using elechouse library …

here is my code

#include <ELECHOUSE_CC1101.h>
byte s;
void setup ()
Serial.begin (9600);
s= ELECHOUSE_cc1101.SpiReadReg(CC1101_FREQ0);
void loop ()

can sm1 help me ??? its urgent…

Thanks a lot Tom!

Actually I've thought of using the hardware SPI in slave mode at first as well, but then I decided that for such a simple task I could just write the capture-routine myself...

But, I think you are right and in the end, it'll be faster done with SPI hardware than by debugging my script.

P.S.: You're right with the in_buffer and binary stuff, but it's not the core of the problem, because initally i've treated in_buffer as a normal variable and binary in printBIN was given by call-by-value as you proposed. I've first changed these things when trying to find a workaround...