My concept is I have two designed boards, One with AT90USB1287, other with ATmega32A both are working properly.

AT90USB1287 is talking to the PC via USB. ATmega32A is talking to the PC via USART(RS232).

Now i have connected ATmega32A board to AT90USB1287 using UART communication(RS232 cable by disabling connection to PC) Because both boards has to work together with one PC. Easiest way is UART connection between those two.

If i want to send data from ATmega32A to PC means, I have to get data from ATmega32A to ATusb901287 and send it to PC via USB.

I am confusing how to get data from ATmega32A to AT90USB1287. I have given connections like 1. connected RxD pin i.e., PD0 i.e., Pin 14 of ATMega32 to TxD pin i.e., PD3 i.e., Pin 28 of AT90USB1287 2. connected TxD pin i.e., PD1 i.e., Pin 15 of ATMega32 to RxD pin i.e., PD2 i.e., Pin 27 of AT90USB1287 3. USB pins of AT90USB1287 are connected to PC USB.


I have implemented UART functionality for both controllers.

The problem is i am not able to send the command that i got from PC to AT90USB1287 via USB. the command will be in USB receive buffer. I have to send the command to another micro controller using UART of AT90usb1287.


I have one more problem with this communication between two microcontrollers using USART. I have the interface code for both controllers like this.

I have the first board with AT90USB1287 microcontroller which is connected to PC using USB, I have several commands like this "CMD", "TEMP" ... When i send command it gives the response. Which is working perfectly. I have to connect another board which contains ATmega32A microcontroller to this board using USART. I have connected and I implemented USART communication in both boards, even the second board also have the similar type of command format and i need to send command to get response as well.
To send the Command from PC to second board i have to send the command first to AT90USB1287 board using USB communication and from that to ATmega32A using USART. I have done that and i am able to get response from second board also but i have one problem. What happening with my code is whatever command i send from PC it is sending to second board, i need to change like only commands which exist in second board has to sent to the second board.

Can anyone suggest me that how to stop sending all commands and send only those 5 commands which related to second board? Please help me with this.


2 Answers 2


I dont understand your confusion. You want to communicate between the two controllers with UART, then ofcourse both of them need UART capabilities and code for this. Your computer has drivers and software for dealing with this, so your microcontroller also needs a driver for it.

Your ATmega32 need UART TX functionality, while AT90USB1287 need UART RX functionality. Having already written both TX and RX for your ATmega32, writing the UART RX routine for AT90 should be a breese. You could add a bitvalue of some kind, identifying that the UART RX on AT90 is coming from your ATmega32, and directly pass it through to USB.

EDIT: Code from AVRFreaks that is written for at90usb1287

#include <avr/io.h> 
#include <util/delay.h> 

#define RXC      (RXC1) 
#define TXC      (RXC1) 
#define UCSRC    (UCSR1C) 
#define UCSRB    (UCSR1B) 
#define UCSRA    (UCSR1A) 
#define UDR      (UDR1) 
#define UBRRL    (UBRR1L) 
#define UBRRH    (UBRR1H) 
#define UBRR     (UBRR1) 
#define UDRE     (UDRE1) 
#define RXCIE    (RXCIE1) 
#define TXEN     (TXEN1) 
#define RXEN     (RXEN1) 
#define UCSZ0    (UCSZ10) 
#define UCSZ1    (UCSZ11) 
#define UMSEL0   (UMSEL10) 
#define UMSEL1   (UMSEL11) 

#define FRAMING_ERROR (1<<FE1) 
#define PARITY_ERROR (1<<UPE1) 
#define DATA_OVERRUN (1<<DOR1) 
#define RX_COMPLETE (1<<RXC1) 

#define FOSC 16000000 

typedef unsigned char       Uchar; 
typedef unsigned long int   Uint32; 

#define Wait_USART_Ready() while (!(UCSR1A & (1<<UDRE1))) 

#define lowByte(w) ((uint8_t) ((w) & 0xff)) 
#define highByte(w) ((uint8_t) ((w) >> 8)) 

int main(void) 
/* Disable clock division */ 
   UBRRH = (Uchar)((((Uint32)FOSC)/((Uint32)USART_BAUDRATE*16)-1)>>8); 
   UBRRL = (Uchar)(((Uint32)FOSC)/((Uint32)USART_BAUDRATE*16)-1) & 0x0ff; 

   UCSRB |= (1 << RXEN) | (1 << TXEN); 
   UCSRC |= (1 << UCSZ1) | (1 << UCSZ0); 

   char ReceivedByte; 
   for (;;) // Loop forever 
      while ((UCSRA & (1 << RXC)) == 0) {}; // Do nothing until data have been received and is ready to be read from UDR 
      ReceivedByte = UDR; // Fetch the received byte value into the variable "ByteReceived" 

      while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it 
      UDR = ReceivedByte; // Echo back the received byte back to the computer 
  • \$\begingroup\$ Thanks for your reply, Yes i understand now. I need to write UART Rx routine and UART Tx routine for AT90USB1287 to recive and send data to and from atmega32a. Can you help me with that routine. \$\endgroup\$
    – verendra
    Dec 6, 2012 at 14:27
  • \$\begingroup\$ I havent written for those exact controllers before, but if you have written for one AVR you should be able to write for another quite easily. \$\endgroup\$
    – chwi
    Dec 6, 2012 at 18:21
  • \$\begingroup\$ Hi i have written code for UART functionality AT90USB1287. The problem is The code as i posted originally is getting command from PC to AT90USB1287 via USB. Now i want to send that command to ATmega32 via UART. please help me how to send that. If you need more code then i will post. \$\endgroup\$
    – verendra
    Dec 13, 2012 at 13:42
  • \$\begingroup\$ You need to read some about UART. It's almost the exact same code, I cannot understand why this should cause confusion if you have already understood and written a UART routine. I don't have time to read the datasheets and write the routine for you. I am starting to suspect you haven't written the code your self if you can not understand how to so this. \$\endgroup\$
    – chwi
    Dec 13, 2012 at 16:45
  • \$\begingroup\$ Please read and understand UART, I cannot understand your problem. You say you know how to write a UART routine, but in practice you do things that just dont make sense \$\endgroup\$
    – chwi
    Dec 13, 2012 at 20:43

you should read the USB input buffer content (in the USB rx interrupt for instance) and copy its content to the UART TX buffer. And that's it.

You already have all the code to setup the UART ports. You only have to pass the data from one RX buffer to the another TX buffer.

With some glue code around (because real things are never that easy) this should work.

  • \$\begingroup\$ I can just give you the basic concept behind the solution of your problem. I can't do the coding for you. But it's easier to implement thing when you know what your aim is. \$\endgroup\$
    – Blup1980
    Dec 14, 2012 at 14:58
  • \$\begingroup\$ Likely it is a little more complicated, in that only some commands/messages arriving over the USB from the PC should be sent one over the serial link to the second microcontroller, while others would be intended for local consumption in the AT90. \$\endgroup\$ Dec 14, 2012 at 18:25
  • \$\begingroup\$ @Blup1980 Yes i understand your concept, i have tried directly assigning "SerIn[RxCnt]" to UDR1. but its not working. please help me with this. I am struggling more than two weeks with this problem. I am new to micro controller programming. This is first time i am facing this type of situation. \$\endgroup\$
    – verendra
    Dec 16, 2012 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.