Ejemplo n.º 1
0
char SetupCC1020RX(char RXANALOG1, char PA_POWER1)
{
    volatile int TimeOutCounter;
    char lock_status;

    // Turn ON DCLK_CS (Carrier Sense Squelch) in RX
    WriteToCC1020Register(CC1020_INTERFACE,ReadFromCC1020Register(CC1020_INTERFACE) | 0x10);


    // Switch into RX, switch to freq. reg A
    WriteToCC1020Register(CC1020_MAIN,0x11);

    // Setup bias current adjustment
    WriteToCC1020Register(CC1020_ANALOG,RXANALOG);

    // Monitor LOCK
    for(TimeOutCounter=30; ((ReadFromCC1020Register(CC1020_STATUS)&0x10)==0)&&(TimeOutCounter>0); TimeOutCounter--)
    {
        _delay_ms(1);
    }

    // If PLL in lock
    if((ReadFromCC1020Register(CC1020_STATUS)&0x10)==0x10)
    {
        lock_status = TRUE;
        sbi(PORTA,LED_PLL);
    }
    else	// Recalibrate
    {
        // If recalibration ok
        if(CalibrateCC1020(PA_POWER1))
        {
            lock_status = TRUE;
            sbi(PORTA,LED_PLL);
            // Else (recalibration failed)
        }
        else
        {
            lock_status = FALSE;
            cbi(PORTA,LED_PLL);
        }
    }


    // Switch RX part of CC1020 on				// RX coming out of PD at this stage
    WriteToCC1020Register(CC1020_MAIN,0x01);

    // Configure LOCK pin to continuous lock status. Active low indicates PLL in lock
    //WriteToCC1020Register(CC1020_LOCK,0x20);

    // Configure LOCK pin to indicate carrier sense. Active low when RSSI above threshold
    WriteToCC1020Register(CC1020_LOCK,0x40);

    // Return LOCK status to application
    return (lock_status);
}
Ejemplo n.º 2
0
char SetupCC1020TX(char TXANALOG1, char PA_POWER1)
{
    volatile int TimeOutCounter;
    int lock_status;

    // Turn off PA to avoid frequency splatter
    WriteToCC1020Register(CC1020_PA_POWER,0x00);

    // Setup bias current adjustment
    WriteToCC1020Register(CC1020_ANALOG,TXANALOG1);

    // Switch into TX, switch to freq. reg B
    WriteToCC1020Register(CC1020_MAIN,0xC1);     // TX Coming out of Power down at this stage

    // Monitor lock
    // LOCK_CONTINUOUS bit set to 1 when PLL is in LOCK
    for(TimeOutCounter=30; ((ReadFromCC1020Register(CC1020_STATUS)&0x10)==0x00)&&(TimeOutCounter>0); TimeOutCounter--)
    {
        _delay_ms(1);
    }

    // If PLL in lock
    if((ReadFromCC1020Register(CC1020_STATUS)&0x10)==0x10)
    {
        lock_status = TRUE;
        sbi(PORTA,LED_PLL);
    }
    else	// if PLL is not locked then Recalibrate
    {
        // If recalibration ok
        if(CalibrateCC1020(PA_POWER1))
        {
            lock_status = TRUE;
            sbi(PORTA,LED_PLL);
            // Else (recalibration failed)
        }
        else
        {
            lock_status = FALSE;
            cbi(PORTA,LED_PLL);
        }
    }

    // Restore PA setting
    WriteToCC1020Register(CC1020_PA_POWER,PA_POWER1);

    // Turn OFF DCLK_CS (Carrier Sense Squelch) in TX
    WriteToCC1020Register(CC1020_INTERFACE,ReadFromCC1020Register(CC1020_INTERFACE)&~0x10);

    // Configure LOCK pin to continuous lock status. Active low indicates PLL in lock
    WriteToCC1020Register(CC1020_LOCK,0x20);

    // Return LOCK status to application
    return (lock_status);
}
Ejemplo n.º 3
0
void WakeUpCC1020ToRX(char RXANALOG1)
{

  // Turn on xtal oscillator core
  WriteToCC1020Register(CC1020_MAIN,0x1B);

  // Setup bias current adjustment
  WriteToCC1020Register(CC1020_ANALOG,RXANALOG1);

  // Insert wait routine here, must wait for xtal oscillator to stabilise, 
  // typically takes 2-5ms.
  //for (i=0x0260; i > 0; i--);
	_delay_ms(3);

  // Turn on bias generator
  WriteToCC1020Register(CC1020_MAIN,0x19);
  
  x = ReadFromCC1020Register(CC1020_MAIN);
  sprintf(arr, "Read: %x\r\n", x);
  //send_UART(arr, strlen(arr));

  // Wait for 150 usec
  _delay_us(150);

  // Turn on frequency synthesiser
  WriteToCC1020Register(CC1020_MAIN,0x11);
}
Ejemplo n.º 4
0
int CalibrateCC1020(char PA_POWER1)
{
    volatile int TimeOutCounter;
    volatile int nCalAttempt;

    // Turn off PA to avoid spurs during calibration in TX mode
    WriteToCC1020Register(CC1020_PA_POWER,0x00);

    // Calibrate, and re-calibrate if necessary:
    for (nCalAttempt = CAL_ATTEMPT_MAX; (nCalAttempt>0); nCalAttempt--)
    {

        // Start calibration
        WriteToCC1020Register(CC1020_CALIBRATE,0xB4);            // verified with cc1020 datasheet

        // Wait for 100 usec. As given errata notes.
        for (int i=0x000B; i > 0; i--);

        // Monitor calibration complete bit in STATUS register
        // CAL_COMPLETE bit set to 1 when calibration is complete
        // Waiting time according to register settings is approx 27ms. Ref_freq=fosc/2 and CAL_WAIT = 11
        // We are waiting for 30ms
        for(TimeOutCounter=30; ((ReadFromCC1020Register(CC1020_STATUS)&0x80)==0x00)&&(TimeOutCounter>0); TimeOutCounter--)
        {
            _delay_ms(1);
        }

        // Monitor lock
        // LOCK_CONTINUOUS bit in STATUS register is set to 1 when PLL is in LOCK
        for(TimeOutCounter=30; ((ReadFromCC1020Register(CC1020_STATUS)&0x10)==0x00)&&(TimeOutCounter>0); TimeOutCounter--)
        {
            _delay_ms(1);
        }

        // Abort further recalibration attempts if successful LOCK
        if((ReadFromCC1020Register(CC1020_STATUS)&0x10) == 0x10)
        {
            break;
        }
    }

    // Restore PA setting
    WriteToCC1020Register(CC1020_PA_POWER, PA_POWER1);

    // Return state of LOCK_CONTINUOUS bit
    return ((ReadFromCC1020Register(CC1020_STATUS)&0x10)==0x10);
}
Ejemplo n.º 5
0
void SetupCC1020PD(void)
{
  
  // Put CC1020 into power-down
  WriteToCC1020Register(CC1020_MAIN,0x1F);
  
  x = ReadFromCC1020Register(CC1020_MAIN);
  sprintf(arr, "Read: %x\r\n", x);
  //send_UART(arr, strlen(arr));

  // Turn off PA to minimise current draw
  WriteToCC1020Register(CC1020_PA_POWER,0x00);
}
Ejemplo n.º 6
0
void SetupCC1020PD(void)
{
    uint8_t x;
    char bufff[100];

    // Put CC1020 into power-down
    WriteToCC1020Register(CC1020_MAIN,0x1F);

    x = ReadFromCC1020Register(CC1020_MAIN);

    sprintf(bufff,"Wake up complete : %d a\r\n",x);
    usart_transmit(bufff);

    // Turn off PA to minimise current draw
    WriteToCC1020Register(CC1020_PA_POWER,0x00);
}
Ejemplo n.º 7
0
int ReadRSSIlevelCC1020(void)
{
    char i;
    //unsigned char RSSI[5];
    unsigned char FILTER;
    int RSSI_dBm;

    // RSSI formula based on CC1020 datahseet and application note 30:
    // P = 1.5 x RSSI - 3 x VGA_SETTING - RSSI_Offset [dBm]

    /*
    VGA_SETTING based on SmartRF Studio - CC1020, v5.3.0.0
    Note: these settings could be subject to optimisation.

    434MHz range:
    -------------------------------------------------
    12.5 => VGA3 = 0x31 => VGA_SETTING = 0x11 = 17dec
    25   => VGA3 = 0x2F => VGA_SETTING = 0x0F = 15dec
    50   => VGA3 = 0x2E => VGA_SETTING = 0x0E = 14dec
    100  => VGA3 = 0x2D => VGA_SETTING = 0x0D = 13dec
    150  => VGA3 = 0x2F => VGA_SETTING = 0x0F = 15dec
    200  => VGA3 = 0x32 => VGA_SETTING = 0x12 = 18dec
    500  => VGA3 = 0x33 => VGA_SETTING = 0x13 = 19dec

    868MHz range:
    -------------------------------------------------
    12.5 => VGA3 = 0x2F => VGA_SETTING = 0x0F = 15dec
    25   => VGA3 = 0x2E => VGA_SETTING = 0x0E = 14dec
    50   => VGA3 = 0x2D => VGA_SETTING = 0x0D = 13dec
    100  => VGA3 = 0x2D => VGA_SETTING = 0x0D = 13dec
    150  => VGA3 = 0x2E => VGA_SETTING = 0x0E = 14dec
    200  => VGA3 = 0x30 => VGA_SETTING = 0x10 = 16dec
    500  => VGA3 = 0x34 => VGA_SETTING = 0x14 = 20dec
    */

    // Get current channel spacing
    FILTER = ReadFromCC1020Register(CC1020_FILTER)&0x7F;

    // Calculate average RSSI in dBm (initially without offset):
    //for(i = 0; i < 5; i++) {
    //  RSSI[i] = ReadFromCC1020Register(CC1020_RSSI);
    //}
    //RSSI_dBm = (int)((((unsigned int)RSSI[0]+(unsigned int)RSSI[1]+(unsigned int)RSSI[2]+(unsigned int)RSSI[3]+(unsigned int)RSSI[4])*3)/(2*5));

    RSSI_dBm = RXBUFFER[0];
    RSSI_dBm = ((RSSI_dBm*3) - (3*(int)(ReadFromCC1020Register(CC1020_VGA3)&0x1F)*2)) / 2;		// RSSI w/o offset

    // Calculate average RSSI in dBm with offset, according to frequency band:
    // Active frequency is in 800 MHz band
    if( (ReadFromCC1020Register(CC1020_ANALOG)&0x80) == 0x80 )
    {
        switch ( FILTER )
        {
        case 0x58://12.5 kHz spacing
        case 0x3F://12.5 kHz spacing, optimal sensitivity
            RSSI_dBm = RSSI_dBm - 95;
            break;
        case 0x2F://25 kHz spacing
            RSSI_dBm = RSSI_dBm - 96;
            break;
        case 0x2B://50 kHz spacing
            RSSI_dBm = RSSI_dBm - 95;
            break;
        case 0x25://100 kHz spacing
            RSSI_dBm = RSSI_dBm - 96;
            break;
        case 0x22://150 kHz spacing
            RSSI_dBm = RSSI_dBm - 99;
            break;
        case 0x01://200 kHz spacing
            RSSI_dBm = RSSI_dBm - 99;
            break;
        case 0x00://500 kHz spacing
            RSSI_dBm = RSSI_dBm - 101;
            break;
        }
        // Active frequency is in 434 MHz band
    }
    else
    {
        switch ( FILTER ) {
        case 0x38://12.5 kHz spacing
        case 0x2F://25 kHz spacing
            RSSI_dBm = RSSI_dBm - 102;
            break;
        case 0x2B://50 kHz spacing
            RSSI_dBm = RSSI_dBm - 100;
            break;
        case 0x25://100 kHz spacing
            RSSI_dBm = RSSI_dBm - 99;
            break;
        case 0x22://150 kHz spacing
            RSSI_dBm = RSSI_dBm - 101;
            break;
        case 0x01://200 kHz spacing
            RSSI_dBm = RSSI_dBm - 102;
            break;
        case 0x00://500 kHz spacing
            RSSI_dBm = RSSI_dBm - 103;
            break;
        }
    }

    return(RSSI_dBm);
}
Ejemplo n.º 8
0
int Receivepacket(void)
{


    unsigned char dummy=0x00;
//	unsigned char reg=0x00;
    char prev_bit=1;
    char Preamblefound=0, SOF=0, err_flag=0;
    curr_buffer_index=0;
    no_databytes_toread=0;
    rxcount=0;

    RXBUFFER[curr_buffer_index]=ReadFromCC1020Register(CC1020_RSSI);	//RXBUFFER[0]=RSSI
    curr_buffer_index++;
    RXBUFFER[curr_buffer_index]=ReadFromCC1020Register(CC1020_STATUS);	//RXBUFFER[1]=STATUS
    curr_buffer_index++;

    // Detect preamble.
    while(!Preamblefound)
    {
        // Read first bit
        while (PINB&(1<<DCLK));			// read data on rising edge of DCLK
        while (!(PINB&(1<<DCLK)));		// since by then it is stable
        //_delay_us(100);

        if(PINB & (1<<DIO))				// Is the first bit 1?
        {
            if(prev_bit==0)					// 01 found, increment count
                rxcount=rxcount+2;
            else
                rxcount=0;
        }
        else
        {
            // No, first bit is 0. Next read second bit
            while (PINB&(1<<DCLK));
            while (!(PINB&(1<<DCLK)));
            //_delay_us(100);

            if(PINB & (1<<DIO))			// Is 2nd bit 1?
            {
                prev_bit=1;
                rxcount=rxcount+2;				// 01 found, increment count
            }
            else
            {
                prev_bit=0;
                rxcount=0;
            }
        }

        //if(rxcount==40)	// 5 bytes of preamble received. This is value is changeable.
        if(rxcount==56)		// 7 bytes of preamble received. This is value is changeable.
            //if(rxcount==72)			// 9 bytes
        {
            Preamblefound=1;
        }

    }

    // Detect Start of Frame (SOF)
    /*while(!SOF)
    {
    	dummy=0x00;
    	for(int l=1;l<=4;l++)			// Read 4 bits.
    	{
    		while (PINB&(1<<DCLK));
    		while (!(PINB&(1<<DCLK)));
    		//_delay_us(100);

    		dummy=dummy<<1;
    		if(PINB & (1<<DIO))
    			{dummy |= 0x01;}
    		else dummy &= 0xFE;
    	}
    	switch(dummy)
    	{
    		case 0x00:		//error
    			err_flag=1;
    			break;

    		case 0x01:		//error
    			err_flag=1;
    			break;

    		case 0x02:		//error
    			err_flag=1;
    			break;

    		case 0x03:		//error
    			err_flag=1;
    			break;

    		case 0x04:		//error
    			err_flag=1;
    			break;

    		case 0x05:		// Part of remaining preamble. Just increment count, do nothing
    			rxcount=rxcount+2;
    			break;

    		case 0x06:		//error
    			err_flag=1;
    			break;

    		case 0x07:		//Start of frame detetcted
    			SOF=1;
    			for(int l=5;l<=8;l++)	// Read the remaining 4 bits
    			{
    				while (PINB&(1<<DCLK));
    				while (!(PINB&(1<<DCLK)));
    				//_delay_us(100);
    				dummy=dummy<<1;
    				if(PINB & (1<<DIO))
    					{dummy |= 0x01;}
    				else dummy &= 0xFE;
    			}

    			RXBUFFER[curr_buffer_index]=rxcount;		//RXBUFFER[2]=No. of bits of preamble received.
    			curr_buffer_index++;

    			RXBUFFER[curr_buffer_index]=dummy;			//RXBUFFER[3]=SOF_1 / flag
    			curr_buffer_index++;

    			/*ReadNumberofBytes(2);						//RXBUFFER[4]=SOF_2 & RXBUFFER[5]=Number of Data bytes to read
    			curr_buffer_index--;
    			no_databytes_toread = RXBUFFER[curr_buffer_index];
    			curr_buffer_index++;*/

    /*ReadNumberofBytes(1);
    curr_buffer_index--;
    curr_byte = RXBUFFER[curr_buffer_index];
    curr_buffer_index++;

    //if((RXBUFFER[3] != SOF_1) || (RXBUFFER[4] != SOF_2))
    if((RXBUFFER[3] != flag))
    {
       //SOF is not correctly received
       err_flag=1;

    }
    break;
    }

    if(err_flag==1)
    {
    return(0);
    }

    }*/

    while(!SOF)
    {
        dummy=0x00;
        for(int l=1; l<=8; l++)			// Read 8 bits.
        {
            while (PINB&(1<<DCLK));
            while (!(PINB&(1<<DCLK)));
            //_delay_us(100);

            dummy=dummy<<1;
            if(PINB & (1<<DIO))
            {
                dummy |= 0x01;
            }
            else dummy &= 0xFE;
        }

        while (dummy != flag)
        {
            while (PINB&(1<<DCLK));
            while (!(PINB&(1<<DCLK)));
            //_delay_us(100);
            dummy=dummy<<1;
            if(PINB & (1<<DIO))
            {
                dummy |= 0x01;
            }
            else dummy &= 0xFE;
        }

        SOF = 1;
        RXBUFFER[curr_buffer_index]=rxcount;		//RXBUFFER[2]=No. of bits of preamble received.
        curr_buffer_index++;

        RXBUFFER[curr_buffer_index]=dummy;			//RXBUFFER[3]=SOF_1 / flag
        curr_buffer_index++;

        /*ReadNumberofBytes(2);						//RXBUFFER[4]=SOF_2 & RXBUFFER[5]=Number of Data bytes to read
        curr_buffer_index--;
        no_databytes_toread = RXBUFFER[curr_buffer_index];
        curr_buffer_index++;*/

        ReadNumberofBytes(1);
        curr_buffer_index--;
        curr_byte = RXBUFFER[curr_buffer_index];
        curr_buffer_index++;

        //if((RXBUFFER[3] != SOF_1) || (RXBUFFER[4] != SOF_2))
        if((RXBUFFER[3] != flag))
        {
            //SOF is not correctly received
            err_flag=1;
            //return(0);

        }

    }

    if(err_flag==1)
    {
        return(0);
    }

    //ReadNumberofBytes(no_databytes_toread);
    while (curr_byte != flag)
    {
        ReadNumberofBytes(1);
        curr_buffer_index--;
        curr_byte = RXBUFFER[curr_buffer_index];
        curr_buffer_index++;
    }

    return(rxcount);
}