Hello,
I'm using nrf52832, and I have to use two SPI Master instances at the same time. Is this possible?
Thanks in advance
Hello,
I'm using nrf52832, and I have to use two SPI Master instances at the same time. Is this possible?
Thanks in advance
Hello,
Yes. That is possible. What you need to do is to use two different instances of the SPI.
I don't know what SDK version you are using, but if you look in your sdk_config.h file, and search for SPI0_ENABLED. If you do this in the SDK17.0.2\examples\peripheral\spi\ you see that this is defined as 1, while SPI1_ENABLED is set to 0. This means that instance 0 of the SPI is used, but not instance 1.
Please be aware of the file apply_old_config.h if you see both the definition SPI0_ENABLED and NRFX_SPI0_ENABLED in your sdk_config.h file.
Then check out how this example is set up to use SPI instance 0 in main.c. Here are some relevant lines:
#define SPI_INSTANCE 0 /**< SPI instance index. */ static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */ APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL)); APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length));
so the instance used is set in SPI_INSTANCE 0, which is used in the "spi" parameter, which is then intialized and used.
Please also be aware that it is possible to hook on several SPI slaves to one SPI bus. This way, you only need to add one extra gpio to each new SPI device (one SS/CS (Slave/Chip Select)). If you have some other reason to use two instances of SPI, then that is fine. You can use the different instances.
Also note that in case you are also using TWI (I2C), then the SPI and TWI share the same instance IRQ handlers. That means that you can not use SPI0 and TWI0, because they share SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler. If you need e.g. two SPI instances and one TWI, you can use:
TWI0, SPI1 and SPI2.
Best regards,
Edvin
Hello,
Yes. That is possible. What you need to do is to use two different instances of the SPI.
I don't know what SDK version you are using, but if you look in your sdk_config.h file, and search for SPI0_ENABLED. If you do this in the SDK17.0.2\examples\peripheral\spi\ you see that this is defined as 1, while SPI1_ENABLED is set to 0. This means that instance 0 of the SPI is used, but not instance 1.
Please be aware of the file apply_old_config.h if you see both the definition SPI0_ENABLED and NRFX_SPI0_ENABLED in your sdk_config.h file.
Then check out how this example is set up to use SPI instance 0 in main.c. Here are some relevant lines:
#define SPI_INSTANCE 0 /**< SPI instance index. */ static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */ APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL)); APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length));
so the instance used is set in SPI_INSTANCE 0, which is used in the "spi" parameter, which is then intialized and used.
Please also be aware that it is possible to hook on several SPI slaves to one SPI bus. This way, you only need to add one extra gpio to each new SPI device (one SS/CS (Slave/Chip Select)). If you have some other reason to use two instances of SPI, then that is fine. You can use the different instances.
Also note that in case you are also using TWI (I2C), then the SPI and TWI share the same instance IRQ handlers. That means that you can not use SPI0 and TWI0, because they share SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler. If you need e.g. two SPI instances and one TWI, you can use:
TWI0, SPI1 and SPI2.
Best regards,
Edvin