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

SPIS on nRF51822

Hello,

While I was making SPIS part, I got several issues.

I am using STM32L151CB for SPI Master and nRF51822 for SPI Slave. It seems many people had issues with SPIS.

SPIS Setting Code is here.

/**************************************************************************************************/

image description

err_code = spi_slave_evt_handler_register(spi_slave_event_handle);
APP_ERROR_CHECK(err_code);    

spi_slave_config.pin_miso      		= SPI1_MISO_PIN;
spi_slave_config.pin_mosi       	= SPI1_MOSI_PIN;
spi_slave_config.pin_sck			= SPI1_SCK_PIN;
spi_slave_config.pin_csn          	= SPI1_CSN_PIN;
spi_slave_config.mode             	= SPI_MODE_1;			// CPOL : 0  / CPHA : 1    From Cortex-M3
spi_slave_config.bit_order        	= SPIM_MSB_FIRST;            
spi_slave_config.def_tx_character	= DEF_CHARACTER;      	// 0xAA
spi_slave_config.orc_tx_character	= ORC_CHARACTER;      	// 0x55

err_code = spi_slave_init(&spi_slave_config);
APP_ERROR_CHECK(err_code);
   
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;

/**************************************************************************************************/

STM32L151 is using CPOL as 0 and CPHA as 0, so I set SPI_MODE as SPI_MODE_1, and it uses MSB_First.

Is there any problem?

  1. Are initial values of MAXRX and MAXTX registers right values?

image description

  1. After setting NRF_SPIS1->DEF register, I found something strange on register values.

2.1 NRF_SPIS1->ORC = 0x55 doesn't work at all. See below 2 capture images. image description image description

2.2 NRF_SPIS1->SHORTS register is not able to change. See below 2 capture images. Of course, I checked SPIS_SHORTS_END_ACQUIRE_Enabled is 0x01. image description image description

  1. NRF_SPIS1->INTENCLR is set automatically when NRF_SPIS1->INTENSET is set. See below 2 images. image description image description

Because my code can't jump into spi_slave_event_handle(SPIS handler), so I have been struggling with codes, and I want to know whether I made any mistakes for SPIS setting.

Thank you for reading, and I hope to see your answer. Thanks.

Ryan

Parents
  • Hi Ryan

    • STM32L151 is using CPOL as 0 and CPHA as 0, so I set SPI_MODE as SPI_MODE_1, and it uses MSB_First

    Shouldn't you choose the same configuration for the nRF51 SPIS, i.e. SPI_MODE_0?

    • Are initial values of MAXRX and MAXTX registers right values?

    When you set the buffers in main with spi_slave_buffers_set, a state change is performed with call to

    sm_state_change(SPI_BUFFER_RESOURCE_REQUESTED);
    

    that will acquire the semaphore by calling the ACQUIRE task. The application receives in turn the ACQUIRED event where the following code is executed in the SPI1_TWI1_IRQHandler which actually sets the buffer configuration

    NRF_SPIS1->TXDPTR = (uint32_t)mp_spi_tx_buf;
    NRF_SPIS1->RXDPTR = (uint32_t)mp_spi_rx_buf;
    NRF_SPIS1->MAXRX  = m_spi_rx_buf_size;
    NRF_SPIS1->MAXTX  = m_spi_tx_buf_size;
                
    NRF_SPIS1->TASKS_RELEASE = 1u;
                
    sm_state_change(SPI_BUFFER_RESOURCE_CONFIGURED);
    
    • NRF_SPIS1->ORC = 0x55 doesn't work at all. See below 2 capture images.
    • NRF_SPIS1->SHORTS register is not able to change. See below 2 capture images. Of course, I checked SPIS_SHORTS_END_ACQUIRE_Enabled is 0x01.

    Hmm, that is strange, works fine on my side. Are you sure the value of p_spi_slave_config->orc_tx_character is 0x55? Try to set the compiler optimization level to 0 and disable cache as shown below, clean target and rebuild

    image description image description

    • NRF_SPIS1->INTENCLR is set automatically when NRF_SPIS1->INTENSET is set

    I can aggree with you, the representation in the debugger is somewhat confusing, but if you disable the interrupts again by writing into the INTENCLR register with the code below then you can see that the interrupt becomes disabled again

    image description

    • Because my code can't jump into spi_slave_event_handle(SPIS handler)

    You should get an SPIS->END event (which will in turn call your spi_slave_event_handle) when the SPI master finishes the transaction by setting CSN high (CSN is active low). Initialize the CSN by letting the SPI master set the CSN to high at the start of your main function. When you want to transmit data, let the SPI master set CSN low, then transmit your data. Then to finish the transaction and get the SPIS->END event, set the CSN high.

    What SPI clock frequency have you selected?

    Have you tried to run the spi_master_example_with_spi_slave example with the spi_slave_example example, on two boards. Does that work?

  • You can not use the SPI slave with the first revision hardware, you need to buy a new kit/chip. See the PCN-082 document to realize what chips are first revision and what chips are second revision.

Reply Children
No Data
Related