Ejemplo n.º 1
0
/*********************************************************************
* Function    : EF_BOOLEAN_nRF_GetData
*
* DESCRIPTION : receive data by the nRF module
*
* PARAMETERS  : U8_t* Data: pointer to received data
* 			    U8_t DataLength: no of bytes of received data
*
* Return Value:  BOOLEAN to check for Errors
**********************************************************************/
BOOLEAN EF_BOOLEAN_nRF_GetData(U8_t* Data , U8_t DataLength)
{
	U8_t Status = 0;
	/* check for length */
	if (DataLength > PAYLOAD_WIDTH_BYTES)
	{
		return FALSE;
	}

	/* wait until RX flag = 1 */
	do
	{
		LOW_CSN;
		/* send No operation command to receive Status register (SPI Mythology )*/
		Status = EF_SpiTransfer (NOP_CMD);
		HIGH_CSN;

	}while((Status & 1<<RX_DR) == 0);

	/* send read command then get data */
	LOW_CSN;
	EF_SpiTransfer (R_RX_PAYLOAD_CMD);
	EF_void_SPI_TransferArray(temp_Buffer, Data , DataLength);
	HIGH_CSN;

#if (GET_WIDTH_IF_DYNAMIC == 1)
	if (STATIC_PW == 0)
	{
		/* Dynamic , to print the data width*/
		LOW_CSN;
		Status = EF_SpiTransfer(R_RX_PL_WID);
		EF_void_SPI_TransferArray(temp_Buffer, temp_Buffer , 1);
		EF_void_UART_HextoASCII(&temp_Buffer[0]);
		HIGH_CSN;

	}
#endif

	/* remove the data from RX Buffer to help receiving data again */
	LOW_CSN;
	EF_SpiTransfer (FLUSH_RX_CMD);
	HIGH_CSN;

	/* make RX flag = 0 to help receiving data again */
	nRF_writeRegister (STATUS_REGISTER, (1<<RX_DR));

	return Status;
}
Ejemplo n.º 2
0
int main()
{
	DDRD |= (1<<7)|(1<<6);
	PORTD |= 1<<7;
	_delay_ms(1000);


	EF_void_UART_Init(&Uart_Paramters);
	EF_void_UART_SendArray((U8_t*)"eee",3);

//	EF_void_SPI_Init(SLAVE_TYPE);
//
//
//	while (1)
//	{
//		EF_u8_SPI_TransferByte(0xEF);
//	}
	EF_void_nRF_init();
	EF_BOOLEAN_nRF_RXSetup();

//	_delay_ms(1);

	while(1)
	{
//		EF_BOOLEAN_nRF_RXSetup();
//		_delay_ms(1);

		for (iterator = 0 ; iterator <3 ; iterator++)
		{
			EF_BOOLEAN_nRF_GetData(&(RX_Buffer[iterator][0]), 32 );
			PORTD ^= 1<<7;
		}

		CRC_Rx = 1;
		for (iterator = 0 ; iterator <3 ; iterator++)
		{
			for (counter = 0 ; counter <31 ; counter++)
			{
				CRC_Rx = (CRC_Rx) ^ (RX_Buffer[iterator][counter]) ^
						  	  	    (RX_Buffer[iterator][counter+1]);
			}
		}
//		EF_BOOLEAN_nRF_GetData ((U8_t*)data_arr , 3);
//		EF_void_UART_SendArray ((U8_t*)data_arr , 3);
//		data_test = EF_u8_nRF_ReadRegister (0x17);
		EF_void_UART_HextoASCII (&CRC_Rx);
		EF_void_UART_PutChar(' ');
//		data_test = EF_u8_nRF_ReadRegister (0x7);
//		EF_void_UART_HextoASCII (&data_test);
//		EF_void_UART_PutChar('-');
//		_delay_ms(100);
//		PORTD ^= 1<<7;
//
//		PORTB &= ~(1<<3);
//		_delay_ms(1);
	}



	return 0;
}