new spim2
This commit is contained in:
@@ -188,6 +188,8 @@ extern "C"
|
||||
#define SPI_ENABLED 1
|
||||
#define SPI1_ENABLED 1
|
||||
#define SPI1_USE_EASY_DMA 1
|
||||
#define SPI2_ENABLED 1
|
||||
#define SPI2_USE_EASY_DMA 1
|
||||
#define SPI_DEFAULT_CONFIG_IRQ_PRIORITY 7
|
||||
#define NRFX_SPIM_MISO_PULL_CFG 3
|
||||
|
||||
|
||||
@@ -5,7 +5,12 @@
|
||||
#define SPI1_CLK_PIN NRF_GPIO_PIN_MAP(0, 13)
|
||||
#define SPI1_MOSI_PIN NRF_GPIO_PIN_MAP(0, 14)
|
||||
|
||||
#define SPI2_CLK_PIN NRF_GPIO_PIN_MAP(0, 12)
|
||||
#define SPI2_MOSI_PIN NRF_GPIO_PIN_MAP(0, 7)
|
||||
#define SPI2_MISO_PIN NRF_GPIO_PIN_MAP(1, 9)
|
||||
|
||||
static const nrf_drv_spi_t spim1 = NRF_DRV_SPI_INSTANCE(1); /**< SPI instance. */
|
||||
static const nrf_drv_spi_t spim2 = NRF_DRV_SPI_INSTANCE(2); /**< SPI instance. */
|
||||
|
||||
void spi_init(void)
|
||||
{
|
||||
@@ -17,6 +22,15 @@ void spi_init(void)
|
||||
spi1_config.mode = NRF_DRV_SPI_MODE_1;
|
||||
spi1_config.frequency = NRF_DRV_SPI_FREQ_1M;
|
||||
APP_ERROR_CHECK(nrf_drv_spi_init(&spim1, &spi1_config, NULL, NULL));
|
||||
|
||||
nrf_drv_spi_config_t spi2_config = NRF_DRV_SPI_DEFAULT_CONFIG;
|
||||
spi2_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
|
||||
spi2_config.miso_pin = SPI2_MISO_PIN;
|
||||
spi2_config.mosi_pin = SPI2_MOSI_PIN;
|
||||
spi2_config.sck_pin = SPI2_CLK_PIN;
|
||||
spi2_config.mode = NRF_DRV_SPI_MODE_1;
|
||||
spi2_config.frequency = NRF_DRV_SPI_FREQ_1M;
|
||||
APP_ERROR_CHECK(nrf_drv_spi_init(&spim2, &spi2_config, NULL, NULL));
|
||||
}
|
||||
|
||||
void spi1_write(uint8_t *p_tx_buffer, uint8_t tx_buffer_length)
|
||||
@@ -24,3 +38,27 @@ void spi1_write(uint8_t *p_tx_buffer, uint8_t tx_buffer_length)
|
||||
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spim1, p_tx_buffer, tx_buffer_length, NULL, 0));
|
||||
// NRF_LOG_HEXDUMP_INFO(p_tx_buffer, tx_buffer_length);
|
||||
}
|
||||
|
||||
static void virtual_data(uint8_t *p_rx_buf, uint8_t rx_buffer_length)
|
||||
{
|
||||
uint8_t virtual_data_buff[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
|
||||
if (rx_buffer_length == 0)
|
||||
return;
|
||||
|
||||
memcpy(p_rx_buf, virtual_data_buff, rx_buffer_length);
|
||||
}
|
||||
|
||||
void spi2_write(uint8_t *p_tx_buffer, uint8_t tx_buffer_length, uint8_t *p_rx_buf, uint8_t rx_buffer_length)
|
||||
{
|
||||
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spim2, p_tx_buffer, tx_buffer_length, p_rx_buf, rx_buffer_length));
|
||||
NRF_LOG_INFO("spi(W)");
|
||||
NRF_LOG_HEXDUMP_INFO(p_tx_buffer, tx_buffer_length);
|
||||
|
||||
// virtual_data(p_rx_buf, rx_buffer_length);
|
||||
|
||||
if (rx_buffer_length > 0)
|
||||
{
|
||||
NRF_LOG_INFO("spi(R)");
|
||||
NRF_LOG_HEXDUMP_INFO(p_rx_buf, rx_buffer_length);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user