2016-07-11 08:18 AM
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
2016-07-12 08:04 AM
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 and compare with your code and configuration to identify what is going wrong:STM32Cube_FW_L0_V1.6.0\Projects\STM32L073Z_EVAL\Examples\SPIRegards