Reading data using SPI

Hello,

I'm using an RFID based development board EMDB409 that uses an analog front end module EM4095(datasheet attached below).

The output of EM4095 IC is Demod_out(data that I want to read), RDY/CLK(clock signal of 125kHz) and a few other pins (not much relevant as of now). I'm using arduino uno to read the serial data coming out of the Demod_out pin in sync to the 125kHz clock coming out of the RDY/CLK pin.

I did go through the concept of SPI, how to use in arduino and other forums where SPI was used for reference. So, technically, I believe my Arduino UNO is the slave and the EMDB409 kit is the master (as the dev. kit is generating clock and the data that I need).

My aim is to read that serial data coming out of Demod_out pin at every 119usecs with respect to the 125kHz clock(sync purpose).

Here is the code to read the data out of the Demod_out pin at ever 119us, I used ISR to do that.

int a[600];
short k=0;

void setup() 
{
  
  Serial.begin(9600);
  DDRB=(0<<PB3); //pin PB3, that is pin 11 on Arduino as input
  TCCR2A = 0b00000010; //CTC mode
  TCCR2B = 0b00000010;//last three bits set the prescaler  = 16MHz/8;
  OCR2A = 237; //CM reg value for desired time period of 119usecs with 237//120usec with 239
  TIMSK2= 0b00000010; //enable timer compare INT
  Serial.println("Begin reading");
}

ISR(TIMER2_COMPA_vect)
 {
  if(k<600)
  {
    a[k] = (PINB & (1<<PB3)); //reading data at every 119usec through pin 11 of arduino
  }
  k++;
 }

 
void loop() 
{
  
  
  for(short i=0; i<600; i++) 
  {
    Serial.print(a[i]); ///to print the data stored in buffer 'a'.
  }
  
 
  Serial.println("\n end of data");
}

This is a simple code to read data and it's working fine. But, the data i'm reading is not in sync with the clock so usually the data I read on the serial monitor is not the actual data that I needed.

So, I think(based on responses from other forums) the way I could do that is to use SPI concept to get my data reading in sync with the clock that is being generated by EM4095, I'm noob to the coding section of the hardware design, so please let me know if there is any other way to do it using SPI or without using SPI concept for the sync in my reading.

Thanks in advance :slight_smile:

em4095_data sheet.pdf (243 KB)

EM4095 pin out.pdf (167 KB)

This is a simple code to read data and it's working fine. But, the data i'm reading is not in sync with the clock so usually the data I read on the serial monitor is not the actual data that I needed.

It's not working at all if its not reading the correct data!

Posting on other forums is known as crossposting and is frowned on

Mark

I meant other people posts and responses about SPI and when to use it. My other post is a bit different from this one, so I hope that I did the right thing by posting a new topic.

Thank you though for your quick response :slight_smile:

int a[600];
a[k] = (PINB & (1<<PB3)); //reading data at every 119usec through pin 11 of arduino

You're wasting a complete integer (16 bits) to store one bit. You know that this array uses about two third of the available RAM, don't you?

The interface to the chip is NOT SPI!

Mark