Hello I'm using STM32L0538 - Disco board. I have problem with E-paper when on SMT32Cube program putting virtual port.
When I don't use virtual port E-paper working fine.
This is the code:
#include "stm32l0538_discovery_epd.h" #include "stm32l0538_discovery.h" #include "main.h" #include "stm32l0xx_hal.h" #include "usb_device.h" #include "usbd_cdc_if.h" ADC_HandleTypeDef hadc; DMA_HandleTypeDef hdma_adc; SPI_HandleTypeDef hspi1; UART_HandleTypeDef huart1; DMA_HandleTypeDef hdma_usart1_tx; float Voltage; int kazkas; uint8_t Mygtukas; float J_termoporos_temperatura, K_termoporos_temperatura; uint32_t ADC_Value; static uint8_t m[30], temp[30], volt[30], vidurk[30]; uint8_t ADC_flag = 0, Tx_flag = 0; uint32_t Dydis; uint8_t *psek, *pmin, *pval; uint32_t *ptime; uint8_t fifo_flag = 0; uint8_t alarm_flag = 0; float vidurkis = 0; float Temp_reiksmes[72]; int i,tt; struct { uint32_t laikas; uint8_t sekunde; uint8_t minute; uint8_t valanda; }Laikrodis; // void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_DMA_Init(void); static void MX_ADC_Init(void); static void MX_SPI1_Init(void); static void MX_USART1_UART_Init(void); void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma); void Termoporos_nustatymas_ir_isvedimas(void); void Itampos_nuskaitymas(ADC_HandleTypeDef* hadc); void Laikmatis(void); void FIFO_Buffer(void); void Alarmas (void); /* ADC veliavos nustatymas */ void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma) { ADC_flag = 1; } // float Funkcija_J_elemento (float itampa) { float y; itampa=(itampa-49)*3300/4096/219.2638997650744; if(itampa>=-8.095 && itampa<-3.786) { y=0.4834*(itampa*itampa*itampa)+6.3113*(itampa*itampa)+51.437*itampa+50.614; } if(itampa>-3.786 && itampa<=2.015) { y=0.0324*(itampa*itampa*itampa)-0.2351*(itampa*itampa)+19.79*itampa-0.0077; } if(itampa>2.015 && itampa<=6.360 ) { y=-0.1038*(itampa*itampa)+19.478*itampa+0.2907; } if(itampa>6.360 && itampa<=28.516) { y=18.069*itampa+5.1185; } if(itampa>28.516 && itampa<=41.645) { y=16.934*itampa+37.696; } return y; } // float Funkcija_K_elemento(float itampa){ float y; if( itampa>= -5.891 && itampa< -4.138) { y = -5.8222*(itampa*itampa) - 12.732*itampa - 72.182; } if( itampa>= -4.138 && itampa<= -2.243) { y = -1.3455*(itampa*itampa) + 23.031*itampa - 1.4361; } if( itampa> -2.243 && itampa<= 3.267) { y = -0.3113*(itampa*itampa) + 25.507*itampa - 0.1501; } if( itampa> 3.267 && itampa<= 15.554) { y = 24.38*itampa + 1.0481; } if( itampa> 15.554) { y = 23.566*itampa + 13.454; } return y; } // int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_DMA_Init(); MX_ADC_Init(); //MX_SPI1_Init(); MX_USART1_UART_Init(); MX_USB_DEVICE_Init(); //CDC_Init_FS(); BSP_EPD_Init(); // Initialize the EPD BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); psek = &Laikrodis.sekunde; pmin = &Laikrodis.minute; pval = &Laikrodis.valanda; ptime = &Laikrodis.laikas; *psek = 0; *pmin = 0; *pval = 0; while (1) { /* ADC veliavos nustatymas */ ADC_DMAConvCplt(&hdma_adc); if(tt% 4000 == 0) { Laikmatis(); Itampos_nuskaitymas(&hadc); Termoporos_nustatymas_ir_isvedimas(); FIFO_Buffer(); //CDC_Transmit_FS(temp, sizeof(temp)); //HAL_Delay(1000); BSP_EPD_Clear(EPD_COLOR_WHITE); BSP_EPD_DisplayStringAt(0,14, m, CENTER_MODE); BSP_EPD_DisplayStringAt(0,9, temp, LEFT_MODE); BSP_EPD_DisplayStringAt(0,5, volt, LEFT_MODE); Alarmas(); BSP_EPD_RefreshDisplay(); } } // end of while(1) } // end of main // void Termoporos_nustatymas_ir_isvedimas(void) { /* Mygtuko nuskaitymas */ if (BSP_PB_GetState(BUTTON_KEY) == 1) Mygtukas ++; //Nustatoma K termopora if(Mygtukas > 1) Mygtukas = 0; //Nustatoma J termopora switch(Mygtukas) { case 0: J_termoporos_temperatura = Funkcija_J_elemento(Voltage); sprintf((char*)m, "J termopora"); sprintf((char*)temp,"Temperatura yra %5.2f",J_termoporos_temperatura); sprintf((char*)volt,"Itampa yra %2.2f",Voltage); break; case 1: K_termoporos_temperatura = Funkcija_K_elemento(Voltage); sprintf((char*)m, "K termopora"); sprintf((char*)temp, "Temperatura yra %5.2f", K_termoporos_temperatura); sprintf((char*)volt,"Itampa yra %2.2f",Voltage); break; } } // void Itampos_nuskaitymas(ADC_HandleTypeDef* hadc) { if (ADC_flag == 1) { Dydis = sizeof(uint32_t); HAL_ADC_Start_DMA(hadc, (uint32_t*)&ADC_Value, Dydis); HAL_ADC_Stop_DMA(hadc); ADC_flag = 0; } Voltage = (ADC_Value); } // void Laikmatis(void) { if(*ptime >= 15) { *pmin += *ptime/15; *ptime = *ptime % 15; } if(*pmin >= 60) { *pval += *pmin/60; *pmin = *pmin % 60; } } // void FIFO_Buffer (void) { uint16_t suma = 0; uint16_t kiekis = 0; if(*pval >= 71) { fifo_flag = 1; *pval = 0; } else if(*pval < 72) { Temp_reiksmes[*pval] = J_termoporos_temperatura; suma = suma + J_termoporos_temperatura; kiekis++; vidurkis = suma / kiekis; } if(fifo_flag == 1) { for( i = 0; i < 72; i++ ) { Temp_reiksmes[i]=Temp_reiksmes[i+1]; } Temp_reiksmes[71] = J_termoporos_temperatura; suma = 0; for( i = 0; i < 72; i++ ) { suma = suma + Temp_reiksmes[i]; } vidurkis = suma / kiekis; } if(vidurkis<9.5) alarm_flag = 1; if(vidurkis >= 10.5) alarm_flag = 0; } // void Alarmas (void){ if (alarm_flag == 1){ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET); sprintf((char*)vidurk, "Vid. nukrito zemiau 9.5 C %5.2f", vidurkis); BSP_EPD_DisplayStringAt(0,1, vidurk, LEFT_MODE); } if (alarm_flag == 0){ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET); } } // void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; /**Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /**Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 16; RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4; RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USB; PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2; PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure the Systick interrupt time */ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); /**Configure the Systick */ HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); /* SysTick_IRQn interrupt configuration */ HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); } /* ADC init function */ static void MX_ADC_Init(void) { ADC_ChannelConfTypeDef sConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc.Instance = ADC1; hadc.Init.OversamplingMode = DISABLE; hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; hadc.Init.Resolution = ADC_RESOLUTION_12B; hadc.Init.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.ContinuousConvMode = DISABLE; hadc.Init.DiscontinuousConvMode = DISABLE; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc.Init.DMAContinuousRequests = DISABLE; hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV; hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED; hadc.Init.LowPowerAutoWait = DISABLE; hadc.Init.LowPowerFrequencyMode = DISABLE; hadc.Init.LowPowerAutoPowerOff = DISABLE; if (HAL_ADC_Init(&hadc) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_5; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /* SPI1 init function */ static void MX_SPI1_Init(void) { /* SPI1 parameter configuration*/ hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_MASTER; 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_HARD_INPUT; hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; 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(__FILE__, __LINE__); } } /* USART1 init function */ static void MX_USART1_UART_Init(void) { huart1.Instance = USART1; huart1.Init.BaudRate = 115200; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /** * Enable DMA controller clock */ static void MX_DMA_Init(void) { /* DMA controller clock enable */ __HAL_RCC_DMA1_CLK_ENABLE(); /* DMA interrupt init */ /* DMA1_Channel1_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); /* DMA1_Channel2_3_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn); } /** Configure pins as * Analog * Input * Output * EVENT_OUT * EXTI */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET); /*Configure GPIO pin : PB4 */ GPIO_InitStruct.Pin = GPIO_PIN_4; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @param None * @retval None */ void _Error_Handler(char * file, int line) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ while(1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Maybe somebody know the problem why E-paper is not working? It will be helpful.
Cube photo(Middleware):
Connectivity:
Hello, if you haven't already, I would recommend (also) posting to the STM32 forums, which would be a more focused audience for this question. Sorry, I have no experience with the e-paper you mention here.https://community.st.com/s/topic/0TO0X000000BSqSWAW/stm32-mcus
Thanks :)