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.

need SPI interface coding in C (for 8051)

Status
Not open for further replies.
You have ready-for-use example in atmel web site for hardware SPI.

For software SPI, may consider using discrete IO pins as

Code:
#define uchar	unsigned char

sbit RF_MISO	= P2^3;  //say
sbit RF_MOSI	= P2^2;
sbit RF_SCK	= P2^1;
sbit RF_CSN	= P2^0;
...

void   spiWr(uchar);
uchar spiRd(void);

...

/*
*********************************************************************************************************
* Low level SPI WRITE FUNCTION
*********************************************************************************************************
*/
void spiWr(uchar dat)
{
		/* software SPI, send MSB first */
	static uchar i,c;

	c = dat;
	for(i=0;i<8;i++)
	{
	if((c&0x80)==0x80)
		RF_MOSI = 1;
	else
		RF_MOSI = 0;

	RF_SCK = 1;
	c=c<<1;
	RF_SCK = 0;
	}
}

/*
*********************************************************************************************************
* Low level SPI READ FUNCTION
*********************************************************************************************************
*/
uchar spiRd(void)
{
	/* software SPI read, MSB read first */
	static uchar i, dat;

	for(i=0;i<8;i++)
	{
		dat = dat<<1;
		RF_SCK = 1;
		if(RF_MISO)
			dat = dat+1;
		RF_SCK = 0;
	}
	
	return dat;
}

John
 
Last edited by a moderator:
i need the SPI coding for the C515 controllers of infenion or siemens the basic structure is similar to the 8051 but with enhance periphirals :?:[/b]
 

TechToys's code is useable on C515
 

i know that the SPI is code is standard in all controllers but i need for C515C controller in which factory test register available by using this register without any slave we can check the SPI communication. :cry:
 

hi,

following are the detail of registers

23_1166263831.JPG


following is the register used for the factory testing

1_1166263885.JPG
 

Code:
       ORL SSCMODE,#$80  ; set LOOPB to 1
       MOV STB,#$5A      ; send $5A to SPI output
Wait:       
       MOV A,SCF         ; SSC Status Register
       JNB A.0,Wait      ; wait until Transfer completed
       MOV A,SRB         ; receive $5A on Receive Buffer Register
 

hi every one;

i want to interface sd card with 8051 in spi mode...
want help in programming in embedded C...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top