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.

[SOLVED] avr and rs485 problem

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 have a circuit[attached] on Pcb, for rs 485 and am using avr atmega8, now when i make the power on and conncet the rs485 to pc using rs485-rs232 converter using hyper terminal i get this error "cannot open COM Port3 check port settings"

now when the power is removed this msg is not displayed, moreover if just avr is removed from socket even then the msg doesnt appear ...

i dont know why? com port is set, baud rate and data bits parity and stop bit settings are same,on pc as well as avr..and i had used the same type of program before on a prototype that was OK,

i would like to share the test code also
Code:
#include <avr/io.h>
#include <avr/interrupt.h>

Void USART_Transmit(unsigned char data)
{
	PORTC &=~0x20;//pc5 is used for enable of ma
	while (!(UCSRA & (1<<UDRE))) sleep();
	UDR = data;
}

unsigned char USART_Receive(void)
{
	PORTC |=0x20;//PC5 is used for enable of max
	while (!(UCSRA & (1<<RXC))) sleep();
	return UDR;
}
void USART_Init(void)
{
	// USART settings: 4800 baud 8-n-1
	UBRRH = 0;
	UBRRL = 207;
	UCSRB = (1<<RXEN) | (1<<TXEN);
	UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0);
}


main()
{
	
	USART_Init();
	
        

        USART_TransmitString("OK!\r\n");
        for (;;)
        {
	USART_Transmit(USART_Receive());
        }
	
}
 

Attachments

  • s.png
    s.png
    148.2 KB · Views: 97

Actually default com port in a PC is COM1. Didn't you try that?
 

i have a programmer attached to it!
i also changed it to COM1 and as expected same problem "unable to open COM1, plz check your port setting"
 

Remove the programmer from com1 port & insert the com port of RS 485 & then check if its working or not.
Regards,
Jerin. :)
 

did that ... it doesnt work...

i think the problem is some where in programming /or circuit.. if MC is removed it doesnt display any message,
 

Did you check the connections of the circuit for loose contacts/soldering/shortings?
 

its full duplex.. i have used to to have communication both ways... pc-->mc and mc-->pc...

---------- Post added at 13:20 ---------- Previous post was at 13:18 ----------

i checked it and there is no apparent problem .... i am really stucked at this
 

But your circuit is half duplex.... how you are managing to solve that problem... and why your are using series resistors on your RS485 line?
 

We can do full duplex communication by using one com port it self which allows yo communicate in both ways. We use it in controlling PIC through commands from hyper terminal.
Regards,
Jerin.
 

its not mentioned on the converter... and i am using half duplex only... i had used it before with rs 485 of same type and it was working...
 

We used MAX232 IC for the serial communication for PC to controller communication by using RS 232.

---------- Post added at 13:31 ---------- Previous post was at 13:30 ----------

Is any interference affecting your circuit i mean electro-magnetic interference?
 

I am not very used to avr programming so i going to consider that your code of USAR init and managing is correct. And, why you are not enabling the RS485 driver when sending? And you are connecting your diferential pair line to the tranceiver related to TX or RX on the RS485 to RS232 converter?? And shouldnt you check that that data was sent before receiving something? As the processor is much faster than the port, you can not turn MAX485 to receiver mode before sending all the data.
 

Me too............ :)
I have used the other controllers i.e 8051 & PIC.
Regards,
Jerin.
 

although this a test code, the problem you identified can lead to cancellation of some data being sent or recieved.... but y do i get the problem ... cant open com port...

right now i did got the old board that worked... and same problem again ... may be i have some problem with the converter it self....... as both circuits cant be wrong... even when i placed a microcontroller with no rs comm code again the problem occured ...
 

Hmmm do you have a scope with you? You could try to see what is going on on your converter
 

Any loose contact from the cable connected to the computer or are the baud rate setting re different?
 

i replied to the scope question... i dont have one and thats a problem
regarding loose connection or baud rate checked twice again....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top