1.2K
#include "main.h" #include "LiquidCrystal.h" uint8_t rxBuffer; char RX1[20]; char RX2[20]; int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_DMA_Init(); MX_SPI1_Init(); LiquidCrystal(GPIOB,GPIO_PIN_9,GPIO_PIN_10,GPIO_PIN_11,GPIO_PIN_12, GPIO_PIN_13,GPIO_PIN_14,GPIO_PIN_15); begin(16,2); while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ // Receive Polling MODE if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5)==GPIO_PIN_SET) { HAL_SPI_Receive(&hspi1, (uint8_t*)RX1, sizeof(RX1),5000); setCursor(0, 0); print("SPI Polling Mode"); setCursor(0, 1); print(RX1); HAL_Delay(1000); clear(); } //Receive IT MODE else if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)==GPIO_PIN_SET) { HAL_SPI_Receive_IT(&hspi1, &rxBuffer, 1); setCursor(0, 0); print("SPI IT Mode"); HAL_Delay(1000); clear(); } else if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7)==GPIO_PIN_SET) { HAL_SPI_Receive_DMA(&hspi1, (uint8_t*)RX2,sizeof(RX2)); setCursor(0, 0); print("SPI DMA Mode"); setCursor(0, 1); print(RX2); HAL_Delay(1000); clear(); } else { setCursor(0, 0); print("SLAVE Ready"); setCursor(0, 1); print("TO Receive"); HAL_SPI_Abort(&hspi1); HAL_SPI_Abort_IT(&hspi1); HAL_SPI_DMAStop(&hspi1); HAL_Delay(1000); clear(); }}}