/* Example for transmitting frames */ /*****************************************/ //thermo #include #include #include #include #include // send #include "board.h" #include "transceiver.h" #include "ioutil.h" #include "xmpl.h" //thermo #define DD_MISO 3 #define DD_MOSI 2 #define DD_SCK 1 #define DD_SS 0 //send static volatile bool tx_in_progress; static volatile uint8_t tx_cnt; static volatile uint8_t irgendwas; static volatile uint8_t len; //thermo function void SPI_MasterInit(void) { //Outputs: MOSI, SCK, SS DDRB = (1<>5) & 0b00000000111111111111111111111111; //die letzten 5 Bit löschen //bei interner Temperaturmessung: Temperatur in °C berechnen laut Datenblatt Seite21 Temp = (masterIn*4/1570)-273; _delay_ms(2000); } //end thermo trx_regval_t rval; irgendwas=Temp; uint8_t txfrm[] = {irgendwas,0, /* faked ieee 802.15.4 data frame control field * this is just needed, that a sniffer has to display something.*/ 42, /* sequence counter, updated by software */ 'h','e','l','l','o',' ','µ','r','a','c','o','l','i','!', /* data */ 'X','X' /* these bytes are overwritten from transceivers CRC generator just before sent. */ }; /* This will stop the application before initializing the radio transceiver * (ISP issue with MISO pin, see FAQ) */ // trap_if_key_pressed(); /* Step 0: init MCU peripherals */ LED_INIT(); trx_io_init(SPI_RATE_1_2); LED_SET_VALUE(LED_MAX_VALUE); LED_SET_VALUE(0); /* Step 1: initialize the transceiver */ DELAY_US(TRX_INIT_TIME_US); TRX_RESET_LOW(); TRX_SLPTR_LOW(); DELAY_US(TRX_RESET_TIME_US); TRX_RESET_HIGH(); trx_reg_write(RG_TRX_STATE,CMD_TRX_OFF); DELAY_US(TRX_INIT_TIME_US); rval = trx_bit_read(SR_TRX_STATUS); ERR_CHECK_DIAG(TRX_OFF!=rval,1); LED_SET_VALUE(1); /* Step 2: setup transmitter * - configure radio channel * - enable transmitters automatic crc16 generation * - go into TX state, * - enable "transmit end" IRQ */ trx_bit_write(SR_CHANNEL,CHANNEL); trx_bit_write(SR_TX_AUTO_CRC_ON,1); trx_reg_write(RG_TRX_STATE,CMD_PLL_ON); #if defined(TRX_IRQ_TRX_END) trx_reg_write(RG_IRQ_MASK,TRX_IRQ_TRX_END); #elif defined(TRX_IRQ_TX_END) trx_reg_write(RG_IRQ_MASK,TRX_IRQ_TX_END); #else # error "Unknown IRQ bits" #endif sei(); LED_SET_VALUE(2); /* Step 3: send a frame each 500ms */ tx_cnt = 0; tx_in_progress = false; LED_SET_VALUE(0); while(1) { WAIT500MS(); if (tx_in_progress == false) { txfrm[2] = tx_cnt; trx_frame_write (len + 3 + 2, txfrm); tx_in_progress = true; TRX_SLPTR_HIGH(); TRX_SLPTR_LOW(); LED_SET(1); LED_TOGGLE(0); } } } #if defined(TRX_IF_RFA1) ISR(TRX24_TX_END_vect) { /* transmission completed */ tx_in_progress = false; tx_cnt ++; LED_CLR(1); } #else /* !RFA1 */ ISR(TRX_IRQ_vect) { static volatile trx_regval_t irq_cause; irq_cause = trx_reg_read(RG_IRQ_STATUS); if (irq_cause & TRX_IRQ_TRX_END) { /* transmission completed */ tx_in_progress = false; tx_cnt ++; LED_CLR(1); } } #endif /* EOF */