Beispiel #1
0
/**
 * The main function.
 */
int main( void )
{
	/* Stop the watchdog timer. */
	WDTCTL = WDTPW + WDTHOLD;
	
	/* Setup MCLK 8MHz and SMCLK 1MHz */
	set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
	
	/* Enable Interrupts */
	eint();
	
	uart0_init(UART0_CONFIG_1MHZ_115200);
	uart0_register_callback(char_cb);
	printf("CC1100 RXTX test program\r\n");
	
	LEDS_INIT();
	LEDS_OFF();
	
	cc1100_init();
	
	cc1100_cfg_append_status(CC1100_APPEND_STATUS_ENABLE);
	cc1100_cfg_crc_autoflush(CC1100_CRC_AUTOFLUSH_DISABLE);
	cc1100_cfg_white_data(CC1100_DATA_WHITENING_ENABLE);
	cc1100_cfg_crc_en(CC1100_CRC_CALCULATION_ENABLE);
	cc1100_cfg_freq_if(0x0C);
	cc1100_cfg_fs_autocal(CC1100_AUTOCAL_NEVER);
	
	cc1100_cfg_mod_format(CC1100_MODULATION_MSK);
	
	cc1100_cfg_sync_mode(CC1100_SYNCMODE_30_32);
	
	cc1100_cfg_manchester_en(CC1100_MANCHESTER_DISABLE);
	
	printf("CC1100 initialized\r\nType 's' to send a message\r\n");
	
	while(1)
	{
		// Enter RX
		LED_RED_ON();
		cc1100_cmd_idle();
		cc1100_cmd_flush_rx();
		cc1100_cmd_calibrate();
		cc1100_cmd_rx();
		
		cc1100_cfg_gdo0(CC1100_GDOx_SYNC_WORD);
		cc1100_gdo0_int_set_falling_edge();
		cc1100_gdo0_int_clear();
		cc1100_gdo0_int_enable();
		cc1100_gdo0_register_callback(rx_ok);
		
		// Low Power Mode
		LPM0;
		
		// Check for send flag
		if (send == 1) {
			send = 0;
			LED_RED_OFF();
			cc1100_cmd_idle();
			cc1100_cmd_flush_tx();
			cc1100_cmd_calibrate();
			cc1100_gdo0_int_disable();
			
			frameseq ++;
			
			length = sprintf((char *)frame, "Hello World #%i", frameseq);
			
			printf("Sent : %s \r\n", frame);
			
			cc1100_fifo_put(&length, 1);
			cc1100_fifo_put(frame, length);
			
			cc1100_cmd_tx();
			
			// Wait for SYNC word sent
			while (cc1100_gdo0_read() == 0);
			
			// Wait for end of packet
			while (cc1100_gdo0_read() != 0);
		}
		
		// Check for receive flag
		if (receive == 1) {
			receive = 0;
			uint8_t i;

			// verify CRC result
			if ( !(cc1100_status_crc_lqi() & 0x80) ) {
				continue;
			}

			cc1100_fifo_get(&length, 1);
			
			if (length > 60) {
				continue;
			}
			
			cc1100_fifo_get(frame, length+2);

			uint16_t rssi = (uint16_t)frame[length];
			int16_t rssi_d;

			if (rssi >= 128)
				rssi_d = (rssi-256)-140;
			else
				rssi_d = rssi-140;

			printf("Frame received with RSSI=%d.%d dBm: ", rssi_d, 5*(rssi_d&0x1));
			for (i=0; i<length; i++) {
				printf("%c",frame[i]);
			}
			printf("\r\n");

			LED_GREEN_TOGGLE();
		}
	}
	
	return 0;
}
Beispiel #2
0
void mac_init(uint8_t channel)
{
    // initialize the unique serial number chip and set node address accordingly
    ds2411_init();
    node_addr = (((uint16_t)ds2411_id.serial1)<<8) + (ds2411_id.serial0);

    // seed the random number generator
    srand(node_addr);

    // reset callbacks
    received_cb = 0x0;
    sent_cb = 0x0;
    error_cb = 0x0;

    // initialize the timerB
    timerB_init();
    timerB_start_ACLK_div(1);
    timerB_register_cb(ALARM_RETRY, check);

    // configure the radio
    cc1100_init();
    cc1100_cmd_idle();

    /* configure the radio behaviour */
    cc1100_cfg_append_status(CC1100_APPEND_STATUS_ENABLE);
    cc1100_cfg_crc_autoflush(CC1100_CRC_AUTOFLUSH_DISABLE);
    cc1100_cfg_white_data(CC1100_DATA_WHITENING_ENABLE);
    cc1100_cfg_crc_en(CC1100_CRC_CALCULATION_ENABLE);
    cc1100_cfg_freq_if(0x0E);
    cc1100_cfg_fs_autocal(CC1100_AUTOCAL_IDLE_TO_TX_RX);
    cc1100_cfg_mod_format(CC1100_MODULATION_GFSK);
    cc1100_cfg_sync_mode(CC1100_SYNCMODE_30_32);
    cc1100_cfg_manchester_en(CC1100_MANCHESTER_DISABLE);
    cc1100_cfg_cca_mode(CC1100_CCA_MODE_RSSI_PKT_RX);

    // freq = 860MHz
    cc1100_write_reg(CC1100_REG_FREQ2, 0x1F);
    cc1100_write_reg(CC1100_REG_FREQ1, 0xDA);
    cc1100_write_reg(CC1100_REG_FREQ0, 0x12);

    //packet length to 61
    cc1100_write_reg(CC1100_REG_PKTLEN, 0x3D);

    // configure the radio channel
    cc1100_cfg_chanspc_e(0x2);
    cc1100_cfg_chanspc_m(0xF8);

    cc1100_write_reg(CC1100_REG_DEVIATN, 0x47);

    // rise CCA threshold
    cc1100_cfg_carrier_sense_abs_thr(5);

    // set channel bandwidth
    cc1100_cfg_chanbw_e(1);
    cc1100_cfg_chanbw_m(3);

    // set data rate
    cc1100_cfg_drate_e(0xB);
    cc1100_cfg_drate_m(0x74);

    // go to RX after RX and TX
    cc1100_cfg_rxoff_mode(CC1100_RXOFF_MODE_IDLE);
    cc1100_cfg_txoff_mode(CC1100_TXOFF_MODE_RX);

    uint8_t table[1];
    table[0] = 0x1E;      // -15dBm   13.4mA
    cc1100_cfg_patable(table, 1);
    cc1100_cfg_pa_power(0);

    // set IDLE state, flush everything, and start rx
    cc1100_cmd_idle();
    cc1100_cmd_flush_rx();
    cc1100_cmd_flush_tx();
    cc1100_cmd_calibrate();

    // configure irq
    cc1100_cfg_gdo0(CC1100_GDOx_SYNC_WORD);
    cc1100_gdo0_int_set_falling_edge();
    cc1100_gdo0_int_clear();
    cc1100_gdo0_int_enable();
    cc1100_gdo0_register_callback(rx_parse);

    // start the machine
    rx_set();

    txframe.length = 0;
}