In this tutorial, we will guide you through the process of interfacing the LMS6DSL Click Mezzanine with the Ultra96-V2 development board using Xilinx Vitis. The LMS6DSL Click Mezzanine is equipped with a sensor that can measure both acceleration and angular rate, making it a versatile choice for various applications. We will read sensor data and integrate it into the Ultra96-V2 projects. Let's get started!
Create a New Vitis Application Project
- Launch Xilinx Vitis.
- Create a new Vitis application project.
- Select your Ultra96-V2 board as the target platform.
{gallery} |
---|
Create an application project for the LMS6DSL sensor and add the following C code to read data from the LMS6DSL sensor. We will be using the SPI interface to communicate with the sensor. Build the project and program the Ultra96-V2 board with the generated application.
#include "xparameters.h"
#include "xspips.h"
#define SPI XPAR_XSPIPS_0_DEVICE_ID
static XSpiPs SpiInstance;
int main()
{
XSpiPs_Config *SpiConfig;
int delay;
s16 temperature;
u8 cmd[2];
u8 rx[2];
u16 temp;
u8 temp_l;
u8 temp_h;
u8 read = (0x80);
u8 write = (0x00);
int byte_i;
int loop;
printf("Lab 11\n\r");
SpiConfig = XSpiPs_LookupConfig((u16)SPI);
XSpiPs_CfgInitialize(&SpiInstance, SpiConfig,SpiConfig->BaseAddress);
XSpiPs_SetOptions(&SpiInstance,XSPIPS_MASTER_OPTION | XSPIPS_FORCE_SSELECT_OPTION);
XSpiPs_SetClkPrescaler(&SpiInstance, XSPIPS_CLK_PRESCALE_256);
//detect the LSM6DSL
cmd[0] = (u8) 0x8f;
cmd[1] = (u8) 0x00;
XSpiPs_SetSlaveSelect(&SpiInstance, 0x01);
XSpiPs_PolledTransfer(&SpiInstance, cmd, rx, 2);
XSpiPs_SetSlaveSelect(&SpiInstance, 0x01);
if (rx[1] == 0x6a){
printf("LSM6DSL detected\n\r");
}
else{
printf("LSM6DSL NOT detected cannot continue\n\r");
return XST_FAILURE;
}
cmd[0] = (u8) 0x10;
cmd[1] = (u8) 0xA0;
XSpiPs_SetSlaveSelect(&SpiInstance, 0x01);
XSpiPs_PolledTransfer(&SpiInstance, cmd, rx, 2);
XSpiPs_SetSlaveSelect(&SpiInstance, 0x01);
while(1){
cmd[0] = (u8) 0xA0;
cmd[1] = (u8) 0x00;
XSpiPs_SetSlaveSelect(&SpiInstance, 0x01);
XSpiPs_PolledTransfer(&SpiInstance, cmd, rx, 2);
XSpiPs_SetSlaveSelect(&SpiInstance, 0x01);
temp_l = rx[1];
//printf("Temp L %x\n\r",rx[1]);
cmd[0] = (u8) 0xA1;
cmd[1] = (u8) 0x00;
XSpiPs_SetSlaveSelect(&SpiInstance, 0x01);
XSpiPs_PolledTransfer(&SpiInstance, cmd, rx, 2);
XSpiPs_SetSlaveSelect(&SpiInstance, 0x01);
temp_h = rx[1];
//printf("Temp H %x\n\r",rx[1]);
temp = ((temp_h <<8)|(temp_l));
if ((temp & 0x8000) == 0) //msb = 0 so not negative
{
temperature = temp;
}
else {
// Otherwise perform the 2's complement math on the value
temperature = (~(temp - 0x01)) * -1;
}
//printf("Temp %x\n\r",temperature);
temperature = temperature * 0.09765;
printf("Temp %d\n\r",temperature);
usleep(1000000);
}
}
Turn off the board and connect the LMS6DSL Click Mezzanine to the Ultra96-V2 board. Make sure it's securely attached to the board's Click Mezzanine connector.
Congratulations! We've successfully interfaced the LMS6DSL Click Mezzanine with the Ultra96-V2 development board using Xilinx Vitis. You can now integrate sensor data into your Ultra96-V2 projects. Happy coding!