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

📄 spi.c

📁 LPC2129实现从SPI通讯和两个串口定时器中断
💻 C
字号:
      #define d_spi_GLOBALES 1
	  
	  #include "lpc2294.h"
	  #include "config.h"
	  #include "spi.h"
	  #include "uart0.h"
	  #include "com_trans.h"
	  /*#define CPOL (1<<4)
	  #define CPHA (1<<3)
	  #define LSBF (0<<6)
	  #define MSTR (0<<5)		//CONG MODEL

	  #define SPI_MODE (MSTR | CPOL | CPHA | LSBF)
	   */
	  /**********************************************
	  ** SSpiIni()
	  ** function: initial the spi ,setting cong model
	  **************************************************/

	  void SSpiIni(void)	
	  {
	   PINSEL0 |=0x00005500;

	   S0PCR=0x00;
	   S0PCR |=(1<<7);	  //interrupt enable
	   spi_irq_set();
	  }

	  void spi_irq_set()
     {
  
      VICIntSelect=VICIntSelect & (~(1<<0x0A));//(0xffffffbf); //VICIntSelect[6]=0 ==irq
      VICVectCntl4=0x20 | 0x0A;	   // UART0中断分配为IRQ 通道0	 ,0x20为使能IRQ通道0
      VICVectAddr4=(uint32)spi_irq;  //中断函数为uart0_irq
      VICIntEnable=	VICIntEnable | (0x400);	 //VICIntEnable[6]=1

     }

    void __irq spi_irq()		// 对于UART有两种情况可以引发接收中断:接收字节达到接收FIFO的处发点(RDA)和接收超时(CTI)
    {
	  uint8 da;
	  if(S0PSR) ;
	  da=S0PSR;
	  da=S0PDR;
	  UART0_SendByte(da);

	  if(0x01==RXD_BUF[0].state)
	  {    
	    S0PDR=RXD_BUF[0].rx_cmd[send_point];
	    send_point++;
		if(send_point>(5+RXD_BUF[0].length))
		{
	       send_point=0;
		   RXD_BUF[0].state=0x00;
		}
	   }

	 // if(0xAA==da)
	 //    spiR=1;

	  S0PINT=0x01;
	  VICVectAddr=0x0;
	}
	  /******************************************

	  ** name: SSendData()
	  ** function:SPI cong model send data
	  ** input:	  data,(will be sended)
	  ** output: none

	  *******************************************/

	  void SSendData(uint8 data)
	  {
	  S0PDR=data;
	  while(0==(S0PSR & 0x80));
	  }

	   /******************************************

	  ** name:RcvData()
	  ** function:SPI cong model send data
	  ** input:none
	  ** output:received data

	  *******************************************/

	  uint8 SRcvData(void)
	  {
	    while(0==(S0PSR & 0x80));
		return(S0PDR);
	  }

⌨️ 快捷键说明

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