static void send_colors(struct color *colors, int count)
{
	int i, k;

	/* Initialize SPI pins. */
	SCLK(0);
	MOSI(0);

	/* Start frame */
	for (i = 0; i < 32; i++) {
		SCLK(1);
		SMALL_DELAY();
		SCLK(0);
		SMALL_DELAY();
	}

	/* Color cell output */
	for (k = 0; k < count; k++) {
		/* Start bit */
		MOSI(1);
		SCLK(1);
		SMALL_DELAY();
		SCLK(0);
		SMALL_DELAY();

		/* Blue */
		for (i = 0; i < 5; i++) {
			MOSI(((colors[k].b & ((1 << 4) >> i)) != 0));
			SCLK(1);
			SMALL_DELAY();
			SCLK(0);
			SMALL_DELAY();
		}
		/* Red */
		for (i = 0; i < 5; i++) {
			MOSI(((colors[k].r & ((1 << 4) >> i)) != 0));
			SCLK(1);
			SMALL_DELAY();
			SCLK(0);
			SMALL_DELAY();
		}
		/* Green */
		for (i = 0; i < 5; i++) {
			MOSI(((colors[k].g & ((1 << 4) >> i)) != 0));
			SCLK(1);
			SMALL_DELAY();
			SCLK(0);
			SMALL_DELAY();
		}
	}

	/* End frame */
	MOSI(0);
	for (k = 0; k < count; k++) {
		SCLK(1);
		SMALL_DELAY();
		SCLK(0);
		SMALL_DELAY();
	}
}
Beispiel #2
0
unsigned char write_spi(unsigned char data)
{
	
	unsigned char i; 
	unsigned char Temp=0x00;
	unsigned char SDI; 
	for (i = 0; i < 8; i++)
	{
		CLK(1);
		ms_delay();
		if (data&0x80)      
		{
			MOSI(1);
		}
		else
		{
			MOSI(0);
		}
		data <<= 1;  
		CLK(0);
		ms_delay();
		ms_delay();
		SDI = MISO();
		Temp<<=1;

		if(SDI)
		{
			Temp++;
		}
		CLK(1);
	}
	
	return Temp; 
}
Beispiel #3
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);
}  
Beispiel #4
0
/**************************************************
Function: SPI_RW();

Description:
	Writes one UINT8 to RFM73, and return the UINT8 read
// **************************************************/
UINT8 SPI_RW(UINT8 inputValue)
{
	UINT8 curBit;
	UINT8 outputValue = 0x00;
	//int i;
	for(curBit = 0; curBit < 8; curBit++)   // output 8-bit
	{
		MOSI(inputValue & 0x80);

		inputValue *= 2;           // shift next bit into MSB..

		SCK(1);

		outputValue *= 2;
		outputValue += MISO;

		//LED(MISO);

		SCK(0);            		  // ..then set SCK low again
	}
	return(outputValue);           		  // return read UINT8
}