cancel
Showing results for 
Search instead for 
Did you mean: 

Control Pins and communicate via usart issue

FLine.1
Associate II

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();
 
}

0693W000006GtqXQAS.png 

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

22 REPLIES 22
zzzzz
Senior
  1. I don't see any reason you need that UART task. You can do everything in your button callbacks. If you have to do it that way, please suspend the UART task when doing string copy or use a semaphore.
  2. You are not coded as I suggested, string.h is C header, need to move it to extern C. I see the whole extern c is commented out, have a problem to use it?
  3. How's your debug? As I said before, Is UART transmit function get called? if so, what data in the buffer?

I just reviewed your code, my code would like this:

  1. #include <gui/screen1_screen/Screen1View.hpp>
  2.  
  3. extern "C"
  4. {
  5. #include "stm32f7xx_hal.h"
  6. #include "main.h" // add extern UART_HandleTypeDef huart2 and extern char giden[10] to main.h
  7. #include "string"
  8. }
  9.  
  10. void Screen1View::basla()
  11. {
  12. strcpy(giden, "basla\n\r");
  13. HAL_UART_Transmit(&huart2, (uint8_t *)giden, 10 ,30);
  14. //btnBasla.invalidate(); // don't need this funciton
  15.  
  16. }

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:

  1. void Screen1View::basla()
  2. {
  3. HAL_UART_Transmit(&huart2, (uint8_t *)"basla\n\r", 10 ,30);
  4. }

@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.

FLine.1
Associate II

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();
}

 0693W000006HLQrQAO.jpg

FLine.1
Associate II

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 */
}

0693W000006HLRBQA4.jpg

FLine.1
Associate II

0693W000006HLRLQA4.png

MM..1
Chief II

Seems you have converter, but scope ?

FLine.1
Associate II

Arduino:

0693W000006HLSTQA4.jpgSTM:

0693W000006HLSYQA4.jpg

Maybe i dont understand your photo, but where you have touchGFX display and where you click ?

FLine.1
Associate II

I click Basla Button.0693W000006HLUPQA4.jpg