Help parsing SPI-display protocol

Hi all,

I have an amplifier placed in a closet. It's controlled remotely using a PC with an IR-transmitter.
Now I want to hook it up to an arduino in order to sniff the data displayed on the amplifiers VFD-display. The display controller is a PT6315 PT6315 pdf, PT6315 Description, PT6315 Datasheet, PT6315 view ::: ALLDATASHEET ::: and it seems to use SPI (MODE3).

I need some help parsing the data sent to the PT6315.

My sketch looks like this:

#include <SPI.h>
#include "pins_arduino.h"

void setup (void)
{
  Serial.begin(9600);
  pinMode(MISO, OUTPUT);
  SPCR |= _BV(SPE);
  
  SPI.setDataMode(SPI_MODE3);
  SPI.attachInterrupt();
}

int data[256];
int dataIndex = 0;
byte firstByte;

ISR (SPI_STC_vect)
{
  byte c = SPDR;
  if(dataIndex < 256)
    data[dataIndex++] = c;
}

void displayMode(){
  // Handle display mode command
}
void dataSetting(){
  // Handle data setting command
}
void addressSetting(){
  // Handle address setting command
}
void displayControl(){
  // Handle display control command
}

void loop (void)
{

  if (digitalRead (SS) == LOW){
    
    firstByte = data[0];
    int b1=bitRead(firstByte, 0);
    int b2=bitRead(firstByte, 1);
    
    if(b1 == LOW && b2 == LOW){
      displayMode();
    }
    if(b1 == LOW && b2 == HIGH){
      dataSetting();
    }
    if(b1 == HIGH && b2 == HIGH){
      addressSetting();
    }
    if(b1 == HIGH && b2 == LOW){
      displayControl();
    }
    
    dataIndex=0;
  }
  
}

I can verify that it receives data (by printing the values of the data-array), but cannot parse it.

I'm pretty new to arduino and low level protocols, and need some help here.

The protocol used is described in the datasheet. The only thing that may be missing is how the chip is wired to the VFD segments. What do you want to achieve? You may have to take into account that the chip is able to accept burst writes from the MCU, so you have to check the SS line because it might be LOW longer than you may expect it.

It's been a while, but I've decided to give this project another go.
I think I'm close, but there seems to be something wrong with my code. I can intercept some of the data sent to the display, but not all. After "Command 3" (Address Setting), 36 bytes of data should be sent to the display. I used to be able to read this, but not any more. Right now I only get the first 10 bytes.

I guess there is some kind of timing issue with my current setup. Any help is appreciated.

#include "pins_arduino.h"
#define wantedCommand 3

volatile boolean firstByte = false;

int buffer[37];
int bufferIndex=0;
int currentCommand = 0;

void setup (void)
{
  Serial.begin(9600);
  SPCR |= _BV(SPE);
  SPCR |= _BV(SPIE);
  
  attachInterrupt (1, ss_rising, RISING);
}

void ss_rising ()
{
  firstByte = true;
}

ISR (SPI_STC_vect)
{
  byte c = SPDR;
  if(firstByte)
  {
    bufferIndex=0;
    currentCommand = getCommand(bitRead(c, 0), bitRead(c, 1));
    firstByte = false;
  }
  if(currentCommand == wantedCommand){
    buffer[bufferIndex++] = c;    
  }
}

int getCommand(byte b1, byte b2){
  if(b1 == LOW && b2 == LOW){
    return 1;
  }
  if(b1 == LOW && b2 == HIGH){
    return 2;
  }
  if(b1 == HIGH && b2 == HIGH){
    return 3;
  }
  if(b1 == HIGH && b2 == LOW){
    return 4;
  }
  return 5;
}

void loop (void)
{
  delay(2000);
  for(int i=0; i<37; i++) {
    printBits(buffer[i]);
  }
  Serial.println("--------");
}

void printBits(byte b){
  for(int i=0; i<8; i++)
    Serial.print(bitRead(b, i));
  Serial.println();
}

You should declare the global variables used in the interrupt handler as "volatile". Otherwise the compiler might optimize in a way that does not address your expectations.

pylon:
You should declare the global variables used in the interrupt handler as "volatile". Otherwise the compiler might optimize in a way that does not address your expectations.

Good suggestion. I've tried that, but it didn't make any difference.