/****************************************************************************** * @brief Displays read axis data 12 MSB. * * @param axis - which data to display. * * @return None. ******************************************************************************/ void ADXL362_Print(char axis) { int rxG = 0; char sign = 0; float value = 0; int whole = 0; int thousands = 0; switch(axis) { case 'x': rxG = ADXL362_ReadX(); xil_printf("X = "); break; case 'y': rxG = ADXL362_ReadY(); xil_printf("Y = "); break; case 'z': rxG = ADXL362_ReadZ(); xil_printf("Z = "); break; default: break; } // Sign is MSB. If 1 -> Negative Number, else Positive Number sign = (rxG & 0x800) >> 11; if (sign == 1) { // If negative number, padding with FFFFF MSB's rxG = rxG | 0xFFFFF000; } else { rxG = rxG | 0x00000000; } value = ((float)rxG / 1000); if(rxG >= 0) { whole = value; thousands = (value - whole) * 1000; } else { value = value * (-1); whole = value; thousands = (value - whole) * 1000; } ADXL362_Display(whole, thousands, sign, 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; }