Beispiel #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
}
Beispiel #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
}
Beispiel #3
0
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;
}
Beispiel #4
0
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;    
}
Beispiel #5
0
/**
 * @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;
}
Beispiel #6
0
/**
 * @brief Funcion para obtener el registro STATUS.
 * @return  Valor del registro STATUS.
 */
uint8_t NRF_GetStatus(void){
    SPI_ClearRxBuffer();
    Control_Write(0);
    SPI_WriteByte(NRF_NOP);
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    
	return (uint8_t)SPI_ReadRxData();  
}
Beispiel #7
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
}
Beispiel #8
0
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;
}
Beispiel #9
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
}
Beispiel #10
0
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;
}
Beispiel #11
0
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;
}
Beispiel #12
0
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;
}
Beispiel #13
0
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;
}
Beispiel #14
0
void writeBufferTest(uint8_t reg, uint8_t* bufIn, uint8_t bufSize){
    SPI_ClearRxBuffer();
    uint8_t auxBuffer[(bufSize + 1)], i = bufSize, h = bufSize;
    
    for(; i > 0; i--){
        h--;
        auxBuffer[i] = bufIn[h];
    }
    
    auxBuffer[0] = (uint8_t)(NRF_W_REGISTER | reg);
    Control_Write(0);
    SPI_PutArray(auxBuffer, (bufSize + 1));
    while(!(SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
    Control_Write(1);
    
    return;
}
Beispiel #15
0
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;
}
Beispiel #16
0
/*******************************************************************************
* Function Name: SPI_Init
********************************************************************************
*
* Summary:
*  Inits/Restores default SPIM configuration provided with customizer.
*
* Parameters:
*  None.
*
* Return:
*  None.
*
* Side Effects:
*  When this function is called it initializes all of the necessary parameters
*  for execution. i.e. setting the initial interrupt mask, configuring the
*  interrupt service routine, configuring the bit-counter parameters and
*  clearing the FIFO and Status Register.
*
* Reentrant:
*  No.
*
*******************************************************************************/
void SPI_Init(void) 
{
    /* Initialize the Bit counter */
    SPI_COUNTER_PERIOD_REG = SPI_BITCTR_INIT;

    /* Init TX ISR  */
    #if(0u != SPI_INTERNAL_TX_INT_ENABLED)
        CyIntDisable         (SPI_TX_ISR_NUMBER);
        CyIntSetPriority     (SPI_TX_ISR_NUMBER,  SPI_TX_ISR_PRIORITY);
        (void) CyIntSetVector(SPI_TX_ISR_NUMBER, &SPI_TX_ISR);
    #endif /* (0u != SPI_INTERNAL_TX_INT_ENABLED) */

    /* Init RX ISR  */
    #if(0u != SPI_INTERNAL_RX_INT_ENABLED)
        CyIntDisable         (SPI_RX_ISR_NUMBER);
        CyIntSetPriority     (SPI_RX_ISR_NUMBER,  SPI_RX_ISR_PRIORITY);
        (void) CyIntSetVector(SPI_RX_ISR_NUMBER, &SPI_RX_ISR);
    #endif /* (0u != SPI_INTERNAL_RX_INT_ENABLED) */

    /* Clear any stray data from the RX and TX FIFO */
    SPI_ClearFIFO();

    #if(SPI_RX_SOFTWARE_BUF_ENABLED)
        SPI_rxBufferFull  = 0u;
        SPI_rxBufferRead  = 0u;
        SPI_rxBufferWrite = 0u;
    #endif /* (SPI_RX_SOFTWARE_BUF_ENABLED) */

    #if(SPI_TX_SOFTWARE_BUF_ENABLED)
        SPI_txBufferFull  = 0u;
        SPI_txBufferRead  = 0u;
        SPI_txBufferWrite = 0u;
    #endif /* (SPI_TX_SOFTWARE_BUF_ENABLED) */

    (void) SPI_ReadTxStatus(); /* Clear Tx status and swStatusTx */
    (void) SPI_ReadRxStatus(); /* Clear Rx status and swStatusRx */

    /* Configure TX and RX interrupt mask */
    SPI_TX_STATUS_MASK_REG = SPI_TX_INIT_INTERRUPTS_MASK;
    SPI_RX_STATUS_MASK_REG = SPI_RX_INIT_INTERRUPTS_MASK;
}