Пример #1
0
void SPIstartCommunication(void)
{
	if(clk800msSPI == COMPLETE) {
	SPI_ReadData(0x08);
	SPI_ReadData(0x08);
	clk800msSPI = RESTART;
	}
}
Пример #2
0
int spi_slave_read(spi_t *obj)
{
    uint32_t rx_data;

    while (!spi_readable(obj));
    rx_data = SPI_ReadData(spi_address[obj->instance]);
    return rx_data & 0xffff;
}
Пример #3
0
int spi_master_write(spi_t *obj, int value)
{
    uint32_t rx_data;

    SPI_WriteData(spi_address[obj->instance], (uint16_t)value, kSPI_FrameAssert);
    // wait rx buffer full
    while (!spi_readable(obj));
    rx_data = SPI_ReadData(spi_address[obj->instance]);
    return rx_data & 0xffff;
}
Пример #4
0
int main ()
{
	/* Configure port D pin 0 as output
	 * for signaling when tests pass
	 */
	DDR_SIGNAL = (1<<DD_SIGNAL);
	uint8_t i, byte_received;
	SPI_MasterInit();
	for (i=0; i<100; i++)
	{
		SPI_MasterTransmit(0x81);
		_delay_ms(5);
	
		/* is SPI interrupt flag set? */
		if (SPSR == 0x80)
		{
			/* if SPI interrupt flag is set
			 * clear it by reading the data
			 * in SPI data register */
			byte_received = SPI_ReadData();
			set_bit(SIGNAL_PORT, SIGNAL);
			//_delay_ms(25);
			/* did clearing interrupt
			 * flag succeed? */	
			if (SPSR == 0x00)
			{
				/* if yes blink LED */
				clear_bit(SIGNAL_PORT, SIGNAL);
				//_delay_ms(25);
			}
		}
		/* if flag is not set blink slowly
		 * forever */
		else
		{
			while (1)
			{
				set_bit(SIGNAL_PORT, SIGNAL);
				_delay_ms(500);
				clear_bit(SIGNAL_PORT, SIGNAL);
				_delay_ms(500);
			}
		}
	}
	/* if all is well, after completing
	 * the requested transmissions
	 * the LED should go off and the 
	 * processeor should do nothing
	 * happily ever after */
	while (1);
		;	
	return (0);

}
Пример #5
0
static void SPI_Read( uint32_t* data)
{
	uint32_t lcm_id=0;

	SPI_SetDatawidth(8);

	//Read data 16bits
	lcm_id = SPI_ReadData(1, 0);  //unit of buswidth
	{
		uint32_t i=0;
		for(i=0; i<1000; i++);
	}
	SPI_SetCsLow(0, FALSE);

	*data = lcm_id;
}