Example program for EVAL-ADMX2001
Dependencies: ADMX2001
Diff: main.cpp
- Revision:
- 8:bd0b93e35392
- Parent:
- 5:746e78113d7d
- Child:
- 9:29db35656fcb
--- a/main.cpp Wed Oct 27 07:36:33 2021 +0000 +++ b/main.cpp Wed Oct 27 21:18:12 2021 +0000 @@ -50,13 +50,21 @@ #include <stdio.h> #include <stdlib.h> -/** This is kept global and non-static because as test codes require this*/ +/** This is kept global and non-static as test code requires this*/ Admx200xDev admx200xDev; static int32_t SPIInit(spi_desc **pSpiDesc); +static int32_t ResetModule(); + /** - * Function to initialize SPI + * + */ + /** + * @brief Function to initialize SPI + * + * @param pSpiDesc - Pointer to the spi descriptor + * @return Returns 0 for success or error code. */ int32_t SPIInit(spi_desc **pSpiDesc) { @@ -80,21 +88,23 @@ } /** - * @brief Measures Impedance - * \ref CmdZ + * Resets measurement */ -int32_t CmdZ() +int32_t ResetModule() { - int32_t status = ADMX_STATUS_SUCCESS; - - status = TriggerAndMeasure(); + int32_t status = 0; + uint8_t cmdId; + uint16_t addr; + uint32_t data; + uint32_t statReg; - PrintMeasureStatusMessage(status); + Admx200xDev *pAdmx200x = &admx200xDev; - if (status != ADMX_STATUS_SUCCESS) - { - status = ADMX_STATUS_FAILED; - } + /* Send reset command */ + cmdId = CMD_RESET; + addr = 0; + data = 0; + status = Admx200xSendCmd(pAdmx200x, &cmdId, &addr, &data, &statReg); return status; } @@ -116,21 +126,35 @@ /* Initialize the ADMX200x application */ if (status != 0) { - printf("Error setting up ADMX200X \r\n\r\n"); + ERROR_MSG("Setting up ADMX200X failed"); } else { - printf("Setting test load to 1k ohms\r\n"); - EnableMuxLine(2); - printf("Starting measurement commands\r\n"); - CmdZ(); - printf("Measurement completed\r\n"); - printf("Setting test load to short\r\n"); - EnableMuxLine(0); - printf("Starting Calibration\r\n"); - calType = CAL_TYPE_OPEN; - status = Calibrate(calType, stdLoad, Xt); - printf("Calibration completed\r\n"); + INFO_MSG("Resetting module"); + status = ResetModule(); + if (status != ADMX_STATUS_SUCCESS) + { + ERROR_MSG("Failed to reset module"); + } + else + { + INFO_MSG("------ Initialising measurement ------"); + INFO_MSG("Setting test load to 1k ohms"); + // Selects test load 3 - 1000 ohm resistor + EnableMuxLine(3); + // Performing measurement + status = MeasureAndDisplay(); + INFO_MSG("------ Measurement completed ------"); + + INFO_MSG("------ Starting Calibration ------"); + INFO_MSG("Setting test load to open circuit"); + // Open the terminals across the lcr meter + EnableMuxLine(0); + // Running open calibration + calType = CAL_TYPE_OPEN; + status = Calibrate(calType, stdLoad, Xt); + INFO_MSG("------ Calibration completed ------"); + } } status = spi_remove(pSpi);