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:

copy the files 'OLED' and 'gpio' 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就点个赞吧谢谢谢谢。

猜你喜欢

转载自blog.csdn.net/weixin_41892263/article/details/82960071