示例#1
0
文件: bitbang_spi.c 项目: gefa/CC1101
void spiWriteAddr(const unsigned char regAddr)
{
	  unsigned char SPICount;                               // Counter used to clock out the data

	  unsigned char SPIData;                                // Define a data structure for the SPI data.

	  //SPI_CS = 1;                                           // Make sure we start with /CS high
	  SPI_CK(0);                                           // and CK low (idle low)

	  SPIData = regAddr;                                    // Preload the data to be sent with Address
	  //SPI_CS = 0;                                           // Set /CS low to start the SPI cycle 25nS
	                                                        // Although SPIData could be implemented as an "int", resulting in one
	                                                        // loop, the routines run faster when two loops are implemented with
	                                                        // SPIData implemented as two "char"s.

	  for (SPICount = 0; SPICount < 8; SPICount++)          // Prepare to clock out the Address byte
	  {
	    if (SPIData & 0x80)                                 // Check for a 1
	      SPI_MOSI(1);                                     // and set the MOSI line appropriately
	    else
	      SPI_MOSI(0);
	    SPI_CK(1);                                         // Toggle the clock line
	    SPI_CK(0);
	    SPIData <<= 1;                                      // Rotate to get the next bit

	  }
}
示例#2
0
文件: bitbang_spi.c 项目: gefa/CC1101
void spiWriteData(const unsigned char regData)
{
	  unsigned char SPICount;                               // Counter used to clock out the data

	  unsigned char SPIData;                                // Define a data structure for the SPI data.

	  //SPI_CS = 1;                                           // Make sure we start with /CS high
	  SPI_CK(0);                                           // and CK low (idle low)

	  SPIData = regData;                                    // Preload the data to be sent with Data
	  for (SPICount = 0; SPICount < 8; SPICount++)          // Prepare to clock out the Data
	  {
	    if (SPIData & 0x80)
	      SPI_MOSI(1);
	    else
	      SPI_MOSI(0);
	    SPI_CK(1);
	    SPI_CK(0);
	    SPIData <<= 1;
	  }
	  //SPI_CS = 1;
	  SPI_MOSI(0);
}
示例#3
0
文件: bitbang_spi.c 项目: gefa/CC1101
unsigned char spiReadData ()
{

  unsigned char SPICount;                               // Counter used to clock out the data

  unsigned char SPIData;

  //SPI_CS = 1;                                           // Make sure we start with /CS high
  SPI_CK(0);                                           // and CK low

  SPI_MOSI(0);                                         // Reset the MOSI data line

  SPIData = 0;
  for (SPICount = 0; SPICount < 8; SPICount++)          // Prepare to clock in the data to be fread
  {
    SPIData <<=1;                                       // Rotate the data
    SPI_CK(1);                                         // Raise the clock to clock the data out of the MAX7456
    SPIData += SPI_MISO;                                // Read the data bit
    SPI_CK(0);                                         // Drop the clock ready for th enext bit
  }                                                     // and loop back
  //SPI_CS = 1;                                           // Raise CS

  return ((unsigned char)SPIData);                      // Finally return the read data
}
示例#4
0
文件: bitbang_spi.c 项目: gefa/CC1101
unsigned char spiReadReg (const unsigned char regAddr)
{

  unsigned char SPICount;                               // Counter used to clock out the data

  unsigned char SPIData;

  //SPI_CS = 1;                                           // Make sure we start with /CS high
  SPI_CK(0);                                           // and CK low
  SPIData = regAddr;                                    // Preload the data to be sent with Address & Data

  //SPI_CS = 0;                                           // Set /CS low to start the SPI cycle
  for (SPICount = 0; SPICount < 8; SPICount++)          // Prepare to clock out the Address & Data
  {
    if (SPIData & 0x80)
      SPI_MOSI(1);
    else
      SPI_MOSI(0);
    SPI_CK(1);
    SPI_CK(0);
    SPIData <<= 1;
  }                                                     // and loop back to send the next bit
  SPI_MOSI(0);                                         // Reset the MOSI data line

  SPIData = 0;
  for (SPICount = 0; SPICount < 8; SPICount++)          // Prepare to clock in the data to be fread
  {
    SPIData <<=1;                                       // Rotate the data
    SPI_CK(1);                                         // Raise the clock to clock the data out of the MAX7456
    SPIData += SPI_MISO;                                // Read the data bit
    SPI_CK(0);                                         // Drop the clock ready for th enext bit
  }                                                     // and loop back
  //SPI_CS = 1;                                           // Raise CS

  return ((unsigned char)SPIData);                      // Finally return the read data
}
static void spi_write_byte(u8 out)
{
    unsigned char i = 0;
    for (i = 0; i < 8; i++)
    {
        SPI_CK(0);
        SPI_CK(0);
        SPI_CK(0);
        SPI_CK(0);
        SPI_CK(0);
        SPI_CK(0);     //延时用

        if ((out & 0x80) ) SPI_DO(1);
        else			  SPI_DO(0);

        SPI_CK(0);
        //	SPI_CK(0);
        //	SPI_CK(0);
//		SPI_CK(0);
        //SPI_CK(0);     //延时用
        out <<= 1;
        SPI_CK(1);
        SPI_CK(1);//做延时用
        SPI_CK(1);
        SPI_CK(1);
        SPI_CK(1);
        SPI_CK(1);
        SPI_CK(1);

    }


}