//main routine int main(void) { unsigned char data; //register to hold letter received and sent Initialize(); //initialize PLL, IO, SPI, set up nRF24L01 as RX //main program loop while(1) { //wait until a packet has been received while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active())); nrf24l01_read_rx_payload(&data, 1); //read the packet into data nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01 PORTC = data; // DelayUS(130); //wait for the other 24L01 to come from standby to RX _delay_us(35); _delay_us(35); _delay_us(35); _delay_us(25); nrf24l01_set_as_tx(); //change the device to a TX to send back from the other 24L01 nrf24l01_write_tx_payload(&data, 1, true); //transmit received char over RF //wait until the packet has been sent while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_tx_ds_active())); nrf24l01_irq_clear_all(); //clear interrupts again nrf24l01_set_as_rx(true); //resume normal operation as an RX // ToggleLED(); //toggle the on-board LED as visual indication that the loop has completed } }
/******** Transceiver_SendMessage ******************************************* // unpack transceiver packet and send out // Input: // pkt - transceiver packet to be sent // Output: status // ------------------------------------------------------------------------*/ unsigned char Transceiver_SendMessage ( TransceiverPacket pkt ) { unsigned char tx[TRANSCEIVER_MAX_PAYLOAD]; unsigned char index, length; unsigned char status = SUCCESS; // validate packet Debug_NetworkTransceiver_PrintPacket(&pkt); if ( MAX_DATA_SIZE < pkt.dataSize ) { status = ERROR_INVALID_PAKCET; Debug_Printf ("Transceiver_SendMessage: Error 0x%x\n", status); goto exit; } // unpack transceiver packet tx[SOURCE_ID_INDEX] = pkt.srcID; tx[DEST_ID_INDEX] = pkt.destID; tx[MSG_ID_INDEX] = pkt.msgID; tx[DATA_SIZE_INDEX] = pkt.dataSize; length = DATA_INDEX; for ( index = 0; index < pkt.dataSize; index++,length++ ) { tx[length] = pkt.data[index]; } Debug_NetworkTransceiver_PrintPayload(tx); // lock transceiver while ( xSemaphoreTake(Transceiver_Mutex, portMAX_DELAY) != pdTRUE ); GPIOPinIntDisable ( nrf24l01_IRQ_IOREGISTER, nrf24l01_IRQ_PIN ); nrf24l01_set_as_tx(); nrf24l01_write_tx_payload ( tx, TRANSCEIVER_MAX_PAYLOAD, true ); //wait until the packet has been sent or the maximum number of retries has been active while( !( nrf24l01_irq_pin_active() && (nrf24l01_irq_tx_ds_active()||nrf24l01_irq_max_rt_active()) ) ); if ( nrf24l01_irq_max_rt_active() ) { // hit maximum number of retries nrf24l01_flush_tx(); status = ERROR_MAX_RETRIES; Debug_Printf ("Transceiver_SendMessage: Error 0x%x\n", status); } // reset transceiver nrf24l01_irq_clear_all(); nrf24l01_set_as_rx(true); Delay_US(130); //unlock transceiver GPIOPinIntEnable ( nrf24l01_IRQ_IOREGISTER, nrf24l01_IRQ_PIN ); while ( xSemaphoreGive(Transceiver_Mutex) != pdTRUE ); exit: return status; }
void main(void) { unsigned int channel = CHANNEL; unsigned char data = 0x07; // DBGU output configuration TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); // Configuration PIT (Periodic Interrupt Timer) ConfigurePit(); // Configuration TC (Timer Counter) ConfigureTc(); // Configuration PIO (Paralell In and Out port), Init Interrupt on PIO ConfigureButtons(); ConfigureLeds(); // Configuration Radio Module nRF24L (PIO and SPI), ConfigureButtons must be executed before ConfigureNRF24L(); ConfigureUSART0(); ConfigureUSART1(); //initialize proximity sensor ir_init(); Global_Variable_Init(); while(Timer0Tick<2); // wait until NRF24L01 power up nrf24l01_power_up(True); while(Timer0Tick<4); // wait until NRF24L01 stand by Timer0Tick = 0; //initialize the 24L01 to the debug configuration as RX and auto-ack disabled nrf24l01_initialize_debug(True, nrf_TX_RX_SIZE, False); nrf24l01_write_register(0x06, &data, 1); nrf24l01_set_as_rx(True); Delay_US(130); nrf24l01_set_rf_ch(channel); nrf24l01_flush_rx(); Delay_US(300); while (1) { if(Timer0Tick!=0){ Timer0Tick = 0; Check_Battery(0); odometry(0); ProxRead_m(); Send_Coord(); Delay_US(10000);//give time for the coming message feedbackController(goalx, goaly, goaldist); } Check_Wireless(); }//while }//main
//main routine int main() { unsigned char data; //register to hold letter sent and received unsigned int count; //counter for for loop Initialize(); //initialize PLL, IO, UART, SPI, set up nRF24L01 as TX stdout = &my_stream; stdin = &my_stream; printf_P(PSTR(" type character to send \n")); //main program loop while(1) { //check UART status register to see if data has been received. if so, process while(usart0_rx_data_ready()) { // data = usart0_get_rx_data(); //get data from UART data = getchar(); //get data from UART PORTC = data; nrf24l01_write_tx_payload(&data, 1, true); //transmit received char over RF //wait until the packet has been sent or the maximum number of retries has been active while(!(nrf24l01_irq_pin_active() && (nrf24l01_irq_tx_ds_active() || nrf24l01_irq_max_rt_active()))); //check to see if the maximum number of retries has been hit. if not, wait for the RX device // to send the char back. if so, assume the packet is lost and send "*" back to UART if(!nrf24l01_irq_max_rt_active()) { nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01 nrf24l01_set_as_rx(true); //change the device to an RX to get the character back from the other 24L01 //wait a while to see if we get the data back (change the loop maximum and the lower if // argument (should be loop maximum - 1) to lengthen or shorten this time frame for(count = 0; count < 25000; count++) { //check to see if the data has been received. if so, get the data and exit the loop. // if the loop is at its last count, assume the packet has been lost and set the data // to go to the UART to "?". If neither of these is true, keep looping. if((nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active())) { nrf24l01_read_rx_payload(&data, 1); //get the payload into data break; } //if loop is on its last iteration, assume packet has been lost. if(count == 24999) data = '?'; } nrf24l01_irq_clear_all(); //clear interrupts again printf("%c", data); //print the received data (or ? if none) to the screen // DelayUS(130); //wait for receiver to come from standby to RX _delay_us(35); _delay_us(35); _delay_us(35); _delay_us(25); nrf24l01_set_as_tx(); //resume normal operation as a TX } else { nrf24l01_flush_tx(); //get the unsent character out of the TX FIFO nrf24l01_irq_clear_all(); //clear all interrupts printf("*"); //print "*" to the screen to show that the receiver did not receive the packet } // ToggleLED(); //toggle the on-board LED as visual indication that the loop has completed } } }
void main(void) { unsigned int channel = CHANNEL; unsigned char data = 0x07; unsigned char t1; unsigned char t2; unsigned int tmpcount = 0; unsigned char wl_data[10]; unsigned char rs_line[20]; unsigned char rs_data[10]; unsigned char tmp_data[50]; // DBGU output configuration TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); // Configuration PIT (Periodic Interrupt Timer) ConfigurePit(); // Configuration TC (Timer Counter) ConfigureTc(); // Configuration PIO (Paralell In and Out port), Init Interrupt on PIO ConfigureButtons(); ConfigureLeds(); // Configuration Radio Module nRF24L (PIO and SPI), ConfigureButtons must be executed before ConfigureNRF24L(); ConfigureUSART0(); ConfigureUSART1(); while(Timer1Tick<2); // wait until NRF24L01 power up nrf24l01_power_up(True); while(Timer1Tick<4); // wait until NRF24L01 stand by Timer1Tick = 0; //initialize the 24L01 to the debug configuration as RX and auto-ack disabled nrf24l01_initialize_debug(True, nrf_TX_RX_SIZE, False); nrf24l01_write_register(0x06, &data, 1); nrf24l01_set_as_rx(True); Delay_US(130); nrf24l01_set_rf_ch(channel); nrf24l01_flush_rx(); Delay_US(300); reset_wl = 1; while (1) { if( nrf_Data > 0 ) { nrf_Data = 0; for( t1 = 0; t1<8; t1++ ) { wl_data[t1] = nrfRxMessage.Data[t1]; } LED_Toggle(LED_Green); writeByteSequence_8(wl_data); } if(messageUSART1){ messageUSART1 = 0; pmsgRead(tmp_data); while (tmp_data[tmpcount]!='\n'){ t1 = tmp_data[tmpcount]; tmpcount++; if( t1 >= '0' && t1 <= '9' ) { // If character is 0-9 convert it to num if( count < 20) { rs_line[count] = t1-'0'; count++; } } if( t1 >= 'A' && t1 <= 'F' ) { // If character A-F convert to 10-15 if( count < 20) { rs_line[count] = t1-'A'+10; count++; } } } // If character is a line break send packet for( count = 0; count <10; count++ ) { // Convert from 16*4 to 8*8 t1 = (rs_line[count*2])<<4; t2 = rs_line[count*2+1]; rs_data[count] = t1 | t2; } count = 0; tmpcount = 0; if( nrf_Transmission_Done == 1 ) { TX_packet_BASE(rs_data); // Send packet. LED_Toggle(LED_Yellow); } }//if msg flag has been raised }//while }//main