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.

Internal SPI interface in ATMEL 89c51re2 microcontroller

Status
Not open for further replies.

gtlg

Newbie level 3
Joined
Sep 8, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,304
We are using atmel 89c51re2 ic. We want to use the internal SPI in this microcontroller ic. We have connected adc3208 ic which also support spi inteface.

We have done pin conncetions for the above setup as below,


89c51re2 adc 3208

sclk(pin 2) sclk(pin 13)
mosi(pin 3) mosi(pin 12)
miso(pin 1) miso(pin 11)
cs (pin 41) cs(pin 10)

Does the above connection is correct?

We are using internal spi first time. We have got applictaion note from atmel site regarding the use of spi. We have implemented the same logic.
Code:
#include "at89c51RE2.h"
char serial_data;
char data_example=0x55;
char data_save;
bit transmit_completed= 0;

void main(void)
{
SPCON |= 0x10;								 /* Master mode */
SPCON |= 0x82; 								/* Fclk Periph/128 */
SPCON |= 0x20; 								/* P1.1 is available as standard I/O pin */
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 */
while(1) /* endless */
{

// here the SPDAT	register contain the value that we are need to pass to adc 3208 ic

SPDAT=0XC0; 					/* send an example data */
while(!transmit_completed);			/* wait end of transmition */
transmit_completed = 0; 			/* clear software transfert flag */

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

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 */
}
}


/**
* FUNCTION_PURPOSE:interrupt
* FUNCTION_INPUTS: void
* FUNCTION_OUTPUTS: transmit_complete is software transfert flag
*/

void it_SPI(void) interrupt 9 /* 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 */
break;
case 0x10:
								/* put here for mode fault tasking */
break;
case 0x40:
								/* put here for overrun tasking */
break;
}
}

The problem is that when we are debugging the above code in keil compiler at that time the spi interrupt is gets generated but in SPSTA register instead of 0x80 we are getting 0x88 value... so that the loop is not comming out of while loop.

Why the value of SPSTA REGISTER COMMING AS 0X88 INSTEAD OF 0X80??

Even we have not connect any thing to controller MOSI,MISO,SCLK pins and try to watch the pulses. When we send the first data into SPDAT REGISTER at that time we are able to see the pulses. But after that when we send one more data to SPDAT register thoes pulses are not generating, nothing to display on cro no pulse nothing. We thought may be it will wait for interupt from slave so we again connect the ADC 3208 but pulses were not generating. May be it is stucking in while(!transmit_completed); loop...Why it is happening? Please reply

Please guide us for the same as early as possible. We want the urgent solution for the same as we have trying for more times on this.
 
Last edited by a moderator:

any body can give the solution for this???
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top