コード例 #1
0
ファイル: main.c プロジェクト: tuxx42/mpu6050_cube
//main here
int main(void) {
	uint8_t i = 0;
	char *wheel = "|/-\\";

	//sending buffer addresses
	uint8_t sendpipe = 0;
	uint8_t addrtx0[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP0;

#if defined(TX)
	long *ptr = 0;
	double qw = 1.0f;
	double qx = 0.0f;
	double qy = 0.0f;
	double qz = 0.0f;
	double roll = 0.0f;
	double pitch = 0.0f;
	double yaw = 0.0f;

	//nrf24l01 variables
	uint8_t bufferout[NRF24L01_PAYLOAD];
#elif defined(RX)
	uint8_t bufferin[NRF24L01_PAYLOAD];
#endif

	//init uart
	uart_init(UART_BAUD_SELECT(UART_BAUD_RATE, F_CPU));
	mpu6050_init();
	nrf24l01_init();
	sei();

	uart_puts("\r\nUART initialized... \r\n");
	_delay_ms(50);
	uart_puts("nrf24l01+ initialized... \r\n");

	//init nrf24l01
	_delay_ms(50);
#if defined(TX)
	mpu6050_dmpInitialize();
	mpu6050_dmpEnable();
	_delay_ms(10);
	uart_puts("mpu6050 initialized... \r\n");
#endif

	//init interrupt
	uart_puts("interrupts enabled... \r\n");

	for(i=0; i<100; i++) {
		uart_putc(wheel[i%4]);
		_delay_ms(10);
		uart_putc('\b');
	}
	uart_puts("\r\n");

#if defined(TX)
	uart_puts("starting as tx...\r\n");
#elif defined(RX)
	uart_puts("starting as rx...\r\n");
#endif

	//setup buffer
#if defined(TX)
	for(i=0; i<sizeof(bufferout); i++)
		bufferout[i] = ' ';
#elif defined(RX)
	for(i=0; i<sizeof(bufferin); i++)
		bufferin[i] = 0;
#endif

#if NRF24L01_PRINTENABLE == 1
	nrf24l01_printinfo(uart_puts, uart_putc);
#endif

	//main loop
	nrf24l01_settxaddr(addrtx0);

#if defined(TX)
	for(;;) {
		//tx
		char pipebuffer[5];
		itoa(sendpipe, pipebuffer, 10);

		if(mpu6050_getQuaternionWait(&qw, &qx, &qy, &qz))
			mpu6050_getRollPitchYaw(qw, qx, qy, qz, &roll, &pitch, &yaw);

		_delay_ms(10);

		//quaternion
		ptr = (long *)(&qw);
		for (i=0; i<4; i++)
			*(bufferout+i) = *ptr>>(i*8);

		ptr = (long *)(&qx);
		for (i=0; i<4; i++)
			*(bufferout+i+4) = *ptr>>(i*8);

		ptr = (long *)(&qy);
		for (i=0; i<4; i++)
			*(bufferout+i+8) = *ptr>>(i*8);

		ptr = (long *)(&qz);
		for (i=0; i<4; i++)
			*(bufferout+i+12) = *ptr>>(i*8);

		// roll pitch yaw
		ptr = (long *)(&roll);
		for (i=0; i<4; i++)
			*(bufferout+i+16) = *ptr>>(i*8);

		ptr = (long *)(&pitch);
		for (i=0; i<4; i++)
			*(bufferout+i+20) = *ptr>>(i*8);

		ptr = (long *)(&yaw);
		for (i=0; i<4; i++)
			*(bufferout+i+24) = *ptr>>(i*8);

		nrf24l01_write(bufferout);
	}
#elif defined(RX)
	for(;;) {
		//rx
		uint8_t pipe = 0;
		if(nrf24l01_readready(&pipe)) { //if data is ready
			//read buffer
			nrf24l01_read(bufferin);

			for (i=0; i < 4*7; i++)
				uart_putc(*(bufferin+i));
			uart_putc('\n');
		}
		_delay_ms(10);
	}
#endif
}
コード例 #2
0
ファイル: NRFL01 RX.c プロジェクト: arnabdasbwn/NRF24L01
//main here
int main(void) {
	uint8_t txrxrole = 0; // 1 transmitter 0 receiver
	uint8_t i = 0;

	//nrf24l01 variables
	uint8_t bufferout[NRF24L01_PAYLOAD];
	uint8_t bufferin[NRF24L01_PAYLOAD];

	#if DEBUGENABLED == 1
	//init uart
	USART_Init(103);
	#endif
	//LCD init
	lcd_init();
	lcd_gotoxy1(0);
	
	//init nrf24l01
	nrf24l01_init();

	//init interrupt
	sei();

	txrxrole = ROLERX;         /////////////////////////////////////////////////

	#if DEBUGENABLED == 1
	if(txrxrole == ROLETX)
	uart_putc('T');
	else if(txrxrole == ROLERX)
	uart_putc('R');
	#endif

	//setup buffer
	for(i=0; i<sizeof(bufferout); i++)
	bufferout[i] = i+'a';
	for(i=0; i<sizeof(bufferin); i++)
	bufferin[i] = 0;

	//sending buffer addresses
	uint8_t sendpipe = 0;
	uint8_t addrtx0[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP0;
	uint8_t addrtx1[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP1;
	uint8_t addrtx2[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP2;
	uint8_t addrtx3[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP3;
	uint8_t addrtx4[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP4;
	uint8_t addrtx5[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP5;

	#if DEBUGENABLED == 1 && NRF24L01_PRINTENABLE == 1
	nrf24l01_printinfo(uart_puts, uart_putc);
	#endif

	//main loop
	for(;;)
	{
		if(txrxrole == ROLETX)
		{//Tx
			#if DEBUGENABLED == 1
			char pipebuffer[5];
			uart_puts("sending data, on pipe ");
			itoa(sendpipe, pipebuffer, 10);
			uart_puts(pipebuffer);
			uart_puts("... ");
			#endif

				if(sendpipe == 0){
				//set tx address for pipe 0
				nrf24l01_settxaddr(addrtx0);
				} else if(sendpipe == 1) {
				//set tx address for pipe 1
				nrf24l01_settxaddr(addrtx1);
				} else if(sendpipe == 2) {
				//set tx address for pipe 2
				nrf24l01_settxaddr(addrtx2);
				} else if(sendpipe == 3) {
				//set tx address for pipe 3
				nrf24l01_settxaddr(addrtx3);
				} else if(sendpipe == 4) {
				//set tx address for pipe 4
				nrf24l01_settxaddr(addrtx4);
				} else if(sendpipe == 5) {
				//set tx address for pipe 5
				nrf24l01_settxaddr(addrtx5);
			}

			//write buffer
			uint8_t writeret = nrf24l01_write(bufferout);

			#if DEBUGENABLED == 1
			if(writeret == 1)
			uart_puts("ok\r\n");
			else
			uart_puts("failed\r\n");
			#endif

			sendpipe++;
			sendpipe%=6;
			
			#if DEBUGENABLED == 0
		}
		#endif
		#if DEBUGENABLED == 1
		_delay_ms(1000);
		#endif
	}
	
	else if(txrxrole == ROLERX)