Ejemplo n.º 1
0
void Nrf24l::send_head() 
// 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
}
Ejemplo n.º 2
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
}
Ejemplo n.º 3
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
	flushTx();

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

	ceHi();                     // Start transmission
	ceLow();
}
Ejemplo n.º 4
0
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());
}