title: Atmega and ARM UART connection. The odd behavior
body: <p>So, it's kind a complex problem and not related to AVR only, but I think that problem is in Atmega.</p>
  
  <ul>
  <li><p>I have FOSCAM WI-FI camera based on ARM NUC745 which runes under  uClinux. There is UART port on that camera which is connected with my Atmega board. In the same time that UART on ARM board used for console output and input.</p></li>
  <li><p>I can send the commands through web interface provided by the camera and this commands goes through ARM board to Atmega board through UART.</p></li>
  <li><p>I've written a program for Atmega to read the data which comes to UART from ARM. And all the data seems to be received by Atmega. Regarding to the data received, Atmega  sent data from Atmega to ARM board through UART. In VMLAB I can see that data is coming out in the oscilloscope. But ARM board doesn't receive that data. When I disconnect Atmega board from ARM board and connect ARM board to the terminal from my iMac all the data which has been sent by Atmega quickly appears in the terminal and program which I've written for ARM board receives all the data.</p></li>
  </ul>
  
  <p>It's pretty strange behavior. Seems that Terminal connection and Atmega serial connections are different and I cannot realize why:(((</p>
  
  <p>Sorry that I couldn't format the code properly</p>
  
  <p>Here is the code for Atmega </p>
  
  <pre><code>/*
   * main.c
   *
   *  Created on: 25.05.2011
   *      Author: moldov
   */
  
  #include &lt;avr/io.h&gt;              // Most basic include files
  #include &lt;avr/interrupt.h&gt;       // Add the necessary ones here
  
  //flash char string_1[]="Prog Start";
  //const char left[] PROGMEM ="no support\0x0ALLno support\0x0D\0x0A";
  
  
  char command_indicator;
  
  #define TXB8 0
  #define RXB8 1
  #define UPE  2
  #define OVR  3
  #define FE   4
  #define UDRE 5
  #define RXC  7
  
  #define FRAMING_ERROR (1&lt;&lt;FE)
  #define PARITY_ERROR (1&lt;&lt;UPE)
  #define DATA_OVERRUN (1&lt;&lt;OVR)
  #define DATA_REGISTER_EMPTY (1&lt;&lt;UDRE)
  //#define RX_COMPLETE (1&lt;&lt;RXC)
  
  
  //TCCR1A
  #define WGM11 1
  #define WGM10 0
  #define COM1A1 7
  #define COM1A0 6
  #define COM1B1 5
  #define COM1B0 4
  //TCCR1B
  #define WGM13 4
  #define WGM12 3
  #define CS0 0
  #define CS1 1
  #define CS2 2
  
  
  void USART_Transmit( unsigned char data );
  void USART_Init( unsigned int baud );
  unsigned char USART_Receive( void );
  
  ISR(USART_RXC_vect) {
      char status, data;
      status=UCSRA;
      data=UDR;
  
      if ((status &amp; (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0) {
  
      if (command_indicator == '$') {
              switch (data ) {
              case 'C':
                  PORTB |= 0x03;
                  PORTD |= 0x30;
                  USART_Transmit('C');
              break;
  
              case 'V':
                  PORTB &amp;= ~0x03;
                  PORTD &amp;= ~0x30;
                  USART_Transmit('V');
              break;
  
              case 'Z':
                  PORTB |= (1 &lt;&lt; 3);
                  USART_Transmit('Z');
              break;
  
              case 'X':
                  PORTB &amp;= ~(1 &lt;&lt; 3);
                  USART_Transmit('X');
              break;
  
              case 'F':
                  PORTB |= (1 &lt;&lt; 0);
                  PORTB |= (1 &lt;&lt; 1);
                  USART_Transmit('F');
                 USART_Transmit(13);
              USART_Transmit(10);
  
              break;
  
              case 'B':
                  PORTB &amp;= ~(1 &lt;&lt; 0);
                  PORTB &amp;= ~(1 &lt;&lt; 1);
                  USART_Transmit('B');
              break;
  
  
              case 'L':
                  USART_Transmit('L');
              break;
  
              case 'R':
                  USART_Transmit('R');
              break;
  
              case '0':
                  USART_Transmit('0');
                  OCR1AL = 0x00; // 0x00FF это число 256
                  OCR1BL = 0x00; // 0x00FF это число 256
              break;
  
              case '1':
                  USART_Transmit('1');
                  OCR1AL = 0x0F; // 0x00FF это число 256
                  OCR1BL = 0x0F; // 0x00FF это число 256
              break;
  
              case '2':
                  USART_Transmit('2');
                  OCR1AL = 0x3F; // 0x00FF это число 256
                  OCR1BL = 0x3F; // 0x00FF это число 256
              break;
  
              case '3':
                  USART_Transmit('3');
                  OCR1AL = 0x6F; // 0x00FF это число 256
                  OCR1BL = 0x6F; // 0x00FF это число 256
              break;
  
              case '4':
                  USART_Transmit('4');
                  OCR1AL = 0x9F; // 0x00FF это число 256
                  OCR1BL = 0x9F; // 0x00FF это число 256
              break;
  
              case  '5':
                  USART_Transmit('5');
                  OCR1AL = 0xCF; // 0x00FF это число 256
                  OCR1BL = 0xCF; // 0x00FF это число 256
              break;
              }
              command_indicator = 0x00;
  
  
          }
          if(data =='$') {//If we send command "$" shows that
          command_indicator = '$';
              //PORTB &amp;= ~(1 &lt;&lt; 3);
          }
      }
  
  }
  void USART_Transmit( unsigned char data ) {
      /* Wait for empty transmit buffer */
      while ( !( UCSRA &amp; (1&lt;&lt;UDRE)) ); /* Put data into buffer, sends the data */
      UDR = data;
  }
  void USART_Init( unsigned int baud ) {
      /* Set baud rate */
      UBRRH = (unsigned char)(baud&gt;&gt;8);
      UBRRL = (unsigned char)baud;
  
      /* Enable receiver and transmitter */
      UCSRB = (1&lt;&lt;RXEN)|(1&lt;&lt;TXEN);
      UCSRC = (1&lt;&lt;URSEL)|(0&lt;&lt;USBS)|(3&lt;&lt;UCSZ0);  // Set frame format: 8data, 1stop bit
      UCSRB |= (1 &lt;&lt; RXCIE); // Enable the USART Recieve Complete interrupt (USART_RXC)
      sei();// Enable the Global Interrupt Enable flag so that interrupts can be processed
  }
  unsigned char USART_Receive( void ) {
      /* Wait for data to be received */
      while ( !(UCSRA &amp; (1&lt;&lt;RXC)) ); /* Get and return received data from buffer */
      return UDR;
  }
  // ***********************************************************
  // Main program
  //
  int main(void) {
  
      //DDRD=0xFF;
      DDRD = 0x30; //4-5-й пин порта D настроим как выход
      DDRB = 0xFF; //
      // Настройка TIMER1 для генерации ШИМ
  
  
      TCCR1A = 0x00; //stop Timer
  
      TCNT1H = 0xFF; // 11111111
      TCNT1L = 0x00; // 00000000
  
      /* регистр OCR1A состоит из двух 8-ми битных регистров OCR1AH и OCR1AL запись в них нужно проводить в указанной последовательности! */
      OCR1AH = 0x00;
      OCR1AL = 0x00;
      OCR1BH = 0x00;
      OCR1BL = 0x00;
      ICR1H  = 0x00;
      ICR1L  = 0x00;
  
      //Got from OR Project
      TCCR1A = 0xA1;
      TCCR1B = 0x0A;
  
      //Скорость USART 115200 при кварцевом генераторе 7.3MHz USART_Init (0x03);
      USART_Init (0x03);
      USART_Transmit('O');//Передаем при включении
      USART_Transmit('k');//сообщение "Ok!", что свидетельствует
      USART_Transmit('!');//о правильно работе программы
      USART_Transmit(0x0d);//переход в начало строки
      USART_Transmit(0x0a);//переход на новую строку
      while(1) {}             // Infinite loop; define here the
  
  } 
  </code></pre>
  
  <p>And code for ARM linux</p>
  
  <pre><code>#include &lt;fcntl.h&gt;      /* open() and O_XXX flags */
  //#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  //#include &lt;sys/stat.h&gt; /* S_IXXX flags */
  //#include &lt;unistd.h&gt;   /* close() */
  
  int main (int argc, char ** argv){
      const char * name = "/home/kiss.txt";
  
          int mode = 0777;
      int flags = O_WRONLY | O_CREAT | O_EXCL;
      int fd = open (name , flags, mode);
      printf ("File descriptor is: %d", fd);
          int tty_fd = open ("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY );
      if (tty_fd == -1) {
          perror ("open_port:Unable to open /dev/ttyS0 - ");
      }
      else {
          unsigned char c='D';
  
          fcntl (tty_fd, F_SETFL,0);
  
          while (1) {
              if (read(tty_fd,&amp;c,1)&gt;0)        {
                  write(STDOUT_FILENO,&amp;c,1);
                  write(fd,&amp;c,1);
  
              }              // if new data is available on the serial port, print it out
              if (read(STDIN_FILENO,&amp;c,1)&gt;0)  {
                  write(tty_fd,&amp;c,1);
                  write(fd,&amp;c,1);
              }
          }
  
          close (tty_fd);
      }
  
      close (fd);
  }
  </code></pre>
  
  <p>Could some one help me with this</p>