1. 程式人生 > >STM32cudemx SPI通訊 OLED顯示

STM32cudemx SPI通訊 OLED顯示

I decide to write my blog in English because I have been preparing my IELTS test. I think it will not be difficult for you to understand because my English level is not pretty good. So please just ignore my grammar error and pay attention to what meaning I am going to convey. 

Well,let's go to the topic.

Today I want to show you how to transplant the OLED program from standard library into HAL library with STM32cudemx.Here are the files you can download from my CSDN:https://download.csdn.net/download/weixin_41892263/10704697 before you start your job.

OK,keep patient and just follow me:

NO.1:generate a new project with STM32cudemx, the parameter should be set as following:

you don't need to care about SPI1 or SPI2 from the picture, for we are not going to control the SPI in hardware way,on the contrary,we control it in the solfware way, that is why you need to download the files which need to be transplanted. Let me tell you more exactly, you just need to set GPIO_output among all of pins no matter which type your STM32 is. if only there are enough GPIO for output then it is OK to start your job. Then you can generate your files.

NO.2 transplant the program

After download the files you can see the catalogue like this:

Firstly,copy the file 'OLED' to the location of your project then add group to your project in MDK,and don't forget to reset the include path.

            

NO.3 change the pin in mxconstants.h according to your GPIO setting

for example,if your connection is  like this:

D0       D1      RST   DC    CS

PA5   PA7     PB0    PB1  PA4

then you just need to change the define in file mxconstants.h as the picture show you.

NO.4 write the main function:

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* 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();
	OLED_Init();
  /* USER CODE BEGIN 2 */
		OLED_Clear();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
		
	//	LED_ON;
		OLED_ShowCHinese(0,0,0);//中
		OLED_ShowCHinese(18,0,1);//景
		OLED_ShowCHinese(36,0,2);//園
		OLED_ShowCHinese(54,0,3);//電
		OLED_ShowCHinese(72,0,4);//子
		OLED_ShowCHinese(90,0,5);//科
		OLED_ShowCHinese(108,0,6);//技
		
  }
  /* USER CODE END 3 */

}

then you can see your OLED display '中景園電子科技' :

寫英語寫得太沒感覺了寫得官方正式完全表達不出我興奮和喜悅的心情大家也沒體會到博主是一個多麼熱情的人。。。哈哈哈哈哈哈哈覺得OK就點個贊吧謝謝謝謝。