This describes how to take the AD7124 example code and integrate it with STM32 firmware libraries in a suitable development environment to produce a complete program. The IDE used here is the STM32CubeIDE, but the general procedure can be applied to other IDEs.
The AD7124 is a low power, low noise, completely integrated analog front end for high precision measurement applications. The device contains a low noise, 24-bit Σ-Δ analog-to-digital converter (ADC). The AD7124 example application provides a terminal based console interface that allows a user to select between different configurations, and to sample data in single or continuous conversion modes.
The example makes use of the AD7124 No-OS software drivers and platform drivers that are using the STM32 HAL firmware libraries.
The Device Configuration Tool with automatic code generation is used to define pin usage and other default modes of operation for the NUCLEO-L476. In addition there are some build and linker settings that may be required depending on the default project build configuration.
A 4-wire SPI bus is used to connect AD7124 to the NUCLEO-L476RG board, and a UART is used to provide the serial I/O for the console interface. An LED is also used to indicate activity. The following sections detail the configuration settings that need to be made for each of these.
SPI1 port on the processor is used to communicate with the AD7124, with the pin assigned to each function as shown here, with the corresponding label.
The pin PB10 is used as a software controlled chips select for SP1, and so its mode must be set to GPIO_output, and set the user label to SPI1_NSS to match what is used in the platform driver file. The Connectivity » SPI1 configuration settings are shown here.
DMA and interrupts are not used and don't need to be configured. The SPI1 GPIO Settings are as follows.
The serial port uses USART2, and no DMA or interrupts need to be configured.
The USART2 GPIO settings are as shown.
An LED is toggled on the NUCLEO-L476 board to indicate sampling and other activity. The activity LED is controlled by Port A, Pin 5, and needs to enabled as digital output to support this function.
The printf(…) function is used to print numbers formatted as floating point values in the terminal view. As this feature is often disabled by default due to the additional memory requirement, floating point support in printf(…) must be enabled. In the Project properties window, under 'C/C++ Build » Settings » MCU GCC linker » Miscellaneous > Other Flags' add a '-u _printf_float' option.
If there are other source or include directories that need to be added to support the project build, they should also be added to the relevant 'Include paths' in the MCU GCC Compiler section as required.
The default value for _estack may be incorrect in the *.ld files. This can cause problems when calling into certain library functions. In particular this can prevent the %f format specifier working with the floating point version of printf(…). If instead of a value like '1.23', the terminal output is '0.00', this can indicate a need to update the linker *.ld files. For the NUCLEO-L476RG, the RAM and the FLASH versions of the ld files contain the following:
/* Highest address of the user mode stack */ _estack = 0x20017fff; /* end of "RAM" Ram type memory */
Changing this as follows fixes the issues related to floating point support in printf:
/* Highest address of the user mode stack */ _estack = 0x20018000; /* end of "RAM" Ram type memory */
When using the Device Configuration Tool, the code generator produces a two of these source files, main.c and main.h need minor edits to integrate the AD7124 example code. There may be an edit required to the _read(…) function in syscalls.c to work around an issue, but whether this is required, will depend on the specific library and build environment.
To keep the integration of the AD7124 example application with other user and platform specific code, there are only two functions that a user needs to call from their own code, typically as part of the main function.
/* Initialize the AD7124 application before the main loop */ int32_t setupResult; if ((setupResult = ad7124_app_initialize(AD7124_CONFIG_A)) < 0 ) { // Handle error setting up AD7124 here }
while(1) { // display the console menu for the AD7124 application adi_do_console_menu(&ad7124_main_menu); }
Both are defined in the “ad7124_console_app.h” header which needs to be added as #include file.
The AD7124 example assumes that all the STM32 hardware is initialized and appropriate SPI and UART port handles are available, and are used in platform_drivers.c and platform_support.c. The following extern declarations for the SPI and serial port handles are required in main.h to make them available to the platform specific code.
extern SPI_HandleTypeDef hspi1; extern UART_HandleTypeDef huart2;
In the _read(…) function, the 'len' parameter passed in was found to always be '1024' for the library and build environment used to develop the example code.
int _read(int file, char *ptr, int len)
In order to support the use of getchar(), the expression 'len = 1;' was added immediately before the for loop in the _read(…) function. While this is sufficient for getchar() to work, it does not support use of other stdio.h functions such as scanf(…).
The distribution of the AD7124 source and header files can be added to the project that has been created. The files can be added in a dedicated 'adi' directory, or in the main 'src' directory, or split as appropriate between 'src' and 'inc' directories, according to the file structure being used. If adding new source and header file locations, then these will need to be added to the build settings as necessary, in the relevant 'Include paths' in the MCU GCC Compiler configuration.
At this point, assuming that any necessary changes, pin names, port usage/configuration have been made, the project should compile cleanly.
A 9V DC supply (barrel jack, center pin positive) is required to power the EVAl-AD7124-8SDZ evaluation board. The NUCLEO-476RG is powered via the USB connection to the PC, which also provides the serial UART connection back to the PC. The NUCLEO-476 creates a COM port that can be connected to by a terminal emulator, e.g. putty.
SPI connections to the host processor board can be made to the relevant test points on the eval board, or more easily with an SDP Breakout Board.
AD7124 SPI Signal | SDP Breakout Board | NUCLEO-L476 |
---|---|---|
GND | 81 | GND on CN5.7 |
SCLK | 82 | D3 (PB3) on CN9.4 |
DOUT/RDYB | 83 | D5 (PB4) on CN9.6 |
DIN | 84 | D4 (PB5) on CN9.5 |
CSB | 85 | D6 (PB10) on CN9.7 |
The screw terminal connections to J6 and J11 can be used to connect appropriate analog input signals to provide test stimulus to the AD7124.
In Configuration A
In Configuration B
Once the hardware connections are made, and the compiled code programmed into the board, open the terminal program, and reset the hardware to see the AD7124 menu that allows a user to perform a variety of functions. These include reset the device, program one of the pre-defined configurations, and sample data that is displayed on screen or streamed so it can captured by the console.
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !