Prayuktibid
Newbie level 6
I am trying to communicate between two Atmega32 through RS485 Driver .. I am using MAX487 IC and Atmega32 MCU, whenever I am simulating on Proteus its not giving any output.. I have done many way but I unable to solve this. Please help me.
Here my schematics
This is my code
and Oscilloscope Output
Here my schematics
This is my code
HTML:
#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define MAXTTEpin 2
#define SET_MAXTE(a,b) ( (a) |= (1 << (b) ) )
#define CLR_MAXTE(a,b) ( (a) &= ~(1 << (b) ) )
#define Led 1
#define Button 1
/*Initilize RS485 data Transmission*/
void RS485init(void)
{
DDRD|= (1<<MAXTTEpin); //make max transmitter enabled pin OUTPUT
CLR_MAXTE(PORTD,MAXTTEpin); //Clear Transmitter enabled pin
UCSRB|=(1<<TXEN)|(1<<RXEN)|(1<<RXCIE); //Enabled transmitter and Receiver and Interrupt on RXC
UCSRC|=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); //SET 8 Character, one stop bit, No parity
UBRRL=0x33; //Set baud 9600
sei(); //Set Interrupt
}
/*IRS485 data Transmitter*/
void RS485Transmitt(char x)
{
SET_MAXTE(PORTD,MAXTTEpin);
_delay_ms(1); //Set Transmitter enabled pin
while(!(UCSRA&(1<<UDRE))); //Check whether Transmitter data buffer is empty or not
UDR=x; //Receive data on UDR register
while(!(UCSRA&(1<<TXC))); //Check whether Transmission complete or not
UCSRA|=(1<<TXC); //Make TXC HIGH
CLR_MAXTE(PORTD,MAXTTEpin);
_delay_ms(1); //Clear Transmitter enabled pin
}
/*IRS485 data Receive Inturrept Vector*/
ISR(USART_RXC_vect)
{
cli();
PORTA = UDR;
_delay_ms(1);
sei(); //send data to port A from UDR
}
/*Main Function*/
int main()
{
char data=0;
DDRA|=(1<<Led);
DDRB&=~(1<<Button); //make pin0 OUTPUT and other pins are INPUT of PORTA
RS485init(); //Initialize Trans receiver
while(1)
{
data=PINB; //Take data from Pin A
RS485Transmitt(data);
_delay_ms(1); //Transmit Data
}
}
and Oscilloscope Output