/****************************************************************************** * @brief Displays read temperature from ADXL362. * * @param None. * * @return None. ******************************************************************************/ void ADXL362_PrintTemp(void) { float value = 0; int rxTemp = 0; char sign = 0; int whole = 0; int thousands = 0; rxTemp = ADXL362_ReadTemp(); value = (float)((rxTemp & 0x7FF) * 0.065); sign = (rxTemp & 0x800) >> 11; whole = value; thousands = (value - whole) * 1000; xil_printf("\n\rADXL362 Temperature is: "); ADXL362_Display(whole, thousands, sign, 1); //xil_printf("\n\r"); rxData = 0; xil_printf("\n\r"); ADXL362_DisplayMenu(); }
/** * * 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; }