那就是代码没问题,是STC芯片的问题喽 |
datasheet没仔细看 结果15f从机本身就不正常!换了15w就解决了 |
zhou792008 发表于 2015-10-5 01:13 怎么解决的,楼主能分享一下吗。期待 |
刚想请教 |
已经完美 |
问题已经找到 |
//从机源码 #include <STC15F2K60S2.H> #include <STDIO.H> #include "AD_UartInit.H" uchar j; void main() { DA_Pointer_Array= DA_Array; DA_InitSpi(); AD_UartInit(); SPI_receive=0; IE2=IE2|ESPI; //使能SPI中断 EA=1; while(1){ for(j=0;j<144;j++) //RAM初始化 { DA_Array[j]=0; } while(!RI); RI=0; for(j=0;j<144;j++) { TI=1; printf("0x%bx\n",DA_Array[j]); } DA_Pointer_Array= DA_Array; } } void spi_isr() interrupt 9 using 1 //SPI中断服务程序 9 (004BH) { SPSTAT = SPIF | WCOL; //清除SPI状态位 0XC0 *DA_Pointer_Array=SPDAT; DA_Pointer_Array++; } |
/芯片的工作频率为22.1184MHz 主机源码 #include<STC15F2K60S2.H> #include <INTRINS.H> #include<ABSACC.H> #include<STDIO.H> #include "AD_SPI.H" #include "AD_UartInit.H" #define ulong unsigned long // 4 byte #define uint unsigned int //2 byte 0-65535 #define uchar unsigned char // byte 0-255 #define nop8(); {_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}; void Delay20us(); void Delay50ms(); uchar *AD_array_point; uchar xdata AD_ZERO[144] _at_ 0x20; uchar k,i,j; void main() { Delay50ms(); AD_UartInit(); AD_InitSpi(); IE2 |= ESPI; EA = 1; while(1){ for(j=0;j<144;j++) //RAM初始化 { AD_ZERO[j]=0; } /**********************/ while(!RI); //***** RI=0; for(k=0;k<144;k++) //72通道采样 { AD_ZERO[k]= k; } /********发送数组到从机***************/ AD_array_point=AD_ZERO; //定位调零数组 for(k=0;k<144;k++) { SS=0; SPDAT=*AD_array_point; AD_array_point++; Delay20us(); Delay20us(); Delay20us(); Delay20us(); Delay20us(); Delay20us(); } /***********显示发送到从机的数组*********************/ AD_array_point=AD_ZERO; for(k=0;k<144;k++) { TI=1; printf("0X%bx\n",AD_ZERO[k]); //0928屏蔽 } } } void Delay50ms() //@22.1184MHz { unsigned char i, j, k; _nop_(); _nop_(); i = 5; j = 52; k = 195; do { do { while (--k); } while (--j); } while (--i); } void spi_isr() interrupt 9 using 1 //SPI中断服务程序 9 (004BH) { SPSTAT = SPIF | WCOL; //清除SPI状态位 SS = 1; //拉高从机的SS } void Delay20us() //@22.1184MHz { unsigned char i; i = 108; while (--i); } |