Why does my serial port open affect SPI communication
Why does my serial port open affect SPI communication
Hi,
Can you elaborate a little on what it is you are doing?
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
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.0void 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.0Hi,
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.