?? spif.c
字號:
Address = (Address << 5) | 0x8000;
// _INT_OFF();
*P_NAND_GPIO_SETUP &= ~PCSN; //使能線置0
Delay(0);
SPI_SB(Address>>8);
SPI_SB(Address);
while(Length--)
{
*DataPtr = SPI_RB();
DataPtr++;
}
*P_NAND_GPIO_SETUP |= PCSN; //使能線置1
// _INT_ON();
}
/****************************************************************************************
* Function:
* Description: 讀ZigBee模塊接收數據包
* Syntax:
* Modify:
* parameter: UINT8 *DataPtr:讀出的數據存放的指針
UINT8 Length: 讀出的數據的長度
* Returns: 無
* Notes:
* Date: 2007-02-27
* Author: ZijianWang
****************************************************************************************/
void spi_rd_rx_fifo(UINT8 *DataPtr, UINT8 *RxLength)
{
UINT8 Length;
// _INT_OFF();
*P_NAND_GPIO_SETUP &= ~PCSN; //使能線置0
Delay(0);
SPI_SB(0xE0);
SPI_SB(0x00);
// Length = SPI_RB(); //接收的第一個數據為幀界定符,忽略
Length = SPI_RB();
*RxLength = Length;
while(Length--)
{
*DataPtr = SPI_RB();
DataPtr++;
}
*P_NAND_GPIO_SETUP |= PCSN; //使能線置1
// _INT_ON();
}
/****************************************************************************************
* Function:
* Description: 中斷中使用的 SPI短地址讀,及地址為1字節,讀出的數據為1字節
* Syntax:
* Modify:
* parameter: UINT8 Address:需要讀的寄存器地址
UINT8 *DataPtr:讀出的數據存放的指針
* Returns: 無
* Notes:
* Date: 2007-02-27
* Author: ZijianWang
****************************************************************************************/
void spi_sr_IRQ(UINT8 Address, UINT8 *DataPtr)
{
Address = (Address << 1);
// _INT_OFF();
*P_NAND_GPIO_SETUP &= ~PCSN; //使能線置0
Delay(0);
SPI_SB(Address);
*DataPtr = SPI_RB();
*P_NAND_GPIO_SETUP |= PCSN; //使能線置1
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//以下為使用芯片SPI驅動的函數
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#else
void InitSPI()
{// Init MCU's SPI Register
*P_SPI_CONF = 0x3; // SPI Clock Enable
*P_SPI_MODE_CTRL = 0x0;
*P_SPI_MISC = 0x00000000; //SPI smart mode,skip data
*P_SPI_TXSTS = 0x80000000; //SPITXLEVEL1, Tx interrupt disable;
*P_SPI_RXSTS = 0x80000000; //SPIRXLEVEL1, Rx interrupt disable;
//*P_SPI_RXSTS = 0x80000000; //SPIRXLEVEL1, Rx interrupt enable;
*P_SPI_MODE_CTRL = 0x80000002; //open SPI clock = 27M/64,Master Mode
*P_SD_INTERFACE_SEL |= 0x100; //Enable SPI
while((*P_SPI_MISC & 0x10)==0x10); //wait for IDLE
}
void spi_sw(UINT8 Address, UINT8 Value)
{
UINT8 temp;
Address = (Address << 1) | 0x0001; //Shfit the Address
_INT_OFF();
*P_SPI_TXDATA = Address; //Write the address
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
*P_SPI_TXDATA = Value; //Write the data
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
while((*P_SPI_MISC & 0x10)==0x10); //wait for IDLE
temp = *P_SPI_RXDATA; //read dummy data
temp = *P_SPI_RXDATA; //read dummy data
_INT_ON();
}
UINT8 spi_sr(UINT8 Address)
{
UINT8 Value;
Address = (Address << 1);
_INT_OFF();
*P_SPI_TXDATA = Address; //Write the address
while(!(*P_SPI_TXSTS & 0x08000000));
Value = *P_SPI_RXDATA; //read dummy data
*P_SPI_TXDATA = 0; //Write the data (For generating the SCLK)
while((*P_SPI_MISC & 0x04)==0x00);
while((*P_SPI_RXSTS & 0x07)>0)
{
while((*P_SPI_MISC & 0x10)==0x10); //wait for IDLE
Value = *P_SPI_RXDATA;
}
_INT_ON();
return Value;
}
void spi_lw(UINT16 Address, UINT8 Value)
{
UINT8 temp;
Address = (Address << 5) | 0x8010;
_INT_OFF();
*P_SPI_TXDATA = Address>>8; //Write the address
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
*P_SPI_TXDATA = Address; //Write the data
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
*P_SPI_TXDATA = Value; //Write the data
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
while((*P_SPI_MISC & 0x10)==0x10); //wait for IDLE
temp = *P_SPI_RXDATA; //read dummy data
temp = *P_SPI_RXDATA; //read dummy data
temp = *P_SPI_RXDATA; //read dummy data
_INT_ON();
}
UINT8 spi_lr(UINT16 Address)
{
UINT8 Value;
Address = (Address << 5) | 0x8000;
_INT_OFF();
*P_SPI_TXDATA = Address>>8; //Write the address
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
*P_SPI_TXDATA = Address; //Write the data
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
// *DataPtr = *P_SPI_RXDATA; //read dummy data //此操作無效,只有IDLE時才能讀數 by zijian
// *DataPtr = *P_SPI_RXDATA; //read dummy data
*P_SPI_TXDATA = 0; //Write the data (For generating the SCLK)
while((*P_SPI_MISC & 0x04)==0x00);
while((*P_SPI_RXSTS & 0x07)>0)
{
while((*P_SPI_MISC & 0x10)==0x10); //wait for IDLE
Value = *P_SPI_RXDATA;
}
_INT_ON();
return Value;
}
void spi_fill_fifo(UINT16 Address, UINT8 *DataPtr, UINT8 Length)
{
UINT8 temp,i,len;
len = Length+2;
Address = (Address << 5) | 0x8010;
_INT_OFF();
*P_SPI_TXDATA = Address>>8; //Write the address
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
*P_SPI_TXDATA = Address; //Write the data
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
while (Length--)
{
*P_SPI_TXDATA = *DataPtr; //Write the data
while(!(*P_SPI_TXSTS & 0x08000000));
*P_SPI_TXSTS |= 0x80000000; //clear the flag
DataPtr++;
}
for(i=0;i<len;i++)
{
while((*P_SPI_MISC & 0x10)==0x10); //wait for IDLE
temp = *P_SPI_RXDATA; //read dummy data
}
_INT_ON();
}
void spi_dump_fifo(UINT16 Address, UINT8 *DataPtr, UINT8 Length)
{
while(Length--)
{
*DataPtr = spi_lr( Address );
Address++;
DataPtr++;
}
}
void spi_rd_rx_fifo(UINT8 *DataPtr, UINT8 *RxLength)
{
UINT8 Length;
UINT16 Address;
Address = 0x300;
Length = spi_lr(Address);
*RxLength = Length;
Address++;
while(Length--)
{
*DataPtr = spi_lr( Address );
Address++;
DataPtr++;
}
}
void spi_sr_IRQ(UINT8 Address, UINT8 *DataPtr)
{
Address = (Address << 1);
_INT_OFF();
*P_SPI_TXDATA = Address; //Write the address
while(!(*P_SPI_TXSTS & 0x08000000));
*DataPtr = *P_SPI_RXDATA; //read dummy data
*P_SPI_TXDATA = 0; //Write the data (For generating the SCLK)
while((*P_SPI_MISC & 0x04)==0x00);
while((*P_SPI_RXSTS & 0x07)>0)
{
// i=0;
// while(i++<0xff4);
while((*P_SPI_MISC & 0x10)==0x10); //wait for IDLE
*DataPtr = *P_SPI_RXDATA;
}
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -