Skip to main content
MFara.4
Associate III
December 9, 2022
Solved

I need to transmit my getting data from adc. But as I am very bigger I do not know how to do it, I would be happy if you take a look at my code in attachment and give me idea. Thanks

  • December 9, 2022
  • 1 reply
  • 5794 views

..

This topic has been closed for replies.
Best answer by Tesla DeLorean

Yes, syntax is wrong for HAL_UART_Transmit(), it wants a POINTER, and will send a pair of raw bytes over the wire. Will look like random junk bytes in a terminal application.

HAL_UART_Transmit(&huart1, (uint8_t *)&readValue, sizeof(readValue), 100);

for human readable numbers

char string[10];

HAL_UART_Transmit(&huart1, (uint8_t *)string, sprintf(string, "%d\n", readValue), 100);

Post code in-line via </> icon, screen shots are unhelpful

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
December 9, 2022

Yes, syntax is wrong for HAL_UART_Transmit(), it wants a POINTER, and will send a pair of raw bytes over the wire. Will look like random junk bytes in a terminal application.

HAL_UART_Transmit(&huart1, (uint8_t *)&readValue, sizeof(readValue), 100);

for human readable numbers

char string[10];

HAL_UART_Transmit(&huart1, (uint8_t *)string, sprintf(string, "%d\n", readValue), 100);

Post code in-line via </> icon, screen shots are unhelpful

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
MFara.4
MFara.4Author
Associate III
December 9, 2022

Thanks for the reply :folded_hands:

but again the problem is not solved!

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_ADC1_Init(void);

static void MX_USART1_UART_Init(void);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

uint16_t readValue;

char string[10];

/* USER CODE END 0 */

/**

 * @brief The application entry point.

 * @retval int

 */

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

 MX_ADC1_Init();

 MX_USART1_UART_Init();

 /* USER CODE BEGIN 2 */

 HAL_ADC_Start(&hadc1);

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

 HAL_ADC_PollForConversion(&hadc1,1000);

 readValue = HAL_ADC_GetValue(&hadc1);

 HAL_UART_Transmit(&huart1, (uint8_t *)&readValue, sizeof(readValue), 100);

Tesla DeLorean
Guru
December 9, 2022

>>but again the problem is not solved!

"The Problem" is ill defined.

No idea what board or chip you are using.

No idea how and to what the UART is configured and connected.

No idea what terminal app you have connected, what you are seeing, or what you expect to see.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..