Exemplo n.º 1
0
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

	  }
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
void CPU_SPI_GetPins(UINT32 spi_mod, GPIO_PIN& msk, GPIO_PIN& miso, GPIO_PIN& mosi)
{
    if (spi_mod >= TOTAL_SPI_PORT)
    {
        msk  = GPIO_PIN_NONE;
        miso = GPIO_PIN_NONE;
        mosi = GPIO_PIN_NONE;
    } else {
        msk  = SPI_MSK(spi_mod);
        miso = SPI_MISO(spi_mod);
        mosi = SPI_MOSI(spi_mod);
    }

    return;
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
void spi_write_byte(unsigned char b)  
{  
    int i;  
    for (i=7; i>=0; i--) 
	{  
		//set_gpio_value(SCLK, 0);
		SPI_CLK(0);  
		//set_gpio_value(MOSI, b&(1<<i));          
		SPI_MOSI(b&(1<<i));
		delay_us(10);                              
		//set_gpio_value(SCLK, 1);                // CPHA=1  
		SPI_CLK(1);
		delay_us(10);      
    }  
	SPI_CLK(0);  
}  
Exemplo n.º 6
0
void spi_init()  
{  
	DRDY();
	SS();
	SCLK();
	MOSI();
	MOSO();
	SPI_CLK(0);
	SPI_MOSI(0);
    //set_gpio_direction(SS, OUTP);  
    //set_gpio_direction(SCLK, OUTP);  
    //set_gpio_direction(MOSI, OUTP);  
    //set_gpio_direction(MISO, INP);  
    //set_gpio_value(SCLK, 0);                    //CPOL=0 
    //set_gpio_value(MOSI, 0);
}  
Exemplo n.º 7
0
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
}