Exemplo n.º 1
0
/**@brief Function for initializing SPI slave.
 *
 *  Function configures a SPI slave and sets buffers.
 *
 * @retval NRF_SUCCESS  Initialization successful.
 */
uint32_t spi_slave_example_init(void)
{
    uint32_t           err_code;
    spi_slave_config_t spi_slave_config;
        
    err_code = spi_slave_evt_handler_register(spi_slave_event_handle);
    APP_ERROR_CHECK(err_code);    

    spi_slave_config.pin_miso         = SPIS_MISO_PIN;
    spi_slave_config.pin_mosi         = SPIS_MOSI_PIN;
    spi_slave_config.pin_sck          = SPIS_SCK_PIN;
    spi_slave_config.pin_csn          = SPIS_CSN_PIN;
    spi_slave_config.mode             = SPI_MODE_0;
    spi_slave_config.bit_order        = SPIM_LSB_FIRST;
    spi_slave_config.def_tx_character = DEF_CHARACTER;
    spi_slave_config.orc_tx_character = ORC_CHARACTER;
    
    err_code = spi_slave_init(&spi_slave_config);
    APP_ERROR_CHECK(err_code);
    
    //Initialize buffers.
    spi_slave_buffers_init(m_tx_buf, m_rx_buf, (uint16_t)TX_BUF_SIZE);
    
    //Set buffers.
    err_code = spi_slave_buffers_set(m_tx_buf, m_rx_buf, sizeof(m_tx_buf), sizeof(m_rx_buf));
    APP_ERROR_CHECK(err_code);            

    return NRF_SUCCESS;
}
Exemplo n.º 2
0
int main( ) {
	DDRC |= ( 1<<PC5 );
	PORTC |= ( 1<<PC5 );
	
	DDRC |= (1<<PC2);  // TEST LED
	PORTC |= (1<<PC2);
	
	spi_slave_init();
	sei();
	uint8_t* data;

	while ( 1 ) {
		//data != NULL if there is data in the SPI-buffer
		data = spi_receive( );
		if ( data ) {
			//Disable interrupts for more performance
			cli();
			//Write received data to the ledstrip
			//Technically this function wants a RGB-struct but casts it internal to an uint8 array.
			//So we simply ignore the struct to make it easier for us and to save RAM on the ATmega.
			ws2812_setleds( data, NUM_LEDS );
			//Enable interrupts again
			sei();
			//Set ready to receive to get data
			PORTC |= ( 1<<PC5 );
			PORTC |= (1<<PC2);
		}
	}
}
Exemplo n.º 3
0
uint32_t spi_slave_example_init(void)
{
	uint32_t           err_code;
	spi_slave_config_t spi_slave_config;

	// This callback fires after the master has de-asserted chip select
	err_code = spi_slave_evt_handler_register(spi_slave_event_handle);
	APP_ERROR_CHECK(err_code);

	// Setup the pins from the board's .h file
	spi_slave_config.pin_miso         = SPIS_MISO_PIN;
	spi_slave_config.pin_mosi         = SPIS_MOSI_PIN;
	spi_slave_config.pin_sck          = SPIS_SCK_PIN;
	spi_slave_config.pin_csn          = SPIS_CSN_PIN;
	spi_slave_config.mode             = SPI_MODE_0;
	spi_slave_config.bit_order        = SPIM_MSB_FIRST;
	spi_slave_config.def_tx_character = 0x00;
	spi_slave_config.orc_tx_character = 0x55;

	err_code = spi_slave_init(&spi_slave_config);
	APP_ERROR_CHECK(err_code);

	// Set buffers so we can receive
	err_code = spi_slave_buffers_set(spi_tx_buf,
									 spi_rx_buf,
									 SPI_BUF_LEN,
									 SPI_BUF_LEN);
	APP_ERROR_CHECK(err_code);

	return NRF_SUCCESS;
}
Exemplo n.º 4
0
void application_start( void )
{
    /* Initialise the WICED device */
    wiced_init();

    /* Initialise SPI slave device */
    spi_slave_init( &spi_slave_device, &spi_slave_device_config );
}
Exemplo n.º 5
0
void main()
{
 DDRD=0xf0;
 spi_slave_init();
 while(1)
 {
  PORTD=spi_slave_receive(); 
  }
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: obulpathi/avr
int main(void)
{
	spi_slave_init();
	//receive here;
	while(1)
		spi_trx('4');
	
	return 0;
}
Exemplo n.º 7
0
void serial_handler_init(void)
{
    has_pending_tx = false;
    /* init packet queues */
    tx_fifo.array_len = SERIAL_QUEUE_SIZE;
    tx_fifo.elem_array = tx_fifo_buffer;
    tx_fifo.elem_size = sizeof(serial_data_t);
    tx_fifo.memcpy_fptr = NULL;
    fifo_init(&tx_fifo);
    rx_fifo.array_len = SERIAL_QUEUE_SIZE;
    rx_fifo.elem_array = rx_fifo_buffer;
    rx_fifo.elem_size = sizeof(serial_data_t);
    rx_fifo.memcpy_fptr = NULL;
    fifo_init(&rx_fifo);

    nrf_gpio_cfg_output(PIN_RDYN);
    nrf_gpio_pin_set(PIN_RDYN);
    serial_state = SERIAL_STATE_IDLE;

    spi_slave_config_t spi_config;
    spi_config.bit_order = SPIM_LSB_FIRST;
    spi_config.mode = SPI_MODE_0;
    spi_config.def_tx_character = 0;
    spi_config.orc_tx_character = 0;
    spi_config.pin_csn = PIN_CSN;
    spi_config.pin_miso = PIN_MISO;
    spi_config.pin_mosi = PIN_MOSI;
    spi_config.pin_sck = PIN_SCK;



    APP_ERROR_CHECK(spi_slave_init(&spi_config));
    APP_ERROR_CHECK(spi_slave_evt_handler_register(spi_event_handler));

    gpiote_init();

    /* set initial buffers, dummy in tx */
    //prepare_rx();
#if 1 
    /* notify application controller of the restart */ 
    serial_evt_t started_event;
    started_event.length = 4;
    started_event.opcode = SERIAL_EVT_OPCODE_DEVICE_STARTED;
    started_event.params.device_started.operating_mode = OPERATING_MODE_STANDBY;
    uint32_t reset_reason;
    sd_power_reset_reason_get(&reset_reason);
    started_event.params.device_started.hw_error = !!(reset_reason & (1 << 3));
    started_event.params.device_started.data_credit_available = SERIAL_QUEUE_SIZE;
    
    if (!serial_handler_event_send(&started_event))
    {
        APP_ERROR_CHECK(NRF_ERROR_INTERNAL);
    }
#endif
}
Exemplo n.º 8
0
static void intermcu_spi_init(void)
{
    uint32_t           err_code;
    spi_slave_config_t spi_slave_config;
        
    err_code = spi_slave_evt_handler_register(spi_slave_event_handle);
    APP_ERROR_CHECK(err_code);    

    spi_slave_config.pin_miso         = SPIS_MISO_PIN;
    spi_slave_config.pin_mosi         = SPIS_MOSI_PIN;
    spi_slave_config.pin_sck          = SPIS_SCK_PIN;
    spi_slave_config.pin_csn          = SPIS_CSN_PIN;
    spi_slave_config.mode             = SPI_MODE_1;
    spi_slave_config.bit_order        = SPIM_MSB_FIRST;
    spi_slave_config.def_tx_character = DEF_CHARACTER;
    spi_slave_config.orc_tx_character = ORC_CHARACTER;
    
    err_code = spi_slave_init(&spi_slave_config);
    APP_ERROR_CHECK(err_code);

    return; 
}
Exemplo n.º 9
0
void user_init( void )
{
	positiondebut = 0;
	positionfin = 1; 


	positiondebutUDP = 0;
	positionfinUDP = 0;

    static struct station_config config;
    uart_div_modify( 0, UART_CLK_FREQ / ( 115200 ) );
    os_printf( "%s\n", __FUNCTION__ );
    uart_init(115200,9600);
    spi_slave_init(HSPI,SPI_BUFF);
    wifi_station_set_hostname( HOSTNAME );
    wifi_set_opmode_current( STATIONAP_MODE );
    gpio_init();
    spi_gpio_init();
//os_printf sur Uart0
 espconn_init() ;
    uart0_tx_buffer("init\n", 5);
    config.bssid_set = 1;
    os_memcpy( &config.ssid, SSID, 14 );
    os_memcpy( &config.password, PASSWORD, 41);
    wifi_station_set_config( &config );
    wifi_station_connect();
   // wifi_set_event_handler_cb( wifi_callback );
   shell_init();
//Démarage du client UDP
   user_set_station_config_udp();

   MessageUDP.Status = E_ID;
 MessageSPi.Status = E_ID;
    system_os_task(all_recvTask,PRIO_SPI,  all_recvTaskQueue, TASK_LENGHT);  ///demo with a task to process the uart data
    system_os_task(uart_recvTask,PRIO_UART,  uart_recvTaskQueue, TASK_LENGHT); // //demo with a task to process the spi 


}
Exemplo n.º 10
0
/*! \brief Main function.
 */
int main(void)
{
	sysclk_init();
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();

	/* Config the USART_SPI in master mode. */
	usart_spi_init(USART_SPI_EXAMPLE);
	usart_spi_setup_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE,
			SPI_MODE_0, USART_SPI_EXAMPLE_BAUDRATE, 0);
	usart_spi_enable(USART_SPI_EXAMPLE);

	/* Config the SPI module in slave mode. */
	spi_slave_init(SPI_SLAVE_EXAMPLE, SPI_MODE_0);
	spi_enable(SPI_SLAVE_EXAMPLE);

	/* Enable global interrupt */
	cpu_irq_enable();

	/* Show the test result by LED. */
	if (spi_usart_master_transfer() == true && spi_slave_transfer() ==
			true) {
		ioport_set_pin_level(SPI_SLAVE_EXAMPLE_LED_PIN,
				IOPORT_PIN_LEVEL_LOW);
	} else {
		ioport_set_pin_level(SPI_SLAVE_EXAMPLE_LED_PIN,
				IOPORT_PIN_LEVEL_HIGH);
	}

	while (1) {
		/* Do nothing */
	}
}
/* ser_phy API function */
uint32_t ser_phy_open(ser_phy_events_handler_t events_handler)
{
    uint32_t           err_code;
    spi_slave_config_t spi_slave_config;
    spi_slave_evt_t    event;

    if (m_trans_state != SPI_RAW_STATE_UNKNOWN)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    if (events_handler == NULL)
    {
        return NRF_ERROR_NULL;
    }

    //one ppi channel and one gpiote channel are used to drive RDY line
    m_spi_slave_raw_config.pin_req       = SER_PHY_SPI_SLAVE_REQ_PIN;
    m_spi_slave_raw_config.pin_rdy       = SER_PHY_SPI_SLAVE_RDY_PIN;
    m_spi_slave_raw_config.ppi_rdy_ch    = SER_PHY_SPI_PPI_RDY_CH;
    m_spi_slave_raw_config.gpiote_rdy_ch = SER_PHY_SPI_GPIOTE_RDY_CH;

    spi_slave_gpio_init();
#ifndef _SPI_5W_
    spi_slave_gpiote_init();
    spi_slave_ppi_init();
#endif

    err_code = spi_slave_evt_handler_register(spi_slave_event_handle);

    if (err_code == NRF_SUCCESS)
    {

        spi_slave_config.pin_miso         = SPIS_MISO_PIN;
        spi_slave_config.pin_mosi         = SPIS_MOSI_PIN;
        spi_slave_config.pin_sck          = SPIS_SCK_PIN;
        spi_slave_config.pin_csn          = SPIS_CSN_PIN;
        spi_slave_config.mode             = SPI_MODE_0;
        spi_slave_config.bit_order        = SPIM_LSB_FIRST;
        spi_slave_config.def_tx_character = SER_PHY_SPI_DEF_CHARACTER;
        spi_slave_config.orc_tx_character = SER_PHY_SPI_ORC_CHARACTER;

        //keep /CS high when init
        nrf_gpio_cfg_input(spi_slave_config.pin_csn, NRF_GPIO_PIN_PULLUP);
        err_code = spi_slave_set_cs_pull_up_config(GPIO_PIN_CNF_PULL_Pullup);
        APP_ERROR_CHECK(err_code);

        err_code = spi_slave_init(&spi_slave_config);

        if (err_code == NRF_SUCCESS)
        {
            m_ser_phy_callback = events_handler;

            m_trans_state   = SPI_RAW_STATE_SETUP_HEADER;
            event.evt_type  = SPI_SLAVE_EVT_TYPE_MAX; //force transition for dummy event
            event.rx_amount = 0;
            event.tx_amount = 0;
            spi_slave_event_handle(event);

        }
    }
    return err_code;
}