/***************************************************************************//** * @brief Initializes the device. * * @return - The result of the initialization. * Example: ERROR - the device was not initialized or the device * is not present. * SUCCES - the device was initialized and the device * is present. *******************************************************************************/ char DoDeviceInit(void) { if(ADXL362_Init() == 0) { CONSOLE_Print("ADXL362 OK\r\n"); GetHelp(NULL, 0); return SUCCESS; } else { CONSOLE_Print("ADXL362 Error\r\n"); return ERROR; } }
/****************************************************************************** * @brief Main function. * * @return Always returns 0. ******************************************************************************/ int main(void) { // Configure system SystemConfiguration(); // Configure SPI SPI_Init(SPI_BASEADDR, 0, 0, 0); // Initialize Interrupts InterruptsInit(); // Initialize ADXL362 ADXL362_Init(); // Run demo program DemoProgram(); return(0); }
/** * * This function does a minimal test on the Spi device and driver as a * design example. The purpose of this function is to illustrate how to use * the XSpi component using the polled mode. * * This function sends data and expects to receive the same data. * * * @param SpiInstancePtr is a pointer to the instance of Spi component. * @param SpiDeviceId is the Device ID of the Spi Device and is the * XPAR_<SPI_instance>_DEVICE_ID value from xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note * * This function contains an infinite loop such that if the Spi device is not * working it may never return. * ******************************************************************************/ int SpiPolledExample(XSpi *SpiInstancePtr, u16 SpiDeviceId) { int Status; u32 Count; XSpi_Config *ConfigPtr; /* Pointer to Configuration data */ /* * Initialize the SPI driver so that it is ready to use. */ ConfigPtr = XSpi_LookupConfig(SpiDeviceId); if (ConfigPtr == NULL) { return XST_DEVICE_NOT_FOUND; } Status = XSpi_CfgInitialize(SpiInstancePtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XSpi_SelfTest(SpiInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Run loopback test only in case of standard SPI mode. */ if (SpiInstancePtr->SpiMode != XSP_STANDARD_MODE) { return XST_SUCCESS; } /* * Set the Spi device as a master and in loopback mode. */ Status = XSpi_SetOptions(SpiInstancePtr, XSP_MASTER_OPTION | XSP_MANUAL_SSELECT_OPTION); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the SPI driver so that the device is enabled. */ XSpi_Start(SpiInstancePtr); /* * Disable Global interrupt to use polled mode operation */ XSpi_IntrGlobalDisable(SpiInstancePtr); /* * Initialize the write buffer with pattern to write, initialize the * read buffer to zero so it can be verified after the read, the * Test value that is added to the unique value allows the value to be * changed in a debug environment. */ /* * Transmit the data. */ /*Init ADCL*/ SpiInstancePtr->SlaveSelectReg = 0x00000000; ADXL362_Init(SpiInstancePtr); DelayMs(1); while(1) { int x = 0, y=0, z=0, temp; x= ADXL362_ReadX(SpiInstancePtr); y= ADXL362_ReadY(SpiInstancePtr); z= ADXL362_ReadZ(SpiInstancePtr); temp = ADXL362_ReadTemp(SpiInstancePtr); DelayMs(5); xil_printf("X: %d\r\n", x); xil_printf("Y: %d\r\n", y); xil_printf("Z: %d\r\n", z); xil_printf("temperature: %d\r\n", temp); } SpiInstancePtr->SlaveSelectReg = 0x0000001; return XST_SUCCESS; }