static void power_off (void) { MCI_MASK0 = 0; MCI_COMMAND = 0; MCI_DATA_CTRL = 0; MCI_CLOCK = 0; /* Power-off */ MCI_POWER = 0; LEDR_OFF(); Stat |= STA_NOINIT; /* Set STA_NOINIT */ }
int main(void) { uint8_t i; uint8_t ChkSum; cli(); //#asm("cli"); DDRB = 0x00; //PB INPUT; DDRD = 0x00; //PD INPUT; //POWER ON indication: both LEDR and LEDG blink 3 times LEDG_OFF(); LEDR_OFF(); LEDG_OUTPUT(); LEDR_OUTPUT(); for (i=0; i<3; i++) { _delay_ms(200); //Delay_ms(200); LEDG_ON(); LEDR_ON(); _delay_ms(200); //Delay_ms(200); LEDG_OFF(); LEDR_OFF(); } LEDG_OFF(); LEDR_OFF(); RFXX_PORT_INIT(); RF12_INIT(); DDRD |= (1 << RF12_DATA); PORTD |= (1 << RF12_DATA); // SET nFFS pin HI when using TX register DDRD &= ~(1 << DDD2); // PD2(INT0) while (1) { LEDR_ON(); rfxx_wrt_cmd(0x0000); //read status register rfxx_wrt_cmd(0x8239); //!er,!ebb,ET,ES,EX,!eb,!ew,DC ChkSum=0; rf12_send(0xAA); //PREAMBLE rf12_send(0xAA); //PREAMBLE rf12_send(0xAA); //PREAMBLE rf12_send(0x2D); //SYNC HI BYTE rf12_send(0xD4); //SYNC LOW BYTE // send data bytes for (i = 0x30; i<=0x3F; ++i) { rf12_send(i); ChkSum += i; } /* rf12_send(0x30); //DATA BYTE 0 ChkSum+=0x30; rf12_send(0x31); //DATA BYTE 1 ChkSum+=0x31; rf12_send(0x32); ChkSum+=0x32; rf12_send(0x33); ChkSum+=0x33; rf12_send(0x34); ChkSum+=0x34; rf12_send(0x35); ChkSum+=0x35; rf12_send(0x36); ChkSum+=0x36; rf12_send(0x37); ChkSum+=0x37; rf12_send(0x38); ChkSum+=0x38; rf12_send(0x39); ChkSum+=0x39; rf12_send(0x3A); ChkSum+=0x3A; rf12_send(0x3B); ChkSum+=0x3B; rf12_send(0x3C); ChkSum+=0x3C; rf12_send(0x3D); ChkSum+=0x3D; rf12_send(0x3E); ChkSum+=0x3E; rf12_send(0x3F); //DATA BYTE 15 ChkSum+=0x3F; */ rf12_send(ChkSum); //send chek sum rf12_send(0xAA); //DUMMY BYTE rf12_send(0xAA); //DUMMY BYTE rf12_send(0xAA); //DUMMY BYTE rfxx_wrt_cmd(0x8201); LEDR_OFF(); LEDG_OFF(); //for(i=0;i<10000;i++) // for(j=0;j<123;j++); //sleep 1 second appr. _delay_ms(1000); } }
void CC1101_ISR(void) { switch((RF1AIV)) // Prioritizing Radio Core Interrupt { case 0: break; // No RF core interrupt pending case 2: break; // RFIFG0 case 4: break; // RFIFG1 case 6: break; // RFIFG2 case 8: break; // RFIFG3 case 10: break; // RFIFG4 case 12: break; // RFIFG5 case 14: break; // RFIFG6 case 16: break; // RFIFG7 case 18: break; // RFIFG8 case 20: // RFIFG9 if(receiving) // RX end of packet { transmit = 1; receive = 0; // Read the length byte from the FIFO RxBufferLength = ReadSingleReg( RXBYTES ); ReadBurstReg(RF_RXFIFORD, RxBuffer, RxBufferLength); // Stop here to see contents of RxBuffer __no_operation(); rssi=radio_rssi(); //print the raw buffer without CRC check - raja code //uart_write( RxBuffer, RxBufferLength ); // Check the CRC results if(RxBuffer[CRC_LQI_IDX] & CRC_OK) { LED_OUT |= (1<<LED_GBIT); // Toggle LED1 //print the CRC checked buffer and say CRC check ok -- raja code // printf("Hello, welcome to serial port example\n"); printf("REceived RSSSI is .. %i dBm \r", rssi); //printf("\n"); //uart_write( RxBuffer, RxBufferLength ); delayms(10); LED_OUT &=~(1<<LED_GBIT); } } else if(transmitting) // TX end of packet { RF1AIE &= ~BIT9; // Disable TX end-of-packet interrupt LEDR_OFF(); // Turn off LED after Transmit printf("trasmitting \n"); transmitting = 0; transmit = 0; receive = 1; } else while(1); // trap break; case 22: break; // RFIFG10 case 24: break; // RFIFG11 case 26: break; // RFIFG12 case 28: break; // RFIFG13 case 30: break; // RFIFG14 case 32: break; // RFIFG15 } __bic_SR_register_on_exit(LPM3_bits); }