slave1.c
来自「ADuC系列芯片的源代码事例」· C语言 代码 · 共 58 行
C
58 行
/*********************************************************************
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 + =
减小字号Ctrl + -
显示快捷键?