⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slave1.c

📁 ADuC7020开发板SPI程序, 授权开发, 内部资料,共享, 后续程序值得学习
💻 C
字号:
/*********************************************************************

 Author        : ADI - Apps            www.analog.com/MicroConverter

 Date          : Sept. 2005

 File          : slave1.c

 Hardware      : Applicable to ADuC702x rev H or I silicon
                 Currently targetting ADuC7026.

 Description   : SPI slave is to use with master.c or master1.c
 				 the slaves receives values from the master and
				 keeps transmitting '0' as it is the default value at reset.
		
*********************************************************************/



#include<ADuC7026.h>
void My_IRQ_Function(void);				//	IRQ Funtion Prototype 
char i;	
char received_data[30];


int main(void) {

	IRQ = My_IRQ_Function;
	GP4DAT = 0x04000000;			// P4.2 configured as an output. LED is turned on	
	IRQEN = SPI_SLAVE_BIT;

	GP1CON = 0x22220000;				// configure SPI on SPM
	SPICON = 0x1409;					// enable SPI slave mode
	
while (1) {

	}			
}


/********************************************************************/
/*                                                                  */
/*		Interrupt Service Rountine									*/
/*                                                                  */
/********************************************************************/

void My_IRQ_Function() {
	GP4DAT ^= 0x00040000;		// Complement P4.2
	if ((IRQSTA & SPI_SLAVE_BIT) != 0) {
		received_data[i] = SPIRX;
		i++;
		SPITX = i;
		if (i==30) i=0;
	}
	return ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -