[ create a new paste ] login | about

Link: http://codepad.org/devRViR1    [ raw code | fork ]

C, pasted on Mar 25:
//Gets the received power detector
bool read_RPD_nRF24L01(void)
{
    uint8_t i, j, data, cmd;

    cmd = 0x09; //Read RPD register ==========================================================================================
    
	cbi(L01_PORT, L01_CSN);//CSN = 0
	delay_us(RF_DELAY);
    
    for(i = 0 ; i < 8 ; i++)
    {
		if(cmd & 0b10000000)
			sbi(L01_PORT, MOSI);
		else
			cbi(L01_PORT, MOSI);
		
		sbi(L01_PORT, L01_SCK); //L01_SCK = 1;
		delay_us(RF_DELAY);

		cbi(L01_PORT, L01_SCK); //L01_SCK = 0; 
		delay_us(RF_DELAY);
		
        cmd <<= 1;
		
    }
    //read the 1 byte register and the LSB is the last bit with the RPD flag
    for(i = 0 ; i < 8 ; i++)
    {
	    if(i==7 && (L01_PORT_PIN & (1<<MISO))) return true;
	    //we are receiving more than -64dBm
	    else if (i==7 && (~L01_PORT_PIN & (1<<MISO))) return false; 	
		//we are receiving less than -64dBm
		//read the next bit
		sbi(L01_PORT, L01_SCK); //L01_SCK = 1;
		delay_us(RF_DELAY);
        
		cbi(L01_PORT, L01_SCK); //L01_SCK = 0; 
		delay_us(RF_DELAY);
    }
	
    sbi(L01_PORT, L01_CSN);//CSN = 1
    
}


Create a new paste based on this one


Comments: