SPI2 global interrupt routine does not get fired upon transmission complete
Hello,
I'm trying to do a project which involves using both UART and SPI to better understand these protocols as well as the HAL drivers.
I have generated the project with the cubeMX and for the first step I'm trying to send some data via SPI2 in interrupt mode when I press a button.
The code logic is like this: The program cyclicly checks in an endless while loop whether I press the user button or not. If I do it's going to start the process of sending some data via SPI in interrupt mode.
I have configured my controller on the board(NUCLEO F401RE) in master full-duplex but I have not connected any cables to any other device/board yet as I just want to test the sending in interrupt mode first.
I put some code which lights up the user LED in the 'SPI2_IRQHandler'(global interrupt that should be fired when transmission is completed if I understood corectly from the datasheet) if which in turn calls HAL function 'HAL_SPI_IRQHandler' which takes care of clearing flags etc.
void SPI2_IRQHandler(void)
{
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
HAL_SPI_IRQHandler(&hspi2);
}The above function is in the 'stm32f4xx_it.c' generated by cubeMX.
The configuration(generated from cubeMX) is like this:
- Motorola Frame Format
- 8 bits data size
- MSB first
- 2 prescaler for baud rate
- clock polarity CPOL
- Clock Phase CPHA
- CRC calculation disabled
- NSS Signal Type SOFTWARE
- Device configured as SPI master full-duplex
This is the main code:
char* data_to_sent = "a";
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI2_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
SPI2->CR1 |= ( 1 << 8 ); //NSS high
//HAL_SPI_Transmit_IT(&hspi2, (uint8_t*)data_to_sent, 1);
while (1)
{
if( HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin) == 0 )
{
//Send the command in SPI interrupt mode
HAL_SPI_Transmit_IT(&hspi2, (uint8_t*)data_to_sent, 1);
}
}
}The code gets into the 'HAL_SPI_Transmit_IT' and seems to be doing everything fine but the interrupt routine does not get fired.
However the SPI2 isr routine does not get called(the led does not light up).
I have configured the NSS signal type to be controlled in software. So I have also tried doing this in the code:
SPI1->CR1 |= ( 1 << 8 );
Because if I understood corectly in the datasheet this bit has to be 1 when NSS is controlled in software in order for the SPI to generate clock(and send data properly) and I did not find anything in the generated code where that is done. However it did not change anything.
Please help me fix this issue. Thanks for reading my post!
Edit: Added the code which I forgot. Also changed the title and the explanation as the previous problem was solved(SPI was busy due to me a hex address instead of the address of the SPI handle) and now there is a new problem in the code(ISR does not get triggered).
