Exemplo n.º 1
0
/*====================================================================================================*/
void SPI_RW( nrf_drv_kspi_t *SPIx, uint8_t *writeData, uint8_t writeLens, uint8_t *readData, uint8_t readLens )
{
  SPIx->flag = false;
  nrf_drv_spi_transfer(&(SPIx->instance), writeData, writeLens, readData, readLens);
  while(!SPIx->flag)
    __WFE();
}
Exemplo n.º 2
0
/**
 * @brief Function for requesting the SPI transaction.
 *
 * The SPI bus must be initialized prior to use of this function.
 *
 * @param[in] p_txb     Pointer to the TX buffer.
 * @param[in] tx_len    TX buffer length.
 * @param[out] p_rxb    Pointer to the RX buffer.
 * @param[in] tx_len    RX buffer length.
 */
__STATIC_INLINE void sdc_spi_transfer(uint8_t const * const p_txb,
                                      uint8_t tx_len,
                                      uint8_t * const p_rxb,
                                      uint8_t rx_len)
{
    SDC_CS_ASSERT();
    ret_code_t err_code = nrf_drv_spi_transfer(&m_spi, p_txb, tx_len, p_rxb, rx_len);
    APP_ERROR_CHECK(err_code);
}
Exemplo n.º 3
0
/**@brief Functions prepares buffers and starts data transfer.
 *
 * @param[in] p_tx_data     A pointer to a buffer TX.
 * @param[in] p_rx_data     A pointer to a buffer RX.
 * @param[in] tx_len        A length of the tx data buffers.
 * @param[in] rx_len        A length of the rx data buffers.
 */
uint32_t spi_send_recv(uint8_t * const p_tx_data,
                          uint8_t * const p_rx_data,
                          const uint16_t  tx_len,
                          const uint16_t  rx_len)
{
    // Start transfer.
    uint32_t err_code = nrf_drv_spi_transfer(&m_spi_master,
        p_tx_data, tx_len, p_rx_data, rx_len);
    APP_ERROR_CHECK(err_code);
    nrf_delay_ms(DELAY_MS);
	return err_code;
}
Exemplo n.º 4
0
/**@brief Functions prepares buffers and starts data transfer.
 *
 * @param[in] p_tx_data     A pointer to a buffer TX.
 * @param[in] p_rx_data     A pointer to a buffer RX.
 * @param[in] len           A length of the data buffers.
 */
static void spi_send_recv(uint8_t * const p_tx_data,
                          uint8_t * const p_rx_data,
                          const uint16_t  len)
{
    // Initalize buffers.
    init_buffers(p_tx_data, p_rx_data, len);

    // Start transfer.
    uint32_t err_code = nrf_drv_spi_transfer(&m_spi_master,
        p_tx_data, len, p_rx_data, len);
    APP_ERROR_CHECK(err_code);
    nrf_delay_ms(DELAY_MS);
}
Exemplo n.º 5
0
/**@brief Functions prepares buffers and starts data transfer.
 *
 * @param[in] p_tx_data     A pointer to a buffer TX.
 * @param[in] p_rx_data     A pointer to a buffer RX.
 * @param[in] len           A length of the data buffers.
 */
static void spi_send_recv(uint8_t * const p_tx_data,
                          uint8_t * const p_rx_data,
                          const uint16_t  len)
{
    // Initalize buffers.
   // init_buffers(p_tx_data, p_rx_data, len); //comment this out since I want to read a register

    // Start transfer.
    uint32_t err_code = nrf_drv_spi_transfer(&m_spi_master,
        p_tx_data, len, p_rx_data, len);
    APP_ERROR_CHECK(err_code);
  nrf_delay_ms(100); //not having this delay allows the function to return at least once
}
Exemplo n.º 6
0
/**
 * @brief TxPacket : transmit TX address and payload data
 * @param none
 */
void TxPacket(void)
{
	uint32_t err_code;
	
	/* transmiting address */
	unsigned char txAddr[5]={
		0x22,0xcc,0xcc,0xcc,0xcc,
	};
	/* transmit Payload data */
	unsigned char txBuf[4];
	txBuf[0] = 0x20;
	txBuf[1] = 'R';
	txBuf[2] = 'F';
	
	nrf_gpio_pin_clear(CSN);
	
	/* Write payload data	*/
	err_code = nrf_drv_spi_transfer(&spi, txBuf, 4, NULL, 0);
	APP_ERROR_CHECK(err_code);
	
	nrf_gpio_pin_set(CSN);
	nrf_delay_ms(10);
	
  	/* Spi enable for write a spi command */
	nrf_gpio_pin_clear(CSN);
	
	/* Write 4 bytes address */
	err_code = nrf_drv_spi_transfer(&spi, txAddr, 5, NULL, 0);
	APP_ERROR_CHECK(err_code);
	
	/* Spi disable */
	nrf_gpio_pin_set(CSN);
		
	/* Set TRX_CE high,start Tx data transmission, CE pulse */
	nrf_gpio_pin_set(TRX_CE);
	nrf_delay_ms(10);
	
	nrf_gpio_pin_clear(TRX_CE);
}
Exemplo n.º 7
0
/**
 * @brief read_config : send read configuration (RC) command.
 * @param none
 */
void read_config(void)
{	
	unsigned char txCmd[1];
	unsigned char data[11];
	
	nrf_gpio_pin_clear(CSN);
	
	txCmd[0] = RC;
		
	/* send read configuration command */
	uint32_t err_code = nrf_drv_spi_transfer(&spi, txCmd, 1, data, 11);
    	APP_ERROR_CHECK(err_code);
	
	nrf_gpio_pin_set(CSN);					/* Disable Spi */
}
Exemplo n.º 8
0
Arquivo: main.c Projeto: JulianYG/WNR
/**@brief Function for initializing a SPI master driver.
 *
 * @param[in] p_instance    Pointer to SPI master driver instance.
 * @param[in] lsb           Bits order LSB if true, MSB if false.
 */
static void spi_master_init(nrf_drv_spi_t const * p_instance, bool lsb)
{
    uint32_t err_code = NRF_SUCCESS;

    nrf_drv_spi_config_t config =
    {
        .irq_priority = APP_IRQ_PRIORITY_LOW,
        .orc          = 0xCC,
        .frequency    = NRF_DRV_SPI_FREQ_8M,   // originally NRF_DRV_SPI_FREQ_1M
        .mode         = NRF_DRV_SPI_MODE_0,
        .bit_order    = (lsb ? //if lsb then LSB_FIRRST, else MSB_FIRST
            NRF_DRV_SPI_BIT_ORDER_LSB_FIRST : NRF_DRV_SPI_BIT_ORDER_MSB_FIRST),
    };

    if (p_instance == &m_spi_master_0)
    {
        config.sck_pin  = SPIM0_SCK_PIN;
        config.mosi_pin = SPIM0_MOSI_PIN;
        config.miso_pin = SPIM0_MISO_PIN; // SS not initialized
				config.ss_pin 	= SPIM0_SS_PIN;
			  err_code = nrf_drv_spi_init(p_instance, &config,
				//spi_intan_id_read_handler);           // EDIT: INTAN ID spi handler
				spi_master_0_event_handler);    // EDIT: data collection spi handler
    }

    APP_ERROR_CHECK(err_code);
}


/**@brief Function for sending and receiving data.
 *
 * @param[in]   p_instance   Pointer to SPI master driver instance.
 * @param[in]   p_tx_data    A pointer to a buffer TX.
 * @param[out]  p_rx_data    A pointer to a buffer RX.
 * @param[in]   len          A length of the data buffers.
 */
static void spi_send_recv(nrf_drv_spi_t const * p_instance,
                          uint8_t * p_tx_data,
                          uint8_t * p_rx_data,
                          uint16_t  tx_len,
                          uint16_t  rx_len)
{
    uint32_t err_code = nrf_drv_spi_transfer(p_instance,
        p_tx_data, tx_len, p_rx_data, rx_len);
    //APP_ERROR_CHECK(err_code);
}
Exemplo n.º 9
0
void spi_master_transfer(spi_t *obj,
                         const void *tx, size_t tx_length,
                         void *rx, size_t rx_length, uint8_t bit_width,
                         uint32_t handler, uint32_t event, DMAUsage hint)
{
    spi_info_t *p_spi_info = SPI_INFO(obj);
    MBED_ASSERT(p_spi_info->master);
    (void)hint;
    (void)bit_width;

    p_spi_info->handler = handler;
    p_spi_info->event   = event;

    p_spi_info->flag.busy = true;
    (void)nrf_drv_spi_transfer(MASTER_INST(obj),
        (uint8_t const *)tx, tx_length,
        (uint8_t *)rx, rx_length);
}
Exemplo n.º 10
0
int spi_master_write(spi_t *obj, int value)
{
    spi_info_t *p_spi_info = SPI_INFO(obj);

#if DEVICE_SPI_ASYNCH
    while (p_spi_info->flag.busy) {
    }
#endif

    p_spi_info->tx_buf = value;
    p_spi_info->flag.busy = true;
    (void)nrf_drv_spi_transfer(MASTER_INST(obj),
        (uint8_t const *)&p_spi_info->tx_buf, 1,
        (uint8_t *)&p_spi_info->rx_buf, 1);
    while (p_spi_info->flag.busy) {
    }

    return p_spi_info->rx_buf;
}
Exemplo n.º 11
0
/**@brief Functions prepares buffers and starts data transfer.
 *
 * @param[in] p_tx_data     A pointer to a buffer TX.
 * @param[in] p_rx_data     A pointer to a buffer RX.
 * @param[in] len           A length of the data buffers.
 */
static void spi_send_recv(uint8_t * const p_tx_data,
                          uint8_t * const p_rx_data,
                          const uint16_t  len)
{
    // Initalize buffers.
    init_buffers(p_tx_data, p_rx_data, len);
        
    
    // Start transfer.
    
    uint32_t err_code = nrf_drv_spi_transfer(&m_spi_master,
        p_tx_data, len, p_rx_data, len);
    //m_tx_data
    //SEGGER_RTT_printf(0, "\nSent: %s\n", p_tx_data);
    //SEGGER_RTT_printf(0, "\nRecieved: %s\n", p_rx_data);
    
    APP_ERROR_CHECK(err_code);
    //nrf_delay_us(10);
}
Exemplo n.º 12
0
/**
 * @brief RxPacket : receive payload data
 * @param none
 */
void RxPacket(void)
{	
	unsigned char rxBuffer[3] = "";
	unsigned char txBuf[1];

	nrf_delay_ms(100);
	
	nrf_gpio_pin_clear(TRX_CE);
	nrf_gpio_pin_clear(CSN);
	nrf_delay_ms(1);
	
	txBuf[0] = RRP;
		
	uint32_t err_code = nrf_drv_spi_transfer(&spi, txBuf, 1, rxBuffer, 3);
	APP_ERROR_CHECK(err_code);
	
	nrf_gpio_pin_set(CSN);
	nrf_delay_ms(10);
	nrf_gpio_pin_set(TRX_CE);
}
Exemplo n.º 13
0
/**
 * @brief Write_Config : send write configuration (WC) command and data.
 * @param none
 */
void Write_Config(void)
{	
	uint32_t err_code;
	
	unsigned char config_data[11]={
	0x00,
  	0x6A,                   //CH_NO,433MHZ
	0x0c,                   //output power 10db, resend disable, Current Normal operation
	0x44,                   //4-byte address
    	0x03,0x03,              //receive or send data length 32 bytes
	0xcc,0xcc,0xcc,0xcc,    //receiving address
    	0x58,									  //CRC enable,8bit CRC,external clock disable,16MHZ Oscillator               
	};
		
	/* Spi enable for write a spi command */
	nrf_gpio_pin_clear(CSN);

	err_code = nrf_drv_spi_transfer(&spi, config_data, 11, NULL, 0);
	APP_ERROR_CHECK(err_code);
		
	nrf_gpio_pin_set(CSN);					/* Disable Spi */
}
Exemplo n.º 14
0
static inline void spi_write(const void * data, size_t size)
{
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, data, size, NULL, 0));
}