SPI

SPI通信中,STM32单片机做从机,能进入接收中断,但是接收buffer中的数据是0

#include "main.h"

#include "spi.h"

#include "usart.h"

#include "gpio.h"


/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

#include <stdio.h>

/* USER CODE END Includes */


/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */


/* USER CODE END PTD */


/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

uint8_t receive[1];

uint8_t receBuff[4096];

uint8_t RX_STA = 0;

/* USER CODE END PD */


/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */


/* USER CODE END PM */


/* Private variables ---------------------------------------------------------*/


/* USER CODE BEGIN PV */


/* USER CODE END PV */


/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

/* USER CODE BEGIN PFP */


/* USER CODE END PFP */


/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */


void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)  //能进入这个回调函数,但是receive这个buffer中数据是0

{

   if(hspi->Instance==SPI1)

  {

    receBuff[RX_STA] = receive[0];

    RX_STA++;

  }

  printf("success into receive it\n"); 

}


/* USER CODE END 0 */


/**

  * @brief  The application entry point.

  * @retval int

  */

int main(void)

{

  /* USER CODE BEGIN 1 */

  uint8_t printData[] = {0X55,0X05};

  uint8_t cut = 0;

  /* 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_USART1_UART_Init();

  MX_SPI1_Init();

  /* USER CODE BEGIN 2 */

HAL_SPI_Receive_IT(&hspi1, receive, 1);


已邀请:

要回复问题请先登录注册