Use Arduino Uno to do signal synchronization

Hi all,

I'd like to receive a 6MHz square wave from Rx pin0, and then output it to TX pin1.

The goal is to see the output 6M signal on pin1 and the output 1M signal on pin4 at the same time,
which means the rising edge of the 6M & 1M signal are synchronized.

The following coding seems to have an error on "Serial.read();" part.

Any suggestion is appreciated.

void setup() {
  Serial.begin(9600); // initialize serial
  USART_MSPIM_Init(); // initialize MSPIM mode
  SPCR = (1 << SPE);  // enable SPI
  TIMSK0 = 0;         // disable timer0
  
}
uint8_t incomingByte = 0;
void loop() {
  if (Serial.available() >0){ //take action when a byte is received
     incomingByte = Serial.read(); // read the byte
     UDR0 = incomingByte;
  }
      
}

void USART_MSPIM_Init()
{
  UBRR0H = 0;
  UBRR0L = 0;
  DDRD |= _BV (4);                                             // XCK as output enables master mode
  UCSR0C = (1 << UMSEL01) | (1 << UMSEL00) | (0 << UCPHA0) | (0 << UCPOL0); // Master SPI, mode 0
  UCSR0B = (1 << RXEN0) | (1 << TXEN0);                        // Enable receiver and transmitter
  UBRR0L = 7;                                                  // 1MHz XCK on pin 4
}

Hi,
I think you had better research RS323 UART and stop bits and start bits.
The UART will not put out or receive a continuous squarewave, it is expecting packets of information that are structured and synchronised.

You might just try just reading a digital input , count pulses and change a digital output in time with or a multiple number of input pulses.

Tom... :slight_smile: