How to send a stream of synchronized data without frame limit

Sorry if the title is confusing.

Say I just wanna send a series of 101010101....... @ a frequency of 1MHz (synchronized by a 1MHz clock)
or something like the one in the diagram (I need at least 3 channels)

Since Serial and I2C has extra frame bits like start/end/ACK bits, it's not a good option.
I'm not sure if SPI or other libraries can do that?
Any suggestions? Thanks in advance.

If you just want to send an unending series of 1s and 0s just use digitalWrite(). However that is a slow function so you will probably need to use port manipulation to write directly to the I/O port.

...R

Where is your "clock" signal coming from? I suggest using an interrupt from the clock signal to toggle the output pins.

Paul

Robin2:
If you just want to send an unending series of 1s and 0s just use digitalWrite(). However that is a slow function so you will probably need to use port manipulation to write directly to the I/O port.

...R

Paul_KD7HB:
Where is your "clock" signal coming from? I suggest using an interrupt from the clock signal to toggle the output pins.

Paul

Thanks for both of your ideas. So combining port manipulation and interrupt, I finally get something like this:

int flag = 0;
void setup(){
  DDRB |= B00001110;
  cli();//stop interrupts
  TCCR3A = 0;
  TCCR3B = 0;
  TCNT3 = 0;
  OCR3A = 15;
  TCCR3B |= (1 << WGM32);
  TCCR3B |= (1 << CS30);
  TIMSK3 |= (1 << OCIE3A);
  sei();//set interrupt on Timer3 @ 1MHz
}//end setup
ISR(TIMER3_COMPA_vect){

  if (flag ==0){
    PORTB = B00001110;
    flag = 1;
  }
  else if(flag ==1){
    PORTB = B00000100;
    flag = 2;
  }
  else if(flag ==2){
    PORTB = B00001110;
    flag = 3;
  }
  else if(flag ==3){
    PORTB = B00000110;
    flag = 0;
  }
}
void loop(){
}

There's still some timing issue at such high frequency, but the format is what I'm looking for.
Thanks again

At 1 MHz on an Arduino UNO you only have 16 instruction cycles to do everything from interrupt handling to data output. The clock interrupt every 900-something microseconds will cause a glitch in your output about every millisecond.

   PORTB = B00001110;
   PORTB = B00000100;
   PORTB = B00001110;
   PORTB = B00000110;

It looks like your bit pattern is:
PB1-> 1011101110111011
PB2-> 1111111111111111
PB3-> 1010101010101010

So PB2 is just ON all the time, PB3 just toggles, and PB1 on 3 off 1 (offset by 1)?

johnwasser:
At 1 MHz on an Arduino UNO you only have 16 instruction cycles to do everything from interrupt handling to data output. The clock interrupt every 900-something microseconds will cause a glitch in your output about every millisecond.

It looks like your bit pattern is:
PB1-> 1011101110111011
PB2-> 1111111111111111
PB3-> 1010101010101010

So PB2 is just ON all the time, PB3 just toggles, and PB1 on 3 off 1 (offset by 1)?

That's just a sample. Actually I want a pattern like:
PB1:0101010101010101....(clock)
PB2:1111111111111111....(enable signal)
PB3:1111111111111111xxxx....(data[0])
PB4:0000000000000011xxxx....(data[1])

Since I don't care what the data xxxx is, I can just implement the first 16 bits (to have 8 pos-edges)and let it loop itself. As you suggest, the ISR block should be done within 16 instruction cycles, how about something like:

bool odd = true;
int pos = 1;

ISR{
iif(odd==true && pos!=15){
PORTB = B00000110;
pos++;
}
else if (odd==true && pos==15){       
PORTB = B00000111;
pos++;
}
else if (odd==false && pos!=16){       
PORTB = B00001110;
pos++;
}
else{
PORTB = B00001111;
pos = 1;
}
odd = !odd;
}

I'm not sure how IDE compiles it, but it looks like the above code goes beyond 16 cycles.
Because the clock signal with a period of 2 interrupts should be 500kHz, but the actual signal I measured has a maximum of 125kHz for the interrupt @ 1MHz,500kHz,250kHz.
Any suggestions on how to minimize the code? only need one signal to change from 0 to 1 on every 8th pos-edge, others signals are always the same.