Issue with reading serial data

TomGeorge:
So how do you detect start of the data pulse, you can't use the data stream to detect the pulse start as there will be no pulse start to a ZERO data bit.
You have to be synchronized to the data stream.
Tom.... :slight_smile:

Could you suggest me how to do that, I was thinking of SPI but it's way too complicated for me as of now and I suppose there might be any other way to do that in a simpler way?

All I know is that I should be using the RDY/CLK signal of EM4095 to sync with my arduino but I don't have a good idea about to implement that.

Here is my code as of now, I can read at every 119usecs but there is not sync so the data i read is not the correct one that I needed.

int a[600];
int k=0;
const byte pin = 2;
void setup()
{
Serial.begin(9600);
DDRB=(0<<PB0); //pin PB0, that is pin 8 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");

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

void loop()
{
if (k>=600)
{
for (short i=0; i<600; i++)
{
Serial.print(a*); //print data stored in the buffer*

  • }*

  • }*

  • Serial.println("\n end of data");*
    }