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 using 89c51ED2 - help needed

Status
Not open for further replies.

aniket4eda

Newbie level 3
Newbie level 3
Joined
Oct 6, 2007
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,327
SPI using 89c51ED2

Hi friends,
I am using 89c51ED2 in my app. It is configured as a master and I'm trying to use on chip SPI to communicate with the ADE7758. As given in the data sheet of ED2 I've configured the interrupt for the SPI. It's generating the interrupt but the communication is not starting. I've also checked the signals SCLK, MISO, MOSI on the CRO but it's not giving any signals. Please help me as early as possible.
 

Re: SPI using 89c51ED2

How can someone help you troubleshoot your problem if you do not post your code?
 

Re: SPI using 89c51ED2

sorry..
Here's the code I've used.

I am using the KEIL uVision 3 IDE. I've also checked whether the SPI interrupt is coming or not? it's giving the interrupt.

//dsp7758.c
#pragma NOAREGS
void ReadDSP7758(unsigned char address, unsigned char length)
{
idata unsigned char index=0x00;
SPIStart();
SPIWrite(address);

HOLD

while(index<length)
{
SPIBUF[index]=SPIRead();
index++;

HOLD

}
SPIStop();
}
#pragma AREGS

#pragma NOAREGS

void WriteDSP7758(unsigned char address, unsigned char length)
{
unsigned char index=0x00;
SPIStart();
SPIWrite(address);

HOLD

while(index<length)
{
SPIWrite(SPIBUF[index]);
index++;

HOLD

}
SPIStop();
}

#pragma AREGS


//spi.c

unsigned char serial_data;
bit transmit_completed= 0;

unsigned char SPIBUF[3];

xdata unsigned char temp_value;


void it_SPI(void) interrupt 9 using 1 /* interrupt address is 0x004B */
{
switch ( SPSTA ) /* read and clear spi status register */
{
case 0x80:
serial_data=SPDAT; /* read receive data */
transmit_completed=1;/* set software flag */
temp_value++;
break;

case 0x10:
/* put here for mode fault tasking */
temp_value=0;
break;

case 0x40:
/* put here for overrun tasking */
temp_value=0;
break;
}

}

//#pragma AREGS

void SPIStart()
{
SPCON |= 0x10; /* Master mode */
P1_1=1; /* enable master */
//SPCON |= 0x82; /* Fclk Periph/128 */
SPCON |= 0x81; /* Fclk Periph/64 */

SPCON &= ~0x08; /* CPOL=0; transmit mode example */
SPCON |= 0x04; /* CPHA=1; transmit mode example */

IEN1 |= 0x04; /* enable spi interrupt */
SPCON |= 0x40; /* run spi */
EA=1; /* enable interrupts */

CS=0; //Chip Select of ADE7758

}

void SPIStop()
{
CS=1;
SPCON &= ~0x40; /* stop spi */
}

#pragma AREGS

//====================================================

void SPIWrite(unsigned char spidata)
{
SPDAT=spidata; /* send an example data */
while(!transmit_completed);/* wait end of transmition */
transmit_completed = 0; /* clear software transfert flag */

}

#pragma AREGS
//==================================================================================================================================

#pragma NOAREGS

unsigned char SPIRead()
{

SPDAT=0x00; /* data is send to generate SCK signal */
while(!transmit_completed);/* wait end of transmition */
transmit_completed = 0; /* clear software transfert flag */
//data_save = serial_data; /* save receive data */

return serial_data; /* save receive data */

}

#pragma AREGS

//main.c

void main()
{
SPIBUF[0]=0x40;
WriteDSP7758(WR_APHASE,1);

while(1)
{
ReadDSP7758(RD_WAVMODE,1);
test_value=SPIBUF[0];

DisplayPage(); //displays value of WAVMODE and also the
// temp_value which is incremented in the SPI interrupt
}

}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top