This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 problems with spi slave

Hi, i'm trying to communicate between a msp-430f5529 (spi master) and a nrf51822 (spi slave). I have configured the MISO, MOSI, CS and SCLK of the nrf. I use the spi_slave_example for testing the communication.

When the spi transfer is completed it calls to the handle "static void spi_slave_event_handle(spi_slave_evt_t event)". As you know to the end of this function you have to set the buffer again (after you process the data that arrived) with "spi_slave_buffers_set" .I want set the new buffer data depending of the last transfer data, then i use a switch case for the first byte that arrives but this fails, i need to set the bufffer to the end of function spi_slave_event_handle(). I'm doing this:

     if (event.evt_type == SPI_SLAVE_XFER_DONE) 
     { 			
      SpiCommand = m_rx_buf[0];			
		switch (SpiCommand)
		{
			case 0x01:
				nrf_gpio_port_set(NRF_GPIO_PORT_SELECT_PORT1, 1);
                 spi_slave_buffers_set(m_tx_buf, m_rx_buf, sizeof(m_tx_buf), sizeof(m_rx_buf));
                 break;
            case 0x02: ...
                 break;
            default:
                 break;
        }             
       }

it doesn't work, the led doesn't turn on. But if i try this:

  if (event.evt_type == SPI_SLAVE_XFER_DONE) 
     { 			
      SpiCommand = m_rx_buf[0];			
		switch (SpiCommand)
		{
			case 0x01:
				nrf_gpio_port_set(NRF_GPIO_PORT_SELECT_PORT1, 1);
                 break;
            case 0x02: ...
                 break;
            default:
                 break;
        }             
         spi_slave_buffers_set(m_tx_buf, m_rx_buf, sizeof(m_tx_buf), sizeof(m_rx_buf));
       }

It works great, the led turn on. I have to put spi_slave_buffers_set() out of the switch at the end. Why? Any idea?

Parents Reply Children
No Data
Related