void Nrf24l::send(uint8_t * value) 
// Sends a data package to the default address. Be sure to send the correct
// amount of bytes as configured as payload on the receiver.
{
	uint8_t status;
	status = getStatus();

	while (PTX) {
		status = getStatus();

		if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
			PTX = 0;
			break;
		}
	}                  // Wait until last paket is send

	ceLow();

	powerUpTx();       // Set to transmitter mode , Power up
	flushTx();

	nrfSpiWrite(W_TX_PAYLOAD, value, false, payload);   // Write payload

	ceHi();                     // Start transmission
	ceLow();
}
Exemple #2
0
void Nrf24l::setRADDR(uint8_t * adr) 
// Sets the receiving address
{
	ceLow();
	writeRegister(RX_ADDR_P1,adr,mirf_ADDR_LEN);
	ceHi();
}
Exemple #3
0
void Nrf24l::powerUpRx(){
	PTX = 0;
	ceLow();
	configRegister(CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
	ceHi();
	configRegister(STATUS,(1 << TX_DS) | (1 << MAX_RT)); 
}
Exemple #4
0
void Nrf24l::send(uint8_t * value) 
// Sends a data package to the default address. Be sure to send the correct
// amount of bytes as configured as payload on the receiver.
{
    uint8_t status;
    status = getStatus();

    while (PTX) {
	    status = getStatus();

	    if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
		    PTX = 0;
		    break;
	    }
    }                  // Wait until last paket is send

    ceLow();
    
    powerUpTx();       // Set to transmitter mode , Power up
    
    csnLow();                    // Pull down chip select
    spi->transfer( FLUSH_TX );     // Write cmd to flush tx fifo
    csnHi();                    // Pull up chip select
    
    csnLow();                    // Pull down chip select
    spi->transfer( W_TX_PAYLOAD ); // Write cmd to write payload
    transmitSync(value,payload);   // Write payload
    csnHi();                    // Pull up chip select

    ceHi();                     // Start transmission
}
void Nrf24l::powerUpRx() {
	PTX = 0;
	ceLow();

	configRegister(CONFIG, baseConfig | _BV(PWR_UP) | _BV(PRIM_RX));
	configRegister(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT)); 

	ceHi();
}
void powerUpRx(){
	PTX = 0;
	ceLow();
	uint8_t result = mirf_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX));
	result |= (1<<MASK_MAX_RT) | (1<<MASK_TX_DS); //ativa nIQR apenas quando tem algo para receber (tx mode)
	writeRegister(CONFIG, &result,1);
	ceHi();
	result = (1 << TX_DS) | (1 << MAX_RT);
	writeRegister(STATUS,&result,1);
}
Exemple #7
0
// 上电
void Nrf24l::powerUpRx(){
	PTX = 0;
	ceLow();
	// 使用 ‘0’-8 位CRC 校验模式,开启1:上电模式,开启接收模式
	configRegister(CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
	ceHi();
	// 清除之前的数据发送完成中断。不是关闭中断
	// 当数据发送完成后产生中断。如果工作在自动应答模式下,
	// 只有当接收到应答信号后此位置一。写‘1’清除中断。
	
	// 清除之前的达到最多次重发中断。不是关闭中断
	// 写‘1’清除中断。如果MAX_RT 中断产生则必须清除后系统才能进行通讯。
	configRegister(STATUS,(1 << TX_DS) | (1 << MAX_RT)); 
}
Exemple #8
0
void Nrf24l::send(uint8_t * value) 
// Sends a data package to the default address. Be sure to send the correct
// amount of bytes as configured as payload on the receiver.
{
    uint8_t status;
    status = getStatus();

    while (PTX) {
	    status = getStatus();
//TX_DS 5 0 R/W 数据发送完成中断。当数据发送完成后产生中
//断。如果工作在自动应答模式下,只有当接收到应答信号后此位置一。
//写‘1’清除中断。
//MAX_RT 4 0 R/W 达到最多次重发中断。
//写‘1’清除中断。
//如果MAX_RT 中断产生则必须清除后系统才
//能进行通讯。
	    if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
		    PTX = 0;
		    break;
	    }
    }                  // Wait until last paket is send

    ceLow();
    
    powerUpTx();       // Set to transmitter mode , Power up
    
    csnLow();                    // Pull down chip select
    spi->transfer( FLUSH_TX );     // Write cmd to flush tx fifo
    csnHi();                    // Pull up chip select
    
    csnLow();                    // Pull down chip select
	//W_RX_PAYLOAD  1010 0000 写TX 有效数据:1-32 字节。写操作从字节0 开始。
    //应用于发射模式下
    spi->transfer( W_TX_PAYLOAD ); // Write cmd to write payload
    transmitSync(value,payload);   // Write payload
    csnHi();                    // Pull up chip select

    ceHi();                     // Start transmission
}
void send_rf(uint8_t * value)
// Sends a data package to the default address. Be sure to send the correct
// amount of bytes as configured as payload on the receiver.
{
    uint8_t status;
    status = getStatus();
    while (PTX) {
	    status = getStatus();
	    if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
		    PTX = 0;
		    break;
	    }
    }                  // Wait until last paket is send

    ceLow();

    powerUpTx();       // Set to transmitter mode , Power up

    csnLow();
    uint8_t result = FLUSH_TX;
    SSPSend(&result, 1);
    csnHi();


    uint8_t* rx = (uint8_t*)malloc(sizeof(uint8_t)*(payload+1));
    rx[0] = W_TX_PAYLOAD;
    uint8_t a;
    for(a = 1; a < payload+1; a++){
    	rx[a] = value[a-1];
    }
    csnLow();
    SSPSend(rx, payload+1);
    free(rx);
    csnHi();

    ceHi();                     // Start transmission
    while(isSending());
}
Exemple #10
0
void Nrf24l::send_end() 
{
    csnHi();                    // Pull up chip select

    ceHi();                     // Start transmission
}