可以的。在使用软件NSS时,需要在SPI初始化后调用SPI_DisableAutoSS()来禁用硬件自动NSS功能,并在需要进行NSS操作时,使用GPIO控制相应的NSS引脚输出高低电平。例如:
/* Disable the automatic hardware slave select function. */
SPI_DisableAutoSS(SPI0);
/* Set software NSS control mode. */
SPI_SET_SS0_HIGH(SPI0);
/* Start SPI transfer. */
SPI_WRITE_TX(SPI0, send_data);
while(!SPI_GET_TX_FIFO_EMPTY_FLAG(SPI0));
/* Set NSS pin to low. */
GPIO_SET_MODE(PB, BIT5, GPIO_MODE_OUTPUT);
GPIO_CLR_PIN(PB, BIT5);
/* Start SPI transfer with NSS controlled by software. */
SPI_SET_SS0_LOW(SPI0);
SPI_WRITE_TX(SPI0, send_data);
while(!SPI_GET_TX_FIFO_EMPTY_FLAG(SPI0));
/* Set NSS pin to high. */
SPI_SET_SS0_HIGH(SPI0);
GPIO_SET_PIN(PB, BIT5);
可以的。在使用软件NSS时,需要在SPI初始化后调用SPI_DisableAutoSS()来禁用硬件自动NSS功能,并在需要进行NSS操作时,使用GPIO控制相应的NSS引脚输出高低电平。例如:
/* Disable the automatic hardware slave select function. */
SPI_DisableAutoSS(SPI0);
/* Set software NSS control mode. */
SPI_SET_SS0_HIGH(SPI0);
/* Start SPI transfer. */
SPI_WRITE_TX(SPI0, send_data);
while(!SPI_GET_TX_FIFO_EMPTY_FLAG(SPI0));
/* Set NSS pin to low. */
GPIO_SET_MODE(PB, BIT5, GPIO_MODE_OUTPUT);
GPIO_CLR_PIN(PB, BIT5);
/* Start SPI transfer with NSS controlled by software. */
SPI_SET_SS0_LOW(SPI0);
SPI_WRITE_TX(SPI0, send_data);
while(!SPI_GET_TX_FIFO_EMPTY_FLAG(SPI0));
/* Set NSS pin to high. */
SPI_SET_SS0_HIGH(SPI0);
GPIO_SET_PIN(PB, BIT5);
举报