void sendBeacon(void) { // Initialize packet buffer of size PKTLEN + 1 uint8 txBuffer[PKTLEN+1] = {0}; packetCounterTX = 0; tx_registers(); // Connect ISR function to GPIO2 ioPinIntRegister(&radioRxTxISR); // Interrupt on falling edge ioPinIntTypeSet(IO_PIN_FALLING_EDGE); // Clear ISR flag ioPinIntClear(); // Enable interrupt ioPinIntEnable(); // Calibrate radio according to errata manualCalibration(); //trxSpiCmdStrobe(CC112X_SAFC); automatic frequency compensation //do { while(1){ // Wait for button push //Continiously sent packets until button is pressed do{ // Update packet counter packetCounterTX++; // Create a random packet with PKTLEN + 2 byte packet counter + n x random bytes createPacket(txBuffer); // Write packet to tx fifo cc112xSpiWriteTxFifo(txBuffer,sizeof(txBuffer)); // Strobe TX to send packet trxSpiCmdStrobe(CC112X_STX); // Wait for interrupt that packet has been sent. // (Assumes the GPIO connected to the radioRxTxISR function is set // to GPIOx_CFG = 0x06) while(!packetSemaphore) { uint8 readByte; //Read datarate from registers cc112xSpiReadReg(CC112X_MARCSTATE, &readByte, 1); if(readByte); }; // Clear semaphore flag packetSemaphore = ISR_IDLE; rssi = Read8BitRssi(); write_tx(); }while(!SW_PUSH); } // Put radio to sleep and exit application //trxSpiCmdStrobe(CC112X_SPWD); } uint8 Read8BitRssi(void){ uint8 rssi2compl,rssiValid; uint8 rssiOffset = 102; int8 rssiConverted; //Read RSSI_VALID from RSSI0 cc112xSpiReadReg(CC112X_RSSI0, &rssiValid, 1); // Check if the RSSI_VALID flag is set if(rssiValid & 0x01){ // Read RSSI from MSB register cc112xSpiReadReg(CC112X_RSSI1, &rssi2compl, 1); rssiConverted = (int8)rssi2compl - rssiOffset; return rssiConverted; } // return 0 since new value is not valid return 0; } static void tx_registers(void) { uint8 writeByte; registerConfig(); //RX Gain writeByte = 0x04; cc112xSpiWriteReg(CC112X_CHAN_BW, &writeByte, 1); // RX filter bandwidth 200kHz writeByte = 0x11; cc112xSpiWriteReg(CC112X_AGC_CFG3, &writeByte, 1); //adjust min gain writeByte = 0x20; cc112xSpiWriteReg(CC112X_AGC_CFG2, &writeByte, 1); //0x20-->max gain 0xA0-->previous gain writeByte = 0x19; cc112xSpiWriteReg(CC112X_AGC_REF, &writeByte, 1); //0x19 //TX Power writeByte = 0x7F; cc112xSpiWriteReg(CC112X_PA_CFG2, &writeByte, 1); writeByte = 0x56; cc112xSpiWriteReg(CC112X_PA_CFG1, &writeByte, 1); writeByte = 0x7C; cc112xSpiWriteReg(CC112X_PA_CFG0, &writeByte, 1); // TXOFF_MODE = RX writeByte = 0x38; cc112xSpiWriteReg(CC112X_RFEND_CFG0, &writeByte, 1); // RXOFF_MODE = RX writeByte = 0x3F; cc112xSpiWriteReg(CC112X_RFEND_CFG1, &writeByte, 1); // Max packet length = 2 writeByte = 0x02; cc112xSpiWriteReg(CC112X_PKT_LEN, &writeByte, 1); //auto ack. paketi --> Length + Address of transmitter + Address of receiver }