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.

SPI Communication between 2 controllers

Status
Not open for further replies.

Rohi231

Member level 2
Joined
Mar 21, 2012
Messages
53
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,673
Hello every1. I am doing SPI communication between master and slave. Program is currently working from master to slave. My question is whether we can do communication from slave to master?
Thanks in advance.
 

it is easy to implement with the help of interrupt pin.
slave with onterrupt output and master with interrupt input configuration
example: CAN Controller MCP2515 interface with microcontroller , ENC28j60 interface ...




slave interrupt initiated a master read.
 
HI Keith. Thanks for the repla. I have searched in search index. There is no required information. I just wanted to know is there any initialization while we are communicating from slave to master. I am using P89V51RD2.

- - - Updated - - -

Hi Jestin_cubetech.
Thanks for the schematic . Here i am doing PC to PC communication. I can do one way communication. Not 2 way. I am not able to understand interrupt concept .Is there anyway you can help me.?
 

A slave is a slave and cannot initiate a transfer. It can respond to a request for data transmission from the master.

Keith.
 
interrupt concept is simple.

if master want to communicate to slave , master generate clock , exchange data - no confusion


if slave want to communicate slave generate an interrupt[usually an active low interrupt ] ,then master recognize slave want communicate to master , then master generate clock pulse read interrupt register , take appropriate actions...
 
Last edited:

You could use two independent SPI interfaces if you have them available.

Keith
 

@keith

m interfacing sd card with p89v51rd2 using spi communication please suggest the hardware interfacing required for this,bz sd card is required 3.3 v and p89v51rd2 requires minimum 4.5 supply.
Please suggest.
 

@ Jestin_cubetech
Thanks a lot Jestin. Instead of using interrupt i will make one bit high in micro controller while to read the data and i will make 1 bit low while i write the data. Correct me if i am wrong. Thanks in advance.

@ Keith: Thanks for the reply. I have only one SPI interface in micro controller P89V51RD2. That mean i should use interrupt concept. Correct me if i am wrong.
 

That mean i should use interrupt concept. Correct me if i am wrong.

The use of interrupts is normally preferable to polling in the majority of cases.

Polling can often lead to the useless burning of cycles, where the use of interrupts can often alleviate this issue.

The interrupt triggers the MCU to service a task when needed versus repeated polling for an event which may or may not occur.

BigDog
 

Thank a lot Bigdogguru. I need one more suggestion from you. Do you think can i go with P89V51RD2 to interface SD card. It has only 1 k ram. I really need strong advice in this.Thanks in advance.
 

Hello every1. I am doing SPI communication between master and slave. Program is currently working from master to slave. My question is whether we can do communication from slave to master?
Thanks in advance.

Hi,
Even I am trying for the SPI communication between master and slave with both ends as P89v51rd2 microcontrollers.
But there is no SPI communication taking place through the code.
Cant figure out the problem.
Please help me with my code and check if the configurations done in the code are correct.
The connections are straight forward i.e.
SS of master-->SS of slave
MOSI of master-->MOSI of slave
MISO of master-->MISO of slave
clk from master-->clk of slave
There is a buzzer defined in the slave for debug but its not going ON
On the other hand, the spi_master_tx() function is executing completely.
Please review and help asap. THANKS


The master micro-controller is working fine....as in the program for the master side executes completely(along with the debugger code lines)....but I think there is some issue with the slave configuration...because the check performed on the SPIF bit on the slave side is never complete...hence the program is stuck in the---> while(!(SPSR & 0X80)); loop forever.

MASTER

#include<p89v51rd2.h>
#include<LCD.h>
#include<DELAY.h>


#define ss_pin P0_4
#define mosi_pin P0_5
#define miso_pin P0_6
#define spi_clk P0_7
#define buzzer P0_3

void spi_config_master()
{
mosi_pin=1;
spi_clk=1;
ss_pin=0;
SPCR=0X51;
SPSR=0X00;
SPDAT=0X00;
}
void spi_master_tx(unsigned char data_given_to_slave)
{
unsigned char temp;
temp=data_given_to_slave;
//ss_pin=0;
//ss_pin=1;
SPDAT=temp;
while(!(SPSR&0X80))
{
buzzer=0;
DELAY(500);
buzzer=1;
DELAY(500);
}
SPSR=0X00;
}
void main()
{
//initialize the port values

P0=0XFF;
P1=0xFF;
P3=0XFF;
P2=0XFF;
buzzer=1;
ss_pin=0;
spi_config_master();
spi_master_tx(1);

}



SLAVE
#include<p89v51rd2.h>
#include<LCD.h>
#include<DELAY.h>

unsigned char data_from_master;
#define ss_pin P0_4
#define mosi_pin P0_5
#define miso_pin P0_6
#define spi_clk P0_7
#define buzzer P0_3

void spi_config_slave()
{
mosi_pin=0;
spi_clk=0;
//ss_pin=0;
SPCR=0X41;
SPSR=0X00;

SPDAT=0X00;
}


void main()
{unsigned char data_from_master;
buzzer=1;//buzzer off
//initialize the port values
P0=0XFF;
P1=0xFF;
P3=0XFF;
P2=0XFF;

LCD_INIT();
spi_config_slave();


while(!(SPSR&0X80))
{buzzer=0;
DELAY(500);
buzzer=1;
DELAY(500);
}
data_from_master=SPDAT;
SPSR=0X00;

buzzer=0;
DELAY(500);
buzzer=1;
LCD_CHAR(data_from_master);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top