cancel
Showing results for 
Search instead for 
Did you mean: 

Interruption problem with SPI cubemx

ibrahim
Associate II
Posted on July 11, 2016 at 17:18

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];
}
}

#spi #bug #stm32l0 #stm32cube
1 REPLY 1
slimen
Senior
Posted on July 12, 2016 at 17:04

Hi,

Your description here of the problem is not clear. What is the result that you expect ?

I recommned you to check the ''SPI'' example in the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubel0.html

and compare with your code and configuration to identify what is going wrong:

STM32Cube_FW_L0_V1.6.0\Projects\STM32L073Z_EVAL\Examples\SPI

Regards