AnsweredAssumed Answered

Interruption problem with SPI cubemx

Question asked by ENEDIS.ibrahim on Jul 11, 2016
Latest reply on Jul 12, 2016 by ForumSTM32.ForumSTM3
Hello,

I have a reception problem with SPI interruption, I only triggers once the interruption and my array is filled with this one character who repeats.. Thank you for your help.

main.c
/* Includes ------------------------------------------------------------------*/
#include "stm32l0xx_hal.h"
#include "spi.h"
#include "gpio.h"
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
 
uint8_t save_one_octet[1];
 
int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SPI1_Init();
 
  /* USER CODE BEGIN 2 */
  HAL_SPI_Receive_IT(&hspi1, (uint8_t *) save_one_octet, 1);
 
  while (1)
  {
  }
}

SPI.c
/* Includes ------------------------------------------------------------------*/
#include "spi.h"
#include "gpio.h"
 
extern uint8_t save_one_octet[1];
int count_buffer = 0;
uint8_t Save_Buffer[111];

void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi);
 
/* SPI1 init function */
void MX_SPI1_Init(void)
{
 
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_SLAVE;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 7;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    Error_Handler();
  }
}
 
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
    if(hspi->Instance == hspi1.Instance)
    {
        HAL_SPI_Receive_IT(&hspi1, (uint8_t *) save_one_octet, 1);
    }
    for(count_buffer = 0; count_buffer < 111; count_buffer++)
    {
       Save_buffer[count_buffer] = save_one_octet[0];
    }
}

Outcomes