2020-12-25 04:08 AM
Helleo,
I am newbie in Touchgfx and I try developing first project.
I am willing to data transfer stm32746 to pc via usart and control pins.
When I click the button stm doesnt send data via usart or stm doesnt control pins.
Screen1View.cpp codes:
#include <gui/screen1_screen/Screen1View.hpp>
#include "stm32f7xx_hal.h"
extern UART_HandleTypeDef huart2;
Screen1View::Screen1View()
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::led_on()
{
/* HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_2|GPIO_PIN_5
|GPIO_PIN_3, GPIO_PIN_SET);
*/
//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_5);
//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_6);
// textArea1.setVisible(true);
char com_cevap[12] ="adc_veri\r\n ";
HAL_UART_Transmit(&huart2, (uint8_t *) &com_cevap, 12, 200);
btndurum.setAlpha(254);
btndurum.invalidate();
}
void Screen1View::led_off()
{
/* HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_2|GPIO_PIN_5
|GPIO_PIN_3, GPIO_PIN_RESET);
*/
//HAL_GPIO_WritePin(GPIOD, GPIO_PIN_5, GPIO_PIN_RESET);
//HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_RESET);
btndurum.setAlpha(50);
btndurum.invalidate();
}
please tell me whats wrong? Could i control pins or data transfer in button click?
I use STMCubeIDe 1.5.1, Visual Studio 2019 and last framework.TouchGfx 4.15
Solved! Go to Solution.
2021-01-03 06:16 AM
2021-01-03 06:36 AM
I just reviewed your code, my code would like this:
This shows how to use a buffer created in C file in Cpp file. Anything you created in C file, you need put them in extern C when you try using them in Cpp.
In your case, code in button callback could be as simple as this:
2021-01-03 07:03 AM
@zzzzz Yes this work too, but only for short strings for example on 115200 to 100 chars. Then with bigger data you need task.
@FLine.1
And i see you maybe have problem on PC COM port , not in your code.
Please check with scope connected to TX signal.
And for connect to PC you need converting 3,3V TTL to RS232 . You cant connect directly. Plus your PC COM software must be properly set.
2021-01-03 08:19 AM
Mr zzzz
Thank you for reply. it is crazy me.
I debug project STM32CubeIDE 1.5.1 . I suspend this tiime but result is same.
What do you mean UART transmit function callback?
If you have time you can remote connection my pc with anydesk. Anydesk number:205 312 968
I liked that last one: main.c
/* USER CODE END Header_StartTask_Uart */
void StartTask_Uart(void const * argument)
{
/* USER CODE BEGIN StartTask_Uart */
/* Infinite loop */
for(;;)
{
if (giden[0] != 0) {//icinde deger varsa
HAL_UART_Transmit_IT(&huart2, (uint8_t *)giden, 10 );
giden[0] = 0;
}
osDelay(1000);
}
/* USER CODE END StartTask_Uart */
}
screenview.cpp:
#include <gui/screen1_screen/Screen1View.hpp>
extern "C"
{
#include "main.h"
#include "stm32f7xx_hal.h"
#include "cmsis_os.h"
UART_HandleTypeDef huart2;
#include "string.h"
osThreadId Task_UartHandle;
//osThreadDef(Task_Uart, StartTask_Uart, osPriorityHigh, 0, 128);
}
extern char giden[];
Screen1View::Screen1View()
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::basla()
{
osThreadSuspend(Task_UartHandle); //Task_UartHandle
strcpy(giden, "basla\n\r");
btnBasla.invalidate();
osThreadResume(Task_UartHandle);
}
void Screen1View::bitir()
{
if (giden[0] == 0) {
strcpy(giden, "durdu\n\r");
}
btn_bitir.invalidate();
}
2021-01-03 08:26 AM
Hello
I changed code like that but result is same.
It is crazy me. I suspend and resume task this time.
If you have time you can remote desktop my pc via Any desk :205 312 968
#include <gui/screen1_screen/Screen1View.hpp>
extern "C"
{
#include "main.h"
#include "stm32f7xx_hal.h"
#include "cmsis_os.h"
UART_HandleTypeDef huart2;
#include "string.h"
osThreadId Task_UartHandle;
//osThreadDef(Task_Uart, StartTask_Uart, osPriorityHigh, 0, 128);
}
extern char giden[];
Screen1View::Screen1View()
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::basla()
{
osThreadSuspend(Task_UartHandle); //Task_UartHandle
strcpy(giden, "basla\n\r");
btnBasla.invalidate();
osThreadResume(Task_UartHandle);
}
void Screen1View::bitir()
{
if (giden[0] == 0) {
strcpy(giden, "durdu\n\r");
}
btn_bitir.invalidate();
}
/* USER CODE END Header_StartTask_Uart */
void StartTask_Uart(void const * argument)
{
/* USER CODE BEGIN StartTask_Uart */
/* Infinite loop */
for(;;)
{
if (giden[0] != 0) {//icinde deger varsa
HAL_UART_Transmit_IT(&huart2, (uint8_t *)giden, 10 );
giden[0] = 0;
}
osDelay(1000);
}
/* USER CODE END StartTask_Uart */
}
2021-01-03 08:31 AM
2021-01-03 08:36 AM
Seems you have converter, but scope ?
2021-01-03 08:51 AM
Arduino:
STM:
2021-01-03 09:09 AM
Maybe i dont understand your photo, but where you have touchGFX display and where you click ?
2021-01-03 09:17 AM
I click Basla Button.