cancel
Showing results for 
Search instead for 
Did you mean: 

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

MFara.4
Associate III
 
1 ACCEPTED SOLUTION

Accepted Solutions

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

9 REPLIES 9

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for the reply 🙏

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

>>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 Venmo
Up vote any posts that you find helpful, it shows what's working..

Try paste here red console log complete not as screenshot. Seems error on board connection....

I use stm32G01291 and CubeIDE

Actually I am a data scientist and just want to get data from ADC and transmit it to python in order to some analysis and ML algorithms!

I used for configuration like this:

ADC1 - IN9 (tick)

Parameter Settings --> ADC Settings --> Continuous Conversion Mode (Enabled)

Enable USART1 asynchronous

Parameter Settings --> Basic Parameters --> Baud rate 9600

Actually codes work now I can see the readValue in live Expression but I am not sure that I can get from serial on the python too! do you think is it enough writing code

for USRAT1 transmit by USB?

Thanks for looking at my problem!

Yes that's another interesting issue although my code looks work properly! but if you have idea about this red console I would be happy that you share with me.

I attached the reading of console.

Seems you are on linux and OCD. For UART to USB you need VCP ...

Too stm32G01291  dont exist

Start any request here with board name or custom.

Thanks again for the reply!

I solved the problem it was related to debugging. I use macOS.