int ADXL362_ReadZ(XSpi *spi_instance_ptr) { int rx; rx = ((ADXL362_ReadReg(spi_instance_ptr, ADXL362_ZDATA_H) & 0xFF) << 8) | (ADXL362_ReadReg(spi_instance_ptr, ADXL362_ZDATA_L) & 0xFF); return(rx); }
int ADXL362_ReadX(XSpi *spi_instance_ptr) { int rx; while(!ADXL362_IsDataReady(spi_instance_ptr)); rx = ((ADXL362_ReadReg(spi_instance_ptr,ADXL362_XDATA_H) & 0xFF) << 8) | (ADXL362_ReadReg(spi_instance_ptr,ADXL362_XDATA_L) & 0xFF); return(rx); }
/****************************************************************************** * @brief Read Z Axis 12 MSB. * * @param None. * * @return rx - read value. ******************************************************************************/ int ADXL362_ReadZ(void) { int rx; while(!ADXL362_IsDataReady()); rx = ((ADXL362_ReadReg(ADXL362_ZDATA_H) & 0xFF) << 8) | (ADXL362_ReadReg(ADXL362_ZDATA_L) & 0xFF); return(rx); }
/****************************************************************************** * @brief Reads temperature from ADXL362. * * @param None. * * @return Temperature value. ******************************************************************************/ int ADXL362_ReadTemp(void) { char temp[2] = {0x00, 0x00}; int result = 0; temp[0] = ADXL362_ReadReg(ADXL362_TEMP_H); temp[1] = ADXL362_ReadReg(ADXL362_TEMP_L); result = ((temp[0] & 0xFF) << 8) | ((temp[1]) & 0xFF); return(result); }
int ADXL362_ReadTemp(XSpi *spi_instance_ptr) { char temp[2] = {0x00, 0x00}; int result = 0; temp[0] = ADXL362_ReadReg(spi_instance_ptr,ADXL362_TEMP_H); temp[1] = ADXL362_ReadReg(spi_instance_ptr, ADXL362_TEMP_L); result = ((temp[0] & 0xFF) << 8) | ((temp[1]) & 0xFF); return(result); }
/****************************************************************************** * @brief Prints ADXL362 internal ID Registers. * * @param None. * * @return None. ******************************************************************************/ void ADXL362_PrintID(void) { xil_printf("\n\r"); xil_printf("Device ID: %x\n\r",ADXL362_ReadReg(ADXL362_DEVID_AD) & 0xFF); xil_printf("Device ID: %x\n\r",ADXL362_ReadReg(ADXL362_DEVID_MST) & 0xFF); xil_printf("Part ID: %x\n\r",ADXL362_ReadReg(ADXL362_PARTID) & 0xFF); xil_printf("Silicon ID: %x\n\r",ADXL362_ReadReg(ADXL362_REVID) & 0xFF); rxData = 0; xil_printf("\n\r"); ADXL362_DisplayMenu(); }
/****************************************************************************** * @brief Read Z Axis 8 MSB. * * @param None. * * @return rx - read value. ******************************************************************************/ char ADXL362_ReadZSmall(void) { char rx; while(!ADXL362_IsDataReady()); rx = ADXL362_ReadReg(ADXL362_ZDATA) & 0xFF; return(rx); }
/****************************************************************************** * @brief Checks if ADXL362 Conversion is complete. * * @param None. * * @return 1 - Data is ready, 0 - Data is not ready. ******************************************************************************/ char ADXL362_IsDataReady(void) { if((ADXL362_ReadReg(ADXL362_STATUS) & 0x01) == 0x01) { return(1); } else { return(0); } }
/****************************************************************************** * @brief Checks if ADXL362 Conversion is complete. * * @param None. * * @return 1 - Data is ready, 0 - Data is not ready. ******************************************************************************/ char ADXL362_IsDataReady(XSpi *SpiInstancePtr) { if((ADXL362_ReadReg(SpiInstancePtr, ADXL362_STATUS) & 0x01) == 0x01) { return(1); } else { return(0); } }
/****************************************************************************** * @brief Sets measurement range. * * @param None. * * @return None. ******************************************************************************/ void ADXL362_SetRange(void) { char rx = 0; char rxReg = 0; xil_printf("\n\r>Select measurement range: \n\r"); xil_printf(" [1] +/- 2g\n\r"); xil_printf(" [2] +/- 4g\n\r"); xil_printf(" [3] +/- 8g\n\r"); xil_printf("Press [1] to [3] to select desired range\n\r"); DisableInterrupts(UART_INTERRUPT); // Check if data is available on the UART rx = UartReadChar(); rxReg = (ADXL362_ReadReg(ADXL362_FILTER_CTL) & 0x3F); switch(rx) { case '1': rxReg = 0x00 | rxReg; xil_printf("> +/- 2g measurement range selected\n\r"); break; case '2': rxReg = 0x40 | rxReg; xil_printf("> +/- 4g measurement range selected\n\r"); break; case '3': rxReg = 0x80 | rxReg; xil_printf("> +/- 8g measurement range selected\n\r"); break; default: xil_printf("> wrong measurement range\n\r"); break; } ADXL362_WriteReg(ADXL362_FILTER_CTL, rxReg); EnableInterrupts(UART_INTERRUPT); rxData = 0; xil_printf("\n\r"); ADXL362_DisplayMenu(); }