Pages: [1]   Go Down
Author Topic: Problem with "sniffing" on Shift Register's SerIN & Clock  (Read 1562 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Berlin, .de
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
Sniffing...
16
1000000000000000
Sniffing...
...which just can't be right...

Here's my code:
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);
  pinMode(CLCK,INPUT);
  
  Serial.begin(9600);
}

void loop() {
  
  Serial.println("Sniffing...");
  
  delay(10);
  
  while(1)
    if(digitalRead(OE)==LOW)break;
  
       master_count = 0;
       in_buffer = 0;

  attachInterrupt(0, interrupt, RISING);  
  // interrupt 0 digital pin 2 positive edge trigger
      
    while(1)
    {
  
      if(master_count>15)
      {
        detachInterrupt(0);
        
        Serial.println(master_count,DEC);
        printBIN(&in_buffer);
      
        delay(6000);
        *in_buffer =0;
        master_count=0;
       break;
      }
    }
}


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

        noInterrupts();
        if(read==true)bitSet(in_buffer,(15-master_count));
        master_count++;
        interrupts();
}


//function that also prints leading zeros
void printBIN(volatile uint16_t* binary)
{
  for(int i=15;i!=-1;i--)
  {
    if(bitRead(*binary,i))Serial.print('1');
    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


* Bildschirmfoto 2014-02-14 um 00.54.06.png (89.76 KB, 1027x542 - viewed 54 times.)
« Last Edit: February 14, 2014, 12:59:32 pm by surumadurum » Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if(master_count>15)

I think you are displaying the buffer when all is gone shouldn't it be 14 here
Logged

"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੂਂ !

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34115
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you are not actually sniffing the correct value. Try just printing the binary value of your buffer with a normal serial print command.
Logged

Pages: [1]   Go Up
Jump to: