Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SPI problem in P89v51RD2

Status
Not open for further replies.

moni_

New Member
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
 
Did you swap the MISO/MOSI lines?
 
ya while making the external connection i did it... i mean i connected mosi pin of master to miso pin of slave and viceversa...
 
Can't really help with the code, not familiar with that micro controller at all. The only thing I can suggest is before suspecting the code re-verify all I/O lines are connected properly and that the SPI clock rate is set properly. SPI clock must be at least 4 times lower than the system clock to properly function. (Please note system clock which is not always the same as the frequency of the main oscillator such as with older PICs)
 
not familiar with that micro controller at all.

Which leads me to question why you even post in the MCS-51 section in the first place. ;)

To the OP...in order to help with the code it would be a big help if you can tell us what compiler you're using.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top