Question
SPI Software Chip Select
Posted on February 14, 2015 at 13:46
What is the best way to implement chip select in software? I've tried doing it this way:
HAL_GPIO_WritePin(NSS_PORT, NSS_PIN, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, out , 1); HAL_GPIO_WritePin(NSS_PORT, NSS_PIN, GPIO_PIN_SET); But the problem is that HAL_SPI_Transmit() exits before data is actually physically sent. I've also tried using interrupts:HAL_GPIO_WritePin(NSS_PORT, NSS_PIN, GPIO_PIN_RESET);
HAL_SPI_Transmit_IT(&hspi1, out , 1);static
void SPI_TxISR_8BIT( struct __SPI_HandleTypeDef *hspi) { *(__IO uint8_t *)&hspi->Instance->DR = (*hspi->pTxBuffPtr++); hspi->TxXferCount--; if (hspi->TxXferCount == 0) { if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLED) { /* Enable CRC Transmission */ hspi->Instance->CR1 |= SPI_CR1_CRCNEXT; } SPI_CloseTx_ISR(hspi); HAL_GPIO_WritePin(NSS_PORT, NSS_PIN, GPIO_PIN_SET); } } But it has the same problem - interrupt occurs way before data is actually sent. Another downside here is that I'm modifying a library file, something I probably should be doing. #interrups #stm32 #spi #nss