Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

rs485 code help/suggestions winavr gcc

Status
Not open for further replies.

sherazi

Banned
Joined
Feb 15, 2010
Messages
388
Helped
61
Reputation
126
Reaction score
61
Trophy points
1,318
Location
Muscat, Oman, Oman
Activity points
0
hi friends!
i wanted to implement rs485 communication b/w an avr and a pc.. the reason being distance up to 50 m b/w the two.. i am using the max485 ic, being the first time for such project wanted help and guidence.. i have a rs232-485 converter that i am going to use.
as far as my thw knowledge i have upto now is that aprt from being half duplex, there is no other big difference in coding.

i have the following code for initialization,
Code:
char ReceivedByte; 


   UCSR0B |= (1 << RXEN0) | (1 << TXEN0);   // Turn on the transmission and reception circuitry 
   UCSR0C |=  (1 << UCSZ00) | (1 << UCSZ01); // Use 8-bit character sizes 

   UBRR0L = 0x0c; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register 
   UBRR0H = 00; // Load upper 8-bits of the baud rate value into the high byte of the UBRR register

well i am using 4800 baud rate because the other functions best suit 1mhz freq.

for a test program that just listens for a byte and echos it back to pc



Code:
for (;;) // Loop forever 
   { 
      //enable_rx;
     PORTD|=0x01;
while ((UCSR0A & (1 << RXC0)) == 0) {}; // Do nothing until data have been recieved and is ready to be read from UDR 
      ReceivedByte = UDR0; // Fetch the recieved byte value into the variable ByteReceived" 


      //enable_tx 
       PORTD&=0xFE
      while ((UCSR0A & (1 << UDRE0)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it 
      UDR0 = ReceivedByte; // Echo back the received byte back to the computer 
   }
is this all ok, plz comment on code and give a better one if available....
thanx in advance


if someone can guide me to a tutorial on hyper terminal that would be really a great help...
 

OK guys i got the mistake
after
Code:
UDR0 = ReceivedByte; // Echo back the received byte back to the computer
i should let the MCU transmit the contents before switching to receiving mode


now another request plz can someone share a circuit /schematic for rs485 using max485 keeping in mind distances upto 70 meters

Added after 2 hours 6 minutes:

should this circuit work if r39,r36 & r40 are not used? also the zener and the led section also be removed **broken link removed**
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top