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.

Help needed with ATmega Multi Processor Communication

Status
Not open for further replies.

drtvskuthsav

Member level 2
Joined
Apr 7, 2010
Messages
46
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,630
Hey guys,
I need some help with MPCM in ATmega32. I tried this mode with two microcontrollers on PROTEUS. The master is transmitting the data, but the slave is not receiving the correct data. I tried this mode with 9bit as recommended in atmega32 datasheet. I am posting code for both master and slave. Please do help me in solving this.
Baud rate=9600
Freq=8MHz
Circuit diagram is attached.


Code:
/*****SLAVE_CODE*****/
//* KUTHSAV*//
//*Including Header Files Required*//
#include <mega32.h>
#include <stdio.h>
#include <stdlib.h>
#include <delay.h>
#include <string.h>
//*Declaring LCD PORT as PORT A*//
#asm
    .equ __LCD_PORT=0x1B; PORTA
#endasm
#include <lcd.h>
#define baud 0x33 /* Baudrate=9600 at 8Mhz IRC Oscillator*/
#define UCB 0xDC /*Enabling TXIE, RXIE TX and RX in 9bit*/
#define rxb 1
#define slave_address 0x01;
/*Declaring Global Variables*/
unsigned char si=0,qi=0,i=0,p=0,j=0,k=0,l=1,g=1,n=0,m=0;
unsigned char z;
unsigned char dl=2000;
char flag;
//char *cmd=NULL;
//char *msg=NULL;
char q[160];
char ch1[60];
char ch2[30];
char ch3[30];
char ch4[6];
char ch5[5];
char control,status,data;
void usart_init(void)
    {
        UCSRA=0x01;
        UCSRB=UCB;
        UCSRC=0x06;
        UBRRH=0x00;
        UBRRL=baud;
    }
interrupt [USART_TXC] void usart_transmit_isr(void)
    {
        if(qi!=si)
        {
            UCSRB&=(~(0X01));
            UDR=q[si++];
        }
    }
  
interrupt [USART_RXC] void rx_isr(void)
{
    status=UCSRA;
    control=(UCSRB&(1<<rxb));
    data=UDR;
   // lcd_putchar(data);
    if(status&(0x01)==1)
        {
            UCSRA&=(~(0x01));
            lcd_putchar('o');            
        }
    else
        {
        lcd_putchar(data);
        
        }       
}
void main(void)
{

lcd_init(16);
//delay_ms(10);
#asm("sei")
usart_init();

    while(1)
    {       
        ;
    }

}
/*****END_SLAVE_CODE*****/



Code:
/*****MASTER_CODE*****/


//?MultiProcessorCommunication?//
//* KUTHSAV*//
//*Including Header Files Required*//
#include <mega32.h>
#include <stdio.h>
#include <stdlib.h>
#include <delay.h>
#include <string.h>
//*Declaring LCD PORT as PORT A*//
#asm
    .equ __LCD_PORT=0x1B; PORTA
#endasm
#include <lcd.h>
#define baud 0x33; /* Baudrate=9600 at 8Mhz IRC Oscillator*/
#define UCB 0xDC; /*Enabling TXIE, RXIE TX and RX in 9bit*/
/*Declaring Global Variables*/
unsigned char si=0,qi=0,i=0,p=0,j=0,k=0,l=1,g=1,n=0,m=0;
unsigned char z;
unsigned char dl=2000;
char flag;
//char *cmd=NULL;
//char *msg=NULL;
char q[160];
char ch1[60];
char ch2[30];
char ch3[30];
char ch4[6];
char ch5[5];
char ch,ph;
void usart_init(void)
    {
        UCSRA|=0x00;
        UCSRB|=UCB;
        UCSRC=0x06;
        UBRRH=0x00;
        UBRRL=baud;
    }
interrupt [USART_TXC] void usart_transmit_isr(void)
    {
        if(qi!=si)
        {   
            UCSRB&=(~0x01);
            UDR=q[si++];
        }
    }
void send_address(unsigned char slave)
    {
        UCSRB|=0x01;
        UDR=slave;
        delay_us(1000);
        UCSRB&=(~0x01);
    }    
void send_data(char *s)
{
     qi=0;
    si=1;
    while(*s)
        {
            q[qi++]=*s++;
        }        
UDR=q[0];
}   
interrupt [USART_RXC] void rx_isr(void)
{
    ch=UDR;
}
void main(void)
{
#asm("sei")
lcd_init(16);
usart_init();
send_address(0x01);
send_data("Kuthsav");
while(1)
 {       
   ;
 }

}
/*****END_MASTER_CODE*****/


Regards
Kuthsav Thattai
 

Attachments

  • figure.jpg
    figure.jpg
    98.2 KB · Views: 141

did you check it in 8 bit mode?

I tried this, code too....
Still getting corrupt message..

Code:
//* KUTHSAV*//
//*Including Header Files Required*//
#include <mega32.h>
#include <stdio.h>
#include <stdlib.h>
#include <delay.h>
#include <string.h>
//*Declaring LCD PORT as PORT A*//
#asm
    .equ __LCD_PORT=0x1B; PORTA
#endasm
#include <lcd.h>
#define baud 0x33 /* Baudrate=9600 at 8Mhz IRC Oscillator*/
#define UCB 0xDC /*Enabling TXIE, RXIE TX and RX in 9bit*/
#define rxb 1
#define slave_address 0x01;
/*Declaring Global Variables*/
unsigned char si=0,qi=0,i=0,p=0,j=0,k=0,l=1,g=1,n=0,m=0;
unsigned char z;
unsigned char dl=2000;
unsigned char flag=0;
//char *cmd=NULL;
//char *msg=NULL;
char q[160];
char ch1[60];
char ch2[30];
char ch3[30];
char ch4[6];
char ch5[5];
char control,status,data;
void usart_init(void)
    {
        UCSRA|=0x01;
        UCSRB|=UCB;
        UCSRC|=0x06;
        UBRRH=0x00;
        UBRRL=baud;
    }
interrupt [USART_TXC] void usart_transmit_isr(void)
    {
        if(qi!=si)
        {
            UCSRB&=(~(0X01));
            UDR=q[si++];
        }
    }
  
interrupt [USART_RXC] void rx_isr(void)
{
    if(flag==0)
   {
    status=UCSRA;
    control=(UCSRB&(1<<rxb));
    data=UDR;
    if((UCSRA&0x01)==1)    
      {
          if((control>>1)==1)
            {
                UCSRA&=(~(0x01));
                UCSRB=0xD8;
//                lcd_putchar('o');
                flag=1;
                return;            
            }
      }
    }            
    else if(flag==1)
        {
        data=UDR;
        lcd_putchar('i');
        lcd_putchar(data);
         return;
        }        

}
void main(void)
{
lcd_init(16);
//delay_ms(10);
#asm("sei")
usart_init();

    while(1)
    {       
        ;
    }

}

I don't think there is some problem with the master. Only slave.
 

Can you post the 2 hex files and proteus .dsn file. zip and post it.
 

I got this error. Please post the complete project files zipped.

----------------------Update---------------


I t shows kuthsav. Should the slaves read the data Kuthsav and display it on lcds?
 

Attachments

  • atmega32_error.jpg
    atmega32_error.jpg
    292.1 KB · Views: 132
  • working.jpg
    working.jpg
    203.1 KB · Views: 160
Last edited:

I got this error. Please post the complete project files zipped.

----------------------Update---------------


I t shows kuthsav. Should the slaves read the data Kuthsav and display it on lcds?

Yes it should read the data 'Kuthsav' and display it on lcd. I'll upload complete project files zipped to night.
Regards
Kuthsav Thattai
 

lcd data was not correct ascii value. I think data is missing in communication.
 

I got this error. Please post the complete project files zipped.

----------------------Update---------------


I t shows kuthsav. Should the slaves read the data Kuthsav and display it on lcds?

The complete project is uploaded. Please try to find the bug and help me in fixing it.
Regards
Kuthsav Thattai
 

Attachments

  • mpcm_2.rar
    208.4 KB · Views: 94

Thank You all for trying to help me...The problem is solved. I still have a doubt.

I tried using slave device design on new .dsn file. And I used COMPIM component and connected it to microcontroller. So I run the simulation of the slave design and then the master design. I got the output when I changed the COMPIM setting as shown in the attached figure(Just tried trail and error).



Now my doubt is why this did not work when we connected master and slaves directly??




 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top