i have interfaced two p89v51rd2 micro-controllers configuring one as master and another as slave.
but i'm not getting any data and spi data transfer is not taking place. i used cro to check the spi clock signal but i'm just getting 5v dc signal. dont know what is the problem.
please anyone check whether my code is correct... i have doubt in slave configuration.
code for master:
#include "p89v51rx2.h"*** **
#include <INTRINS.H>
sbit*** SS= P1^4;
sbit*** spiclk = P1^7;
sbit*** MOS1 = P1^5;
sbit miso = P1^6;
sbit**** st = P2^1;
sbit*** irq = P2^0;
char xacc1,xacc2;
unsigned int i=0;
*
void msdelay( unsigned int);
void serial ();
*
void main()
{
**
* SS = 1;
* irq = 1;
* SPCTL = 0xdf;
* SPCFG = 0X00;
* P1 = 0x40;
* ES0 = 1;
*
*while (1)
* {
*** SPDATA = 0X11;
*** while (!(SPCFG & 0x80));
*** SPCFG = 0X00;
*** serial (); ***
** }
}***
*
*void msdelay(unsigned int ms)
{
unsigned int i,j;
for (i=0;i<ms;i++)**
for (j=0;j<53;j++);
}
*
void serial ()
*{
*
*while (1)
* {
** TMOD = 0x20;
** TH1 = 0xfd;
** SCON = 0x50;
** TR1 = 1;
** TI = 0;
** SBUF = xacc1;
** while (!TI);
** TI = 0;
*
** TR1 = 1;
** SBUF = xacc2;
** while (!TI);
** TI = 0;
* }
code for slave:
#include "p89v51rx2.h"
#include <INTRINS.H>
sbit*** SS= P1^4;
sbit*** spiclk = P1^7;
sbit*** MOS1 = P1^5;
sbit*** MISO = P1^6;
sbit*** irq = P2^0;
*
*unsigned int i=0;
*
void main()
{
* SPCFG = 0X00;
* SPCTL = 0xcd;
* P1 = 0xc0;
* SS = 0;
* ES0 = 1;
*
* irq = 0;
* while (!(SPDATA == 0X11));
**** SPDATA = 0x4E;
*** *for(i=0;i<10;i++);*
*
** while (!(SPDATA == 0X22));
**** SPDATA = 0x52;
* *** *for(i=0;i<10;i++);
*}
please tell me what is the problem with the code... thank u
but i'm not getting any data and spi data transfer is not taking place. i used cro to check the spi clock signal but i'm just getting 5v dc signal. dont know what is the problem.
please anyone check whether my code is correct... i have doubt in slave configuration.
code for master:
#include "p89v51rx2.h"*** **
#include <INTRINS.H>
sbit*** SS= P1^4;
sbit*** spiclk = P1^7;
sbit*** MOS1 = P1^5;
sbit miso = P1^6;
sbit**** st = P2^1;
sbit*** irq = P2^0;
char xacc1,xacc2;
unsigned int i=0;
*
void msdelay( unsigned int);
void serial ();
*
void main()
{
**
* SS = 1;
* irq = 1;
* SPCTL = 0xdf;
* SPCFG = 0X00;
* P1 = 0x40;
* ES0 = 1;
*
*while (1)
* {
*** SPDATA = 0X11;
*** while (!(SPCFG & 0x80));
*** SPCFG = 0X00;
*** serial (); ***
** }
}***
*
*void msdelay(unsigned int ms)
{
unsigned int i,j;
for (i=0;i<ms;i++)**
for (j=0;j<53;j++);
}
*
void serial ()
*{
*
*while (1)
* {
** TMOD = 0x20;
** TH1 = 0xfd;
** SCON = 0x50;
** TR1 = 1;
** TI = 0;
** SBUF = xacc1;
** while (!TI);
** TI = 0;
*
** TR1 = 1;
** SBUF = xacc2;
** while (!TI);
** TI = 0;
* }
code for slave:
#include "p89v51rx2.h"
#include <INTRINS.H>
sbit*** SS= P1^4;
sbit*** spiclk = P1^7;
sbit*** MOS1 = P1^5;
sbit*** MISO = P1^6;
sbit*** irq = P2^0;
*
*unsigned int i=0;
*
void main()
{
* SPCFG = 0X00;
* SPCTL = 0xcd;
* P1 = 0xc0;
* SS = 0;
* ES0 = 1;
*
* irq = 0;
* while (!(SPDATA == 0X11));
**** SPDATA = 0x4E;
*** *for(i=0;i<10;i++);*
*
** while (!(SPDATA == 0X22));
**** SPDATA = 0x52;
* *** *for(i=0;i<10;i++);
*}
please tell me what is the problem with the code... thank u