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

SPI communication problems

Why does my serial port open affect SPI communication

Parents Reply
  • void hal_spi_init(void)//This is my SPI initialization code
    {
     
        nrf_gpio_cfg_output(AEF_START);
        nrf_gpio_pin_set(AEF_START);
        nrf_gpio_cfg_output(AEF_RESET);
        nrf_gpio_pin_set(AEF_RESET);
    
        nrf_gpio_cfg_input(AEF_RDRDY,  NRF_GPIO_PIN_PULLDOWN);
    
        nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    //     spi_config.ss_pin   = BOARD_SPI0_CSN_IO;
        spi_config.miso_pin = BOARD_SPI0_MISO_IO;
        spi_config.mosi_pin = BOARD_SPI0_MOSI_IO;
        spi_config.sck_pin  = BOARD_SPI0_CLK_IO;
        APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
    	
        nrf_gpio_cfg_output(BOARD_SPI0_CSN_IO);
        nrf_gpio_pin_set(BOARD_SPI0_CSN_IO);
    }
    
    
    
    uint8_t SpiFlash_ReadOneByte(void)
    {
       
        spi_xfer_done = false;
    
        nrf_drv_spi_transfer(&spi, 0x00, 1, spi_rx_buf, 1);
    
        while(!spi_xfer_done)
            ;
    	 
        return (spi_rx_buf[0]);
    }
     
    void SpiFlash_WriteOneByte(uint8_t Dat)
    {
        
    
        spi_tx_buf[0] = Dat;
        spi_xfer_done = false;
        nrf_drv_spi_transfer(&spi,spi_tx_buf, 1, spi_tx_buf, 1 );
        while(!spi_xfer_done)
            ;
    }
    This is my SPI initialization code and SPI write read function, which is done according to the example of sdk15.0

Children
  • Hi,

    Your uart communication is sending one byte at the time. this means a lot of cpu processing at priority APP_IRQ_PRIORITY_LOWEST. What priority are you using for SPI? I am guessing it has the same priority so it is first come, first serve. You could try to increase the priority of spi, but that means UART throughput might be affected.

    Maybe a better way is to use bigger buffers in both cases, so you have less cpu interaction all over. Maybe consider using libuarte instead of app_uart.

Related