Exemplo n.º 1
0
// Write short register
void zigbee_short_write(uint8 adr, uint8 dat)
{
    adr = (adr << 1) | 1;						// Setup address for write
    SPI_WriteTxData(adr);						// Send SPI address
    SPI_WriteTxData(dat);						// Send SPI data
    while( !(SPI_ReadTxStatus() & 0x01));       // while not: SPI-done, wait
}
Exemplo n.º 2
0
// Read short register
uint8 zigbee_short_read(uint8 adr)
{
    adr = adr << 1;								// Setup address for read
    SPI_WriteTxData(adr);						// Send SPI address
    SPI_WriteTxData(0x00);                      // Send dummy byte for read
    while( !(SPI_ReadTxStatus() & 0x01));       // while not: SPI-done, wait
    return SPI_ReadRxData();					// Read SPI data
}
Exemplo n.º 3
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
void NRF_WriteSingleRegister(uint8_t reg, uint8_t data){
    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_W_REGISTER | reg);
    SPI_WriteTxData(data);
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    return;
}
Exemplo n.º 4
0
// Write long register
void zigbee_long_write(uint16 adr, uint8 dat)
{
    uint8 adrMSB, adrLSB;
    adr = (adr << 5) | (1 << 15) | (1 << 4);    // Setup address for write
    adrMSB = adr >> 8;							// Setup address MSB
    adrLSB = adr;								// Setup address LSB
    SPI_WriteTxData(adrMSB);					// Send SPI address MSB
    SPI_WriteTxData(adrLSB);					// Send SPI address LSB
    SPI_WriteTxData(dat);						// Send SPI data
    while( !(SPI_ReadTxStatus() & 0x01));       // while not: SPI-done, wait
}
Exemplo n.º 5
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
void NRF_ReadSingleRegister(uint8_t reg, uint8_t* data){
    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_R_REGISTER | reg);
    SPI_WriteTxData(NRF_NOP);
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    (void)SPI_ReadRxData(); /* Dummy read, this is the STATUS Register */
    *data = SPI_ReadRxData();
    
    return;
}
Exemplo n.º 6
0
// Read long register
uint8 zigbee_long_read(uint16 adr)
{
    uint8 adrMSB, adrLSB;
    adr = (adr << 5) | (1 << 15);				// Setup address for read
    adrMSB = adr >> 8;							// Setup address MSB
    adrLSB = adr;								// Setup address LSB
    SPI_WriteTxData(adrMSB);					// Send SPI address MSB
    SPI_WriteTxData(adrLSB);					// Send SPI address LSB
    SPI_WriteTxData(0x00);                      // Send dummy byte for read
    while( !(SPI_ReadTxStatus() & 0x01));       // while not: SPI-done, wait
    return SPI_ReadRxData();					// Read SPI data
}
Exemplo n.º 7
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
void NRF_WriteMultipleRegister(uint8_t reg, uint8_t* bufIn, uint8_t bufSize){
	uint8_t i = 0;

    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_W_REGISTER | reg);
    for(; i < bufSize; i++){
        SPI_WriteTxData(bufIn[i]);
    }
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    
    return;
}
Exemplo n.º 8
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
void NRF_RxWritePayload(uint8_t pipe, uint8_t* data, uint8_t payloadSize){
    uint8_t i = 0;

    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_W_ACK_PAYLOAD | (pipe & 0x7));
    for(; i < payloadSize; i++){
        SPI_WriteTxData(data[i]);
    }
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    
    return;
}
Exemplo n.º 9
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
void NRF_FillTxFIFO(uint8_t* data, uint8_t payloadSize){
    uint8_t i = 0;

    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_W_TX_PAYLOAD);
    for(; i < payloadSize; i++){
        SPI_WriteTxData(data[i]);
    }
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    
    return;
}
Exemplo n.º 10
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
void NRF_TxTransmitWaitNoACK(uint8_t* data, uint8_t payloadSize){
    uint8_t i = 0;

    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_W_TX_PAYLOAD_NOACK);
    for(; i < payloadSize; i++){
        SPI_WriteTxData(data[i]);
    }
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    NRF_TransmitPulse();
    
    return;
}
Exemplo n.º 11
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
void NRF_ReadMultipleRegister(uint8_t reg, uint8_t* bufIn , uint8_t bufSize){
	uint8_t i = 0, j = 0;
	
    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_R_REGISTER | reg);
    for(; i < bufSize; i++){
        SPI_WriteTxData(NRF_NOP);
    }
    (void)SPI_ReadRxData(); /* Dummy read, this is the STATUS Register */
    for(; j < bufSize; j++){
        *(bufIn + j) = SPI_ReadRxData();
    }
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    
    return;
}
Exemplo n.º 12
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
void NRF_ReuseTxPayload(void){
    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_REUSE_TX_PL);
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    
    return;    
}
Exemplo n.º 13
0
Arquivo: NRF.c Projeto: C47D/nRF24_Rx
/**
 * @brief Vaciamos el TX FIFO.
 */
void NRF_FlushTx(void){
    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteTxData(NRF_FLUSH_TX);
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    
    return;
}
Exemplo n.º 14
0
/*******************************************************************************
* Function Name: SPI_PutArray
********************************************************************************
*
* Summary:
*  Write available data from ROM/RAM to the TX buffer while space is available
*  in the TX buffer. Keep trying until all data is passed to the TX buffer.
*
* Parameters:
*  *buffer: Pointer to the location in RAM containing the data to send
*  byteCount: The number of bytes to move to the transmit buffer.
*
* Return:
*  None.
*
* Side Effects:
*  Will stay in this routine until all data has been sent.  May get locked in
*  this loop if data is not being initiated by the master if there is not
*  enough room in the TX FIFO.
*
* Reentrant:
*  No.
*
*******************************************************************************/
void SPI_PutArray(const uint8 buffer[], uint8 byteCount)
                                                                          
{
    uint8 bufIndex;

    bufIndex = 0u;

    while(byteCount > 0u)
    {
        SPI_WriteTxData(buffer[bufIndex]);
        bufIndex++;
        byteCount--;
    }
}