cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 F767ZI: How to read an external ADC and print the result

CEaso
Associate

Hello,

I am using the stm32 F767ZI development board for a project. This is my first time using this board and only my second time working with an MCU in general. The software I am using is CubeMX and Attollic Truestudio.

My current goal is to read data from an external 8 bit ADC. The data is ready on the rising edge of the CLK. So far I have used cubemx to configure pins PD0-PD7 as GPIO inputs and PA0 as an external interrupt with rising edge detection.

Now that I have the software generated code I am completely lost as to where to start.

Where do I write the code to read the inputs, inside the interrupt? In Main.c?

And what is the syntax for reading data from a specific port?

Finally, if I am able to successfully read the data. How can I display or print it to verify that it is reading it? The simple printf function does not seem to work with this software.

2 REPLIES 2

I'd just read it in the interrupt, and then clear the EXTI

uint16_t foo = GPIOD->IDR & 0xFF;

__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);

You could use the HAL callback method, but frankly too much of a circus for my liking.

Afraid I'm not using CubeMX or Atollic, but the printf() stuff comes up occasionally on the forum. Might be some check box items for the libraries, support for _write() in syscalls.c or __io_putchar()

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

Alternatively, you could either verify a few cases (ADC input voltages) with the debugger and a breakpoint.

Or printf() the ADC value into a string, and transmit it via UART, which is more portable across platforms and toolchains.

Avoid printf() or similar "heavy" functions inside interrupts, it will eventually break your code.