/*************************************************************************************************** * Main section * ***************************************************************************************************/ void main(void) { error = 0; uint8 cntr; // Initialize system speed, communication interfaces and RF radio module exit_code = System_Init(); Print_Error(exit_code); while (1) { payload_length = 0; // Construct the packet TxPacket[payload_length++] = 0x01; TxPacket[payload_length++] = 0x02; TxPacket[payload_length++] = 0x03; // Send data over radio exit_code = Radio_Tx(TxPacket, payload_length, ADDR_REMOTE); // Print out packet that was sent UART_Send_Data("\r\nSending:"); for (cntr = 0; cntr < payload_length; cntr++) { UART0_Send_ByteToChar(&TxPacket[cntr]); } // Add some delay (around 1sec) __delay_cycles(5000000*SYSTEM_SPEED_MHZ); } } /* END: main */
// ************************************************************************************************* // @fn Print_Error // @brief Print code that is set when function exits. If error code is 0 then nothin is prnted // out and packet is received or sent correctly // @param uint8 error_code Error code number that is set by the function // @return none // ************************************************************************************************* void Print_Error(uint8 error_code) { // Print out error code only if it is not 0 if (error_code) { UART_Send_Data("\r\nError code: "); UART0_Send_ByteToChar(&error_code); error_code = 0; } // If packet size has wrong length then reset radio module if (error_code == ERR_RX_WRONG_LENGTH) { Radio_Init(RF_DATA_RATE, TX_POWER, RF_CHANNEL); } exit_code = 0; }
/*************************************************************************************************** * Main section * ***************************************************************************************************/ void main(void) { // Initialize system Print_Error(System_Init()); WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer /* Start : CPU clock configuration */ if (CALBC1_1MHZ==0xFF) // If calibration constant erased { while(1); // do not load, trap CPU } DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; /* End : CPU clock configuration */ /* Start : data pin configuration */ P1IE |= DATA_PIN; // DATA_PIN interrupt enabled // P1IES |= DATA_PIN; // DATA_PIN HI to LOW edge P1IFG &= ~DATA_PIN; // DATA_PIN IFG cleared /* End : data pin configuration */ /* Start : Timer interrupt configuration */ TACCTL0 = CCIE; // TACCR0 interrupt enabled TACCR0 = 32768; // Interrupt every one second ( TACTL = TASSEL_1 + ID_0 + MC_1; // Set the timer A to ACLK, divide clock cycle by 1, Up mode /* End : Timer interrupt configuration */ __enable_interrupt(); // Enabling interrupt __bis_SR_register(LPM0 + GIE); // LPM0 with interrupts enabled while (1) { payload_length = 0; // Clear Tx packet buffer cntr = 0; for (cntr=RF_BUFFER_SIZE; cntr > 0; cntr--) TxPacket[cntr] = 0; // Construct the packet // This is the place where you can put your own data to send TxPacket[payload_length++] = PKT_CTRL | PKT_CTRL_REQUEST; TxPacket[payload_length++] = PKT_TYPE_VOLTAGE; TxPacket[payload_length++] = 255; TxPacket[payload_length++] = 90; // Print out all data that we are goind to send // Payload length includes Control packet and does not take into account // packet encryption nor source, destination adress bytes. Only actual payload that // you have defined above UART_Send_Data("\r\nPayload length:\t"); UART0_Send_ByteToChar(&payload_length); UART_Send_Data("\r\nDestination address: "); UART0_Send_ByteToChar(&addr_remote); UART_Send_Data("\r\nMessage: "); for (cntr = 1; cntr < payload_length; cntr++) { UART0_Send_ByteToChar(&TxPacket[cntr]); } /* NWK level data sending */ Print_Error(Radio_Send_Data(TxPacket, payload_length, addr_remote, PAYLOAD_ENC_ON, PCKT_ACK_ON)); //UART_Send_Data("\r\nERR: "); //UART0_Send_ByteToChar((uint8 *)exit_code); exit_code = 0; UART_Send_Data("\r\n"); // Insert new line to separate packets // Add some delay (around 2sec) __delay_cycles(5000000*SYSTEM_SPEED_MHZ); } } /* END: main */