This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with nrf51822 in spi slave mode

Hello all

I making some device with ARM core CPU with nRF51822.

I set CPU to SPI master and set nRF51822 to slave. And then I read some data from nRF51822, that was always "0x55" or "0xAA". That depend on configuration of POL and PHA in master side.

Do you guess what is wrong?

B. Regards,

Parents
  • Dear Stefan Birnir Sverrisson

    I set 1 ms delay before and after CSN HIGH.

    Here is my using code in master and slave.

    Could you find something wrong in this?

    For Master (just pseudocode)

    spi_test()
    {
    spi_init();
    spi_cs_enable(); // LOW
    spi_write( 0x33, 1 );
    delay( 1ms );
    spi_cs_disable(); // HIGH
    delay( 1ms );
    
    spi_cs_enable();
    read = spi_read( 1 );
    delay( 1ms );
    spi_cs_disable();
    delay(1ms);
    }
    

    For slave

    static void spi_slave_event_handle(spi_slave_evt_t event)
    {
    uint32_t err_code;
    
    if (event.evt_type == SPI_SLAVE_XFER_DONE)
    { 
        led_toggle();
        
        //Check if buffer size is the same as amount of received data.
        APP_ERROR_CHECK_BOOL(event.rx_amount == RX_BUF_SIZE);
    
        // loop back
        for( i=0 ; i<event.rx_amount ; i++ )
        {
          m_tx_buf[i] = m_rx_buf[i];
        }
    
        //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);          
    }
    }
    
  • You need to provide the delay between spi_cs_enable and spi_write, also between spi_cs_enable and spi_read

Reply Children
No Data
Related