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
  • Hi,

    Can you elaborate a little on what it is you are doing?

  • Hello! Now I mainly do the drive control of SPI to ADC chip, but when I open the serial port to see the data, SPI communication has a problem, there is no write value

  • Hi,
    Could you post your code so it's possible to see what it is you are doing?

    Please note that we have example code for SPI in our SDK that you can use as reference:
    SPI Master Example

    nrfx SPI Master Example

  • 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

  • void UART_Init(void)
    {
    
    uint32_t err_code;
    
    	   
        const app_uart_comm_params_t comm_params =
          {
              RX_PIN_NUMBER,
              TX_PIN_NUMBER,
              RTS_PIN_NUMBER,
              CTS_PIN_NUMBER,
              UART_HWFC,
              false,
    #if defined (UART_PRESENT)
              NRF_UART_BAUDRATE_115200
    #else
              NRF_UARTE_BAUDRATE_115200
    #endif
          };
         
        APP_UART_FIFO_INIT(&comm_params,
                             UART_RX_BUF_SIZE,
                             UART_TX_BUF_SIZE,
                             uart_error_handle, 
                             APP_IRQ_PRIORITY_LOWEST,
                             err_code);
    
        APP_ERROR_CHECK(err_code);
    }
    void UART_WriteData(uint8_t *pData, uint8_t dataLen)
    {
    	uint8_t i;
    	for(i = 0; i < dataLen; i++)
    	{
    		app_uart_put(pData[i]);
    	}
    }
     
    This is my serial initialization function, as well as the serial send function

Reply
  • void UART_Init(void)
    {
    
    uint32_t err_code;
    
    	   
        const app_uart_comm_params_t comm_params =
          {
              RX_PIN_NUMBER,
              TX_PIN_NUMBER,
              RTS_PIN_NUMBER,
              CTS_PIN_NUMBER,
              UART_HWFC,
              false,
    #if defined (UART_PRESENT)
              NRF_UART_BAUDRATE_115200
    #else
              NRF_UARTE_BAUDRATE_115200
    #endif
          };
         
        APP_UART_FIFO_INIT(&comm_params,
                             UART_RX_BUF_SIZE,
                             UART_TX_BUF_SIZE,
                             uart_error_handle, 
                             APP_IRQ_PRIORITY_LOWEST,
                             err_code);
    
        APP_ERROR_CHECK(err_code);
    }
    void UART_WriteData(uint8_t *pData, uint8_t dataLen)
    {
    	uint8_t i;
    	for(i = 0; i < dataLen; i++)
    	{
    		app_uart_put(pData[i]);
    	}
    }
     
    This is my serial initialization function, as well as the serial send function

Children
No Data
Related