drtvskuthsav
Member level 2
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.
Regards
Kuthsav Thattai
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