I need to connect two boards using UART of AVR. I wanted to know how much can be the maximum length of the cable between two baords if VCC is 3.3V. I dont want to use rs232 here.
Maximum distance for AVR UART on 3.3V
avruart
Related Solutions
There is no single safe answer. It has a lot to do with the length of the cable, surrounding electrical noise, and how fast you want to go. Ethernet uses CAT5 cable to transmit at 10 Mbit/s for the slowest variety, so 1 Mbit/s is easily doable if you take the proper precautions. Note that with ethernet each signal gets its own twisted pair, and each pair is carefully terminated at the characteristic impedance of the cable at each end. Each pair is driven differentially and interpreted differentially, and is also designed so that it can't cause ground loops.
If you do all these thing, you can transmit 1 Mbit/s data on CAT5 cable for long distances, like 1000 meters. As you do less of these things, the usable distance will go down. If it's just board to board in the same chassis, for example, then you probably don't need to do much special. If you're going outside the unit, then differential line drivers and receivers could be useful.
Try something in your setup and look at the signals at the receiving end to get some idea of the noise margin, adjust as needed. Maybe use a protocol that can detect and recover from errors, and keep track of how often that is happening. There are too many ways to list here without more information.
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 DATA_REGISTER_EMPTY (1<<UDRE1)
#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 */
clock_prescale_set(clock_div_1);
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
}
}
Related Topic
- Electronic – Compare AVR programming tools
- Electronic – 3.3V UART over 20cm ribbon cable inside an enclosure – EMC considerations
- Maximum cable length for 5V or 3.3V I2C, UART, or 1-wire signals over Ethernet and how to increase it
- Electronic – AVR UART synchronization problem
- Electronic – How far can 3.3V UART go at 38400 baud
Best Answer
I can't answer as to the maximum length, but at 9600 baud I wouldn't expect problems at a metre or two, let alone 10cm. Just ensure there is a good ground wire connecting the two boards.
And that assumes it's permanently wired, and working in a typical lab environment, or your home, rather than in the engine compartment, or in orbit or on a mountain top.
Even in the lab, if you plan to unplug and reconnect it regularly, add that info to the question and someone will advise on suitable ESD protection.