0% found this document useful (0 votes)
6 views4 pages

Multiprocessor Communication Mode

mode

Uploaded by

Schwarz Chimunhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Multiprocessor Communication Mode

mode

Uploaded by

Schwarz Chimunhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Multiprocessor Communication Mode

Do Steps 1 to 4 below:

Step 1. Carefully, read the following in the ATmega328P datasheet:


19.6.2 Sending Frames with 9 Data Bits
19.7.2 Receiving Frames with 9 Data Bits
19.9 Multi-processor Communication Mode
19.9.1 Using MPCMn (follow the steps)

Step 2. Wire this circuit below (for the simulation in Step 3):

Step 3. Simulate the example codes below:

In Transmitter Code, interchange receiver address between ‘1’ and ‘2’ to select receiver,
build project and simulate in each case – observe display of transmitter PORTD (PD2 – PD7)
on selected receiver.

//Transmitter Code
/*
* MasterCode.c
*
* Created: 2021/08/09 13:06:03
* Author : SibandaA
*/

//Master code

#define F_CPU 16000000


#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <string.h>
#include <math.h>

int main(void)
{
DDRD = 0b00000011;
UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 < UCSZ02);
UBRR0L = 103;
while(1)
{
while(!(UCSR0A & (1 << UDRE0))); //wait until UDR0 Empty flag
UCSR0B |= (1<<TXB80); //set 9th bit to send address
UDR0 = '1'; //send address to receivers
while(!(UCSR0A & (1 << UDRE0))); //wait until UDR0 Empty flag is set
UCSR0B &= ~(1<<TXB80); //clear 9thbit to send data
UDR0 = (PIND & 0xFC); //send data
}
return 0;
}

//Receiver 1 Code

/*
* MasterCode.c
*
* Created: 2021/08/09 13:06:03
* Author : SibandaA
*/

//Master code

#define F_CPU 16000000


#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <string.h>
#include <math.h>

int main(void)
{
DDRD = 0xFF;
UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 << UCSZ02);
UCSR0A |= (1 << MPCM0);
UBRR0L = 103;
unsigned ch;
PORTD = 0x00; //Turn OFF PORTD
while(1)
{
while(!(UCSR0A & (1 << RXC0))); //wait until character is received
ch = UDR0;
if(ch == '1') //if Receiver 1 address
{
UCSR0A &= ~(1 << MPCM0); //clear MPC mode on Receiver 1
while(!(UCSR0A & (1 << RXC0))); //wait until data is received
PORTD = UDR0; //display received data on PORTD
}
}
return 0;
}

//Receiver 2 Code

/*
* MasterCode.c
*
* Created: 2021/08/09 13:06:03
* Author : SibandaA
*/

//Master code

#define F_CPU 16000000


#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <string.h>
#include <math.h>

int main(void)
{
DDRD = 0xFF;
UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 << UCSZ02);
UCSR0A |= (1 << MPCM0);
UBRR0L = 103;
unsigned ch;
PORTD = 0x00; //Turn OFF PORTD
while(1)
{
while(!(UCSR0A & (1 << RXC0))); //wait until character is received
ch = UDR0;
if(ch == '2') //if Receiver 2 address
{
UCSR0A &= ~(1 << MPCM0); //clear MPC mode on Receiver 2
while(!(UCSR0A & (1 << RXC0))); //wait until data is received
PORTD = UDR0; //display received data on PORTD
}
}
return 0;
}

Step 4. For your project, work on your coding as follows:


• Configure any device that has to transmit (whether project master or slave) as
multiprocessor communication mode master while others are slaves (with addresses),
for the sake of transmitting
• Configure any device that has to receive (whether project master or slave) as
multiprocessor communication mode slave (with address), for the sake of receiving

You might also like