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 MASTER(PC) - SLAVE(ATMEGA8515)

Status
Not open for further replies.

_SquiD_

Advanced Member level 4
Joined
Jul 30, 2008
Messages
114
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Activity points
2,035
I want to make a communication MASTER (PC) - SLAVE (ATMEGA8515) using RS485.
I want the MASTER to send a data of 8 bits, on the SLAVE I would like to light up (on some LED's) PORTB (let's say) in order to show me the 8bit data received.

Can anyone help me with some sample code ?

Thanks in advance.

-SQD-
 

Hi,
Which language and compiler?
If you use UART, it won't be very difficult. I can help you with sample code if you can use mikroBASIC.
Tahmid.
 


@Tahmid:
I'm using AVR Studio with avr-gcc (C coding).

Bogdan M.
 

@Tahmid: It will be good a MikroC version of what I asked. I will try to adapt the code for AVR Studio. I don't like about MikroC those predefined functions (UART1_Init(), USART1_Data_Ready(), UART1_Read(), UART1_Write() ) that you must use, I would rather write them explicitly in my code.

Bogdan M.
 

Hi Squid,
Okay, it is possible to make explicitly with own code. But usually I use the predefined functions as it makes life so much easier.
Anyway, I'll be looking to post a sample soon.
Will your master be PC or an AVR?
Tahmid.
 

Good stucture sample for AVRGCC from Avrfreaks
 

@ Tahmid: For the moment I want to make the communication with the PC as MASTER. After that I will try myself to write a code for the MASTER on a ATMEGA8515.

@medap:
Thanks for the links and the code. I will see if they will come on handy. :)

Bogdan M.
 

Hii, if you want to use master slave communication there is a several way :

1. SPI serial peripheral interface
2. RS-485 multinode
3. RS-422 single node (same as uart but the distance is longer)

if you want to use pc as mater then you have to use rs-232 to rs-485 level converter, cause the level rs-232 is different from rs-485. If you want reference for the circuit you can visit mikroelektonika site. there is a sample and source code for this problem.

But if you want more simple way in programming, you can use PC and 2 microcontroller. PC will comunicate with micro using uart protocol the micro will communicate with other micro using SPI.

I've already made A master slave comunication using 2 atmega 8535 using SPI protocol it's quite easy to use. My master just display the result to lcd and my slave is control i2c device like PCF8951 (adc), ds1307 (RTC) and 24c04a (eeprom). I use bascom AVR as my compiler.

If you need reference I will send to you. Okay.

DENY (BODAT'Z)
 

Hi,
Try this:
Code:
#include <avr/io.h>

//Receives Data via USART module and resends data
//Echoes received data
//PORTD0 = Rx pin
//PORTD1 = Tx pin
//9600bps, 8 bit, no parity, 1 stop bit, asynchronous
//System Clock: 8MHz
//Clock Source: Int RC
//Programmed by: Tahmid
//February 01, 2010

unsigned char Received;

void main(void){
	DDRD = 0xFE; //PD0 = Rx, PD1 = Tx
	UBRRL = 51; //9600bps
	UCSRB = (1<<RXEN)|(1<<TXEN); //Enable Receiver and Transmitter
	UCSRC = 6; //8-bit, no parity, 1 stop bit, asynchronous
	do{
		while ((UCSRA & 0x80) == 0); //Wait for data to be received
		Received = UDR;
		while ((UCSRA & 0x20) == 0); //Wait for buffer to receive new data
		UDR = Received;
		while ((UCSRA & 0x40) == 0); //Wait for transmission to complete
	}while (1);
}
Hope it helps.
Tahmid.

Added after 1 minutes:

P.S. It is written with WinAVR & AVR Studio.
 

@balistic: I intend to finally make a RS485 multinode using USART. If you can help me in this matter I would appreciate it.

@Tahmid: The code you're showing to me it's a RS232 echo application, right ? I managed to make this RS232 communication work.

Now I wanna know what modifications should I bring to this code in order to make the RS485 communication.

Bogdan M.
 

Hi,
Yes, it's an RS232 echo app.
For RS485, I suggest you use mikroC as it has the internal library. I've not done the RS485 myself, but shouldn't be very difficult with the library.
Tahmid.
 

For what it is worth, I wrote a series of 2 articles entitled "Generic Modbus Simulator" that appeared in issues 200 and 201 (March/April 2007) of Circuit Cellar. In it I describe the creation of a Modbus Master on a PC

**broken link removed**
**broken link removed**

I describe the design and coding of a Modbus slave in a follow up article "Create A Modbus Slave" that appeared in issue 216 (July 2008) of Circuit Cellar. Although I developed my code for the slave on the PSoC, it was developed in C so should be easily converted to any micro.


**broken link removed**

-Aubrey

P.S. Circuit Cellar's business model is to charge a nominal amount to download the articles.
 

Tahmid said:
Hi,
Which language and compiler?
If you use UART, it won't be very difficult. I can help you with sample code if you can use mikroBASIC.
Tahmid.

hello Tahmid

i am also facing same problem with PC to mater controller communication problem on Rs485 network using mikrobasic and PIC16F877A
regards
sohail
 

Hi,
O. I can help you with mikroC or mikroBASIC. I haven't used AVR Studio.
Tahmid.

can help me with mikro c coding..? i have seen example in mikro c but still not working .. i am need to how to test the master slave with pc...
 

hi all
i also wanted to build rs 485 but in my case i want to send data from slave uC in this case a clock data to master uC and display it on 7 seg
is there anyone could help me with the code
iam familiar with bascom-avr compiler

thanks in advance
 

hi all
i also wanted to build rs 485 but in my case i want to send data from slave uC in this case a clock data to master uC and display it on 7 seg
is there anyone could help me with the code
iam familiar with bascom-avr compiler

thanks in advance

since u ar using rs- 485.u need to have use a driver say max 485.
for communication.since rs-485 have 2 wire comm. u have to use serial comm.using uart
can u tell me which controller u are using?
 

i do not know much about avr series.but in opinion the serial port programming remain same ,cause avr also have uart. so using the rs-485 protocol will remain same. u want to send a clock data. study the atmel rs -485 rules for serial communication. u have to send the address of master uC, to it.after dat u can send the data..... read the article on uart programming on atmel website.. it will be helpfull to u.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top