Sensors Knowledge Base

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sensors Knowledge Base

Discussions

Sort by:
FRDM-STBC-AGM01: 9-Axis Inertial Measurement Sensor Board FRDM-KL25Z FRDM-STBC-AGM01 - Example project in KDS 3.0.0 using KSDK 1.2.0 and Processor Expert FRDM-STBC-AGM01 - Bare metal example project   FRDMSTBC-A8471: 3-Axis Accelerometer Sensor Toolbox Development Board FRDMSTBC-A8471 - Bare metal example project FRDMSTBC-A8471 - Example project in KDS 3.0.2 using KSDK 2.0 FXLS8471Q Auto-sleep with Transient threshold trigger    MPL3115A2: 20 to 110kPa, Absolute Digital (I 2 C) Pressure Sensor MPL3115A2 - Bare metal example project FRDMKL25-P3115 - Example project in KDS 3.0.2 using KSDK 2.0 https://community.nxp.com/docs/DOC-345632    MPL115A1: 50 to 115kPa, Absolute Digital (SPI) Pressure Sensor MPL115A1- Bare metal example project    FXOS8700CQ: Digital (I 2 C/SPI) Sensor - 3-Axis Accelerometer (±2g/±4g/±8g) + 3-Axis Magnetometer FXOS8700CQ - Bare metal example project FXOS8700CQ - Magnetic threshold detection function example code  FXOS8700CQ - Auto-sleep with Magnetic threshold trigger    FXLS8471Q: ±2g/±4g/±8g, 3-Axis, 14-Bit Digital (I 2 C/SPI) Accelerometer FXLS8471Q - Bare metal example project FXLS8471Q - FIFO Fill mode example code FXLS8471Q - Accelerometer vector-magnitude function example code FXLS8471Q - Accelerometer transient detection function example code FXLS8471Q - Accelerometer motion detection function example code  FXLS8471Q - Accelerometer orientation detection function example code    MMA8652FC: ±2g/±4g/±8g, 3-Axis, 12-Bit Digital (I 2 C) Accelerometer MMA8652FC - Bare metal example project MMA8652FC - Auto-WAKE/SLEEP mode   MMA8451Q: ±2g/±4g/±8g, 3-Axis, 14-bit Digital (I 2 C) Accelerometer MMA8451Q - Bare metal example project MMA8451Q - Single Tap Detection Bare metal example project FRDM-KL27Z MMA8451Q - How to build and run an ISSDK based example project    MMA8491Q: ±8g, 3-Axis, 14-bit Digital (I 2 C) Accelerometer/Tilt Sensor MMA8491Q - Acceleration data streaming using the PIT on the Kinetis KL25Z MCU   FXLN83xxQ: 3-Axis, Low-Power, Analog Accelerometer FXLN8371Q - Bare metal example project   FXAS21002C: 3-Axis Digital (I 2 C/SPI) Gyroscope FXAS21000 – Bare metal example project FXAS21002C - Angular rate threshold detection function example code   MAG3110FC: 3-Axis Digital (I 2 C) Magnetometer MAG3110FC – Bare metal example project   LM75A: Digital temperature sensor and thermal watchdog LM75A - Temperature data streaming using the PIT on the Kinetis KL25Z MCU
View full article
Hi Everyone, This tutorial is a guide on how to create a simple application in the Kinetis Design Studio that reads the data from both sensors on the FRDM-STBC-AGM01 board​ using an interrupt technique through the I 2 C interface. The Processor Expert is used to configure the I 2 C interface and GPIO on the MKL25Z128 MCU. I will not cover the Sensor Fusion libraryand the ISF​. Before you begin please make sure that both the Kinetis Design Studio (Eclipse based) and the Kinetis SDK are setup and you can already compile and debug code. If not, please refer to Erich's blog: Tutorial: Adafruit WS2812B NeoPixels with the Freescale FRDM-K64F Board – Part 2: Software Tools | MCU on Eclipse http://centaurian.co.uk/2015/05/22/toolchain-ksdk-1-2-0-with-eclipse-4-4-luna-and-gnu-arm-plugin/ 1. Create a new project in KDS Within KDS, click on "File" menu item and select "New" > "Kinetis Project" Name and set location of your project. I use the default location under the workspace area. Click Next. Select the development board used (in my case it is the FRDM-KL25Z) and click Next. Select “KSDK 1.2.0”. Set location to KSDK path, I use an absolute path. The location of my KSDK is in the default location where KSDK would install to. Ensure “Processor Expert” checkbox is checked. Press Next. Make sure that “GNU C Compiler” is selected. Click the "Finish" button. 2. Open Processor Expert Open the Processor Expert perspective, this should be a button on the top right hand side of Eclipse. If it is not there, try clicking on the “Open Perspective” button and then selecting “Processor Expert” in the form that appears. 3. Add I2C component Click on the “Components Library” tab, search for the component “fsl_i2c” and double click on it. Select the "i2cCom1:fsl_i2c" in the Components window. In the "Component Inspector" tab configure the I2C component. As you can see in the FRDM-STBC-AGM01 schematic, with jumpers J6 and J7 in their default position (2-3), the I 2 C signals are routed to the I2C1 module (PTC1 and PTC2 pins) of the KL25Z MCU. The 7-bit I 2 C slave address of the FXOS8700CQ is 0x1E (to enter hex values, switch the format to the ‘H’ mode) since both SA0 and SA1 pins are shorted to GND. The address of the FXAS21002C is 0x20 since SA0 pin is also shorted to GND. The I2C bus clock frequency is set to 400 kHz. 4. Add GPIO component Click on the “Components Library” tab, search for the component “fsl_gpio” and double click on it. Select the "gpio1:fsl_gpio" in the Components window. In the "Component Inspector" tab configure the GPIO component. The INT1_8700 output is connected to the PTD4 pin and the INT1_21002 pin to the PTA5 pin of the KL25Z MCU. These both interrupt pins are configured as push-pull active-low outputs, so the corresponding PTD4/PTA5 pin configuration is GPIO with an interrupt on falling edge. To enable both the PORTA and PORTD interrupts, select the “Events” tab and then select “generate code” next to PORTA IRQ and PORTD IRQ handlers. 5. Add Wait component​ Click on the “Components Library” tab, search for the component “Wait” and double click on it. At this point we have done all we can within Processor Expert. Make sure you save all on the project at this point then on the Components window, click on the "Generate code" button. 6. Add your code Here is the initialization of the FXOS8700CQ and FXAS21002C. /****************************************************************************** * FXOS8700CQ initialization function ******************************************************************************/ void FXOS8700CQ_Init (void) {   FXOS8700CQ_WriteRegister(CTRL_REG2, 0x40); // Reset all registers to POR values   WAIT1_Waitms(1);   FXOS8700CQ_WriteRegister(XYZ_DATA_CFG_REG, 0x00); // +/-2g range with 0.244mg/LSB   FXOS8700CQ_WriteRegister(M_CTRL_REG1, 0x1F); // Hybrid mode (accelerometer + magnetometer), max OSR   FXOS8700CQ_WriteRegister(M_CTRL_REG2, 0x20); // M_OUT_X_MSB register 0x33 follows the OUT_Z_LSB register 0x06 (used for burst read)   FXOS8700CQ_WriteRegister(CTRL_REG2, 0x02); // High Resolution mode   FXOS8700CQ_WriteRegister(CTRL_REG3, 0x00); // Push-pull, active low interrupt   FXOS8700CQ_WriteRegister(CTRL_REG4, 0x01); // Enable DRDY interrupt   FXOS8700CQ_WriteRegister(CTRL_REG5, 0x01); // DRDY interrupt routed to INT1 - PTD4   FXOS8700CQ_WriteRegister(CTRL_REG1, 0x25); // ODR = 25Hz, Reduced noise, Active mode } /****************************************************************************** * FXAS21002C initialization function ******************************************************************************/ void FXAS21002C_Init (void) {   FXAS21002C_WriteRegister(GYRO_CTRL_REG1, 0x40); // Reset all registers to POR values   WAIT1_Waitms(1);   FXAS21002C_WriteRegister(GYRO_CTRL_REG0, 0x03); // High-pass filter disabled, +/-250 dps range -> 7.8125 mdps/LSB = 128 LSB/dps   FXAS21002C_WriteRegister(GYRO_CTRL_REG2, 0x0C); // Enable DRDY interrupt, mapped to INT1 - PTA5, push-pull, active low interrupt   FXAS21002C_WriteRegister(GYRO_CTRL_REG1, 0x16); // ODR = 25Hz, Active mode } In the ISRs (look for the file Events.c), only the interrupt flags are cleared and the DataReady variables are set to indicate the arrival of new data. void PORTA_IRQHandler(void) {   /* Clear interrupt flag.*/   PORT_HAL_ClearPortIntFlag(PORTA_BASE_PTR);   /* Write your code here ... */   FXAS21002C_DataReady = 1; } void PORTD_IRQHandler(void) {   /* Clear interrupt flag.*/   PORT_HAL_ClearPortIntFlag(PORTD_BASE_PTR);   /* Write your code here ... */   FXOS8700CQ_DataReady = 1; } The output values from accelerometer registers 0x01 – 0x06 are first converted to signed 14-bit integer values and afterwards to real values in g’s. Similarly, the output values from magnetometer registers 0x33 – 0x38 are first converted to signed 16-bit integer values and afterwards to real values in microtesla (µT). if (FXOS8700CQ_DataReady)         // Is a new set of accel+mag data ready? {    FXOS8700CQ_DataReady = 0;       FXOS8700CQ_ReadRegisters(OUT_X_MSB_REG, 12, AccelMagData);         // Read FXOS8700CQ data output registers 0x01-0x06 and 0x33 - 0x38       // 14-bit accelerometer data    Xout_Accel_14_bit = ((int16_t) (AccelMagData[0]<<8 | AccelMagData[1])) >> 2;             // Compute 14-bit X-axis acceleration output value    Yout_Accel_14_bit = ((int16_t) (AccelMagData[2]<<8 | AccelMagData[3])) >> 2;             // Compute 14-bit Y-axis acceleration output value    Zout_Accel_14_bit = ((int16_t) (AccelMagData[4]<<8 | AccelMagData[5])) >> 2;             // Compute 14-bit Z-axis acceleration output value       // Accelerometer data converted to g's    Xout_g = ((float) Xout_Accel_14_bit) / SENSITIVITY_2G;         // Compute X-axis output value in g's    Yout_g = ((float) Yout_Accel_14_bit) / SENSITIVITY_2G;         // Compute Y-axis output value in g's    Zout_g = ((float) Zout_Accel_14_bit) / SENSITIVITY_2G;         // Compute Z-axis output value in g's    // 16-bit magnetometer data    Xout_Mag_16_bit = (int16_t) (AccelMagData[6]<<8 | AccelMagData[7]);        // Compute 16-bit X-axis magnetic output value    Yout_Mag_16_bit = (int16_t) (AccelMagData[8]<<8 | AccelMagData[9]);        // Compute 16-bit Y-axis magnetic output value    Zout_Mag_16_bit = (int16_t) (AccelMagData[10]<<8 | AccelMagData[11]);      // Compute 16-bit Z-axis magnetic output value    // Magnetometer data converted to microteslas    Xout_uT = (float) (Xout_Mag_16_bit) / SENSITIVITY_MAG;             // Compute X-axis output magnetic value in uT    Yout_uT = (float) (Yout_Mag_16_bit) / SENSITIVITY_MAG;             // Compute Y-axis output magnetic value in uT    Zout_uT = (float) (Zout_Mag_16_bit) / SENSITIVITY_MAG;             // Compute Z-axis output magnetic value in uT } Similarly, the output values from gyroscope registers 0x01 – 0x06 are first converted to signed 16-bit integer values and afterwards to real values in degrees per second. Temperature is also read out from the 0x12 register. if (FXAS21002C_DataReady)         // Is a new set of gyro data ready? {    FXAS21002C_DataReady = 0;    FXAS21002C_ReadRegisters(GYRO_OUT_X_MSB_REG, 6, GyroData);         // Read FXAS21002C data output registers 0x01-0x06    // 16-bit gyro data    Xout_Gyro_16_bit = (int16_t) (GyroData[0]<<8 | GyroData[1]);         // Compute 16-bit X-axis output value    Yout_Gyro_16_bit = (int16_t) (GyroData[2]<<8 | GyroData[3]);         // Compute 16-bit Y-axis output value    Zout_Gyro_16_bit = (int16_t) (GyroData[4]<<8 | GyroData[5]);         // Compute 16-bit Z-axis output value    // Gyro data converted to dps    Roll = (float) (Xout_Gyro_16_bit) / SENSITIVITY_250;               // Compute X-axis output value in dps    Pitch = (float) (Yout_Gyro_16_bit) / SENSITIVITY_250;              // Compute Y-axis output value in dps    Yaw = (float) (Zout_Gyro_16_bit) / SENSITIVITY_250;                // Compute Z-axis output value in dps    // Temperature data    FXAS21002C_ReadRegisters(GYRO_TEMP_REG, 1, GyroData);    Temp = (int8_t) (GyroData[0]); } The complete project including the I2C communication routines and sensor's header files is attached. 6. Build and debug the project To build the project, select the root folder of the project in the Project Explorer view and click the "Hammer" icon to build it. If everything goes well, no errors are shown in the "Problems" view: The .elf (binary) file has been created inside the "Debug" folder: Connect the SDA port on the FRDM-KL25Z board to a USB port on your computer. To debug the project for the first time, select the root folder of the project in the Project Explorer view and open the "Debug Configurations" window. Select the ""GDB PEMicro Interface Debugging" and click the "New launch configuration" icon. In the "Debugger" tab, select the "OpenSDA Embedded Debug - USB Port" interface and the KL25Z128M4 as a target device. Click the "Debug" button. Click the "Resume" button to run the project. You can pause the execution and look at the data using the "Suspend" button. Now you can edit, build and debug the project again. As we used a debug configuration, it is listed under the "Debug" icon, so you can start it from there. Well done if you managed to follow along and get it all working. As a bonus I have attached the FreeMASTER project that will allow you to visualize the gathered data. If there are any questions regarding this simple project, do not hesitate to ask below. Your feedback or suggestions are also welcome. Regards, Tomas
View full article
Hi Everyone,   As I am often asked for a simple bare metal example code illustrating the use of the embedded rate threshold detection function, I have decided to share here one of my examples I created for the FXAS21002C gyroscope while working with the NXP FRDM-KL25Z platform and FRDM-FXS-MULT2-B sensor expansion board.   The FXAS21002C is set for detection of an angular rate exceeding 96 dps for a minimum period of 20 ms on either the X or Y axes. Once an event is triggered, an interrupt will be generated on the INT1 pin:   void FXAS21002_Init (void) {     unsigned char reg_val = 0;                 I2C_WriteRegister(FXAS21002_I2C_ADDRESS, CTRL_REG1, 0x40);      // Reset all registers to POR values                 Pause(0x631);                                                   // ~1ms delay                             do                                                              // Wait for the RST bit to clear     {         reg_val = I2C_ReadRegister(FXAS21002_I2C_ADDRESS, CTRL_REG1) & 0x40;     }    while (reg_val);                 I2C_WriteRegister(FXAS21002_I2C_ADDRESS, RT_THS_REG, 0x05);     // Set threshold to 96 dps             I2C_WriteRegister(FXAS21002_I2C_ADDRESS, RT_COUNT_REG, 0x02);   // Set debounce timer period to 20 ms    I2C_WriteRegister(FXAS21002_I2C_ADDRESS, RT_CFG_REG, 0x0B);     // Enable rate threshold detection for X and Y axis, latch enabled  I2C_WriteRegister(FXAS21002_I2C_ADDRESS, CTRL_REG2, 0x30);      // Rate threshold interrupt enabled and routed to INT1    I2C_WriteRegister(FXAS21002_I2C_ADDRESS, CTRL_REG1, 0x0E);      // ODR = 100 Hz, Active mode    }     In the ISR, only the interrupt flag is cleared and the RT_SRC register (0x0F) is read in order to clear the EA status bit and deassert the INT1 pin, as shown on the screenshot below. 0x4C in the RT_SRC register indicates that the rate threshold event has been detected on the Y-axis and was negative.   void PORTA_IRQHandler() {    PORTA_PCR5 |= PORT_PCR_ISF_MASK;                                   // Clear the interrupt flag     IntSource = I2C_ReadRegister(FXAS21002_I2C_ADDRESS, RT_SRC_REG);   // Read the RT_SRC register to clear the EA flag and deassert the INT1 pin EventCounter++;       }       Attached you can find the complete source code. If there are any questions regarding this simple example code, please feel free to ask below. Your feedback or suggestions are also welcome.   Regards, Tomas Original Attachment has been moved to: FRDM-KL25Z-FXAS21002-Angular-rate-detection-using-interrupts.rar
View full article
This is a step-by-step guide document to set the FRDM-K64F-AGM01 on the Freescale Sensor Fusion Toolbox Software.
View full article
Hi, The FXAS2100x, is a small, low-power, yaw, pitch, and roll angular rate gyroscope with 16 bit ADC resolution. The full-scale range is adjustable from ±250°/s to ±2000°/s. It features both I2C and SPI interfaces. Here is a Render of the FXAS2100x Breakout- Board downloaded from OSH Park: Layout Design for this board: In the Attachments section, you can find the Schematic Source File (SCH), Schematic PDF File, Layout Source File (BRD), Gerber Files (GTL, GBL, GTS, GBS, GTO, GBO, GKO, XLN) and BOM files. If you're interested in more designs like this breakout board for other sensors, please go to Freescale Sensors Breakout Boards Designs – HOME
View full article
Hello Freescale Community, Most of the new Freescale Sensors in our portfolio come in very small packages, some of them as small as 2x2x1mm, which is awesome! However, one of the problems that we detected last year is that many customers struggle in the evaluation stage of the project due to the small packages. They should either, buy an evaluation board or spend valuable time designing and manufacturing a PCB just for testing our devices. Our goal with this project is to share with our community the Freescale Sensors Breakout Boards we designed for this specific purpose, so you can easily manufacture your own sensor boards or modify our designs to fit  your specific application. This way you can easily evaluate Freescale sensors. The boards were designed to be used in a prototype board (DIP style pins) and they can communicate to any MCU thru IIC or SPI (depending on the sensor). These designs were made using Eagle Layout 6.5, if you want to modify the designs you can do it with the free version of Eagle CAD (for non-commercial purposes), or you can send the gerber files (included in the zip files) to your preferred PCB manufacturer. The following designs are available: + Altimeter: MPL3115A2 Breakout Board + Accelerometer: MMA845x Breakout Board MMA865x Breakout Board MMA8491 Breakout Board FXLN83xx Breakout Board FXLS8471 Breakout Board MMA690x Breakout Board + Accelerometer + Magnetometer (6-DOF): FXOS8700 Breakout Board + Gyroscope: FXAS2100x Breakout Board The above .ZIP files, contains the following design information: - Schematic Source File (.SCH) - Schematic (.PDF) - Layout Source File (.BRD) - Layout Images (.jpg) - Gerber Files (GTL, GBL, GTS, GBS, GTO, GBO, GKO, XLN). - PCB Render Image (.png created in OSH park) - BOM (.xls) Additional content: If you want to modify our designs, please download the attached library file "Freescale_Sensors_v2.lbr" and add it to your Eagle Library repository. We'll be more than glad to respond to your questions and please, let us know what you think. -Freescale Sensor's Support team.
View full article
The Freescale Freedom KL26Z hardware (FRDM-KL26Z) is a capable and cost-effective design featuring a Kinetis L series microcontroller, the industry’s first microcontroller built on the ARM® Cortex™-M0+ core. It features a KL26Z128VLH4 (KL26Z), a device boasting a maximum operating frequency of 48MHz, 128KB of flash. The FRDM-KL26Z features the Freescale open standard embedded serial and debug adapter known as OpenSDA. You can find more information at following link: FRDM-KL26Z: Freescale Freedom Development Platform for Kinetis KL16 and KL26 MCUs (up to 128 KB Flash) The second required board for this example is the Freescale's Freedom Development Platform for Multiple Xtrinsic Sensors, the FRDM-FXS-MULTI. It is a sensor expansion board that contains 7 sensors among which is the FXAS21000 Xtrinsic 3-axis gyroscopic sensors. This example is using above mentioned tools to create data acquisition system (DAQ) for acquiring angular rate data measured in deg/s from the FXAS21000 Xtrinsic 3-axis gyroscopic sensors (Gyro). For data logging and visualization of acquired data FreeMASTER tool is used. The output is in 3 directions of rotation. Around X direction is for the Roll (around longitudinal axis), around Y direction is for the Pitch (around the lateral axis) and around Z direction for the Yaw (around the vertical axis). The Gyro embedded registers are accessed through an I 2 C serial interface and routed to KL26Z I 2 C 1 module with following pin association. Precisely the 7-bit I 2 C slave address is 0x20 (SA0=0) and SCL1, SDA1 lines are routed to port C of the I 2 C 1 module at KL26Z board pins PTC1 and PTC2: Proper interrupt INT1_GYRO at J1-6 needs to be routed via jumper on J6 to INT_GYRO as shown in following block diagram since the interrupts are shared with other sensors: This is then handled as GPIO port A: PTA at the KL26Z board and configured for the falling edge interrupts. For more details see the schematics of the FRDM-FXS-MULTI block diagram. This example illustrates:    1.  Initialization of the KL26Z MCU (I 2 C and PORT modules).    2. Initialization of the Gyro to achieve the resolution 0.025 dsp/LSB with +/-200 dps range and a high-pass filter on.    3. Output data reading using an interrupt technique.    4. Conversion of the output values from registers 0x01 – 0x06 to real values in deg/s.    5. Visualization of the output values in the FreeMASTER tool. 1. According to the schematic, the INT1_GYRO output of the FXAS21000 is connected to the PTA5 pin of the KL26Z MCU and both SCL and SDA lines are connected to the I2C1 module (PTC1 and PTC2 pins). The MCU is, therefore, configured as follows:      void MCU_Init(void){              //I2C1 module initialisation         SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK;       // Turn on clock to I2C1 module         SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;      // Turn on clock to Port C module         PORTC_PCR1 = PORT_PCR_MUX(2);           // PTC1 pin is I2C1 SCL1 line pin alternative         PORTC_PCR2 = PORT_PCR_MUX(2);           // PTC2 pin is I2C1 SDA1 line pin alternative         I2C1_F = 0x14; // SDA hold time = 2.125us, SCL start hold time = 4.25us, SCL stop hold time = 5.125us         I2C1_C1 = I2C_C1_IICEN_MASK;                    // Enable I2C1 module              //Configure the PTA5 pin (connected to the INT_GYRO of the FXAS21000) for falling edge interrupts         SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;      // Turn on clock to Port A module         PORTA_PCR5 |= (0|PORT_PCR_ISF_MASK|     // Clear the interrupt flag         PORT_PCR_MUX(0x1)|                      // PTA5 is configured as GPIO         PORT_PCR_IRQC(0xA));                    // PTA5 is configured for falling edge interrupts             //Enable PORTA interrupt on NVIC         NVIC_ICPR |= 1 << ((INT_PORTA - 16)%32);         NVIC_ISER |= 1 << ((INT_PORTA - 16)%32);      } 2. At the beginning of the initialization, all Gyro registers are reset to their default values by setting the RST bit of the CTRL_REG1 register. Also the ZR_cond in CTRL_REG1 to trigger the offset compensation is enabled and hold till ZR_cond offset compensation is accomplished. This is meant to be used only when the IC is in zero rate condition on all axes. Writing a '1' to this bit initiates the internal zero-rate offset calibration. The ZR_cond bit self-clears after the zero-rate offset calculation, and it can only be used once after a hard or soft reset has occurred. The measuring range of Gyro is set to ±200 dps and to achieve the highest resolution the ODR = 1.5625Hz (640ms) and the High-pass filter is enabled with H-P filter cutoff frq.:0.047 Hz.      void Gyro_Init (void){              unsigned char reg_val = 0;          I2C_WriteRegister(FXAS21_I2C_ADDRESS, CTRL_REG1, 0x40); // Reset all registers to POR values              do              // Wait for the RST bit to clear              {                 reg_val = I2C_ReadRegister(FXAS21_I2C_ADDRESS, CTRL_REG1) & 0x40;              } while (reg_val);         // Zero values initialisation ------------------------------------------------------------             //      I2C_WriteRegister(FXAS21_I2C_ADDRESS, CTRL_REG1, 0x80); // ZR_cond to trigger offset compensation             do      // wait till ZR_cond to trigger offset compensation accomplished          {           reg_val = I2C_ReadRegister(FXAS21_I2C_ADDRESS, CTRL_REG1) & 0x80;               } while (reg_val);             //----------------------------------------------------------------------------------------         I2C_WriteRegister(FXAS21_I2C_ADDRESS, CTRL_REG2, 0x0C); // Enable DRDY interrupt, DRDY interrupt routed to INT1 - PTA5, Push-pull, active low interrupt         I2C_WriteRegister(FXAS21_I2C_ADDRESS, CTRL_REG0, 0x17); // High-pass filter enabled, H-P filter cutoff frq.:0.047 Hz, +/-200 dps range -> 0.025 dsp/LSB = 40 LSB/dps         I2C_WriteRegister(FXAS21_I2C_ADDRESS, CTRL_REG1, 0x1E); // ODR = 1.5625Hz(640ms), Active mode      }      Below are the snap shots of write and read section of the registers from the instructions above.           3. In the ISR, only the interrupt flag is cleared and the DataReady variable is set to indicate the arrival of new data.      void PORTA_IRQHandler(){         PORTA_PCR5 |= PORT_PCR_ISF_MASK;                        // Clear the interrupt flag         DataReady = 1;       }      4. The output values from Gyro registers 0x01 – 0x06 are first converted to signed 14-bit values and afterwards to real values in deg/s.      while(1){              if (DataReady){                 // Is a new set of data ready?                               DataReady = 0;                                                                                                I2C_ReadMultiRegisters(FXAS21_I2C_ADDRESS, OUT_X_MSB_REG, 6, GyrData);  // Read data output registers 0x01-0x06              Xout_14_bit = ((short) (GyrData[0]<<8 | GyrData[1])) >> 2;// Compute 14-bit X-axis output value      Yout_14_bit = ((short) (GyrData[2]<<8 | GyrData[3])) >> 2;// Compute 14-bit Y-axis output value              Zout_14_bit = ((short) (GyrData[4]<<8 | GyrData[5])) >> 2;// Compute 14-bit Z-axis output value                                        Roll = ((float) (Xout_14_bit)) / SENGYR_025D;   // Compute X-axis output value in dps              Pitch = ((float) (Yout_14_bit)) / SENGYR_025D;  // Compute Y-axis output value in dps              Yaw = ((float) (Zout_14_bit)) / SENGYR_025D;    // Compute Z-axis output value in dps                                    Temperature on the Gyro is also read out from the TEMP register of the Gyro              Temp = (signed char) I2C_ReadRegister(FXAS21_I2C_ADDRESS, TEMP_REG);  // temperature on Gyro      5. The calculated values can be watched in the "(x)= Variables" window on the top right of the Debug perspective of the CodeWarrior IDE or in the FreeMASTER application.      To open and run the FreeMASTER project, install the FreeMASTER 1.4 application and FreeMASTER Communication Driver that can be downloaded from following link:      FREEMASTER: FreeMASTER Run-Time Debugging Tool      User Guide for FreeMASTER is available within the installation.      For board communication in FreeMASTER following Options of Plug-in Module needs to be selected and configured for the BDM P&E Kinetis cable settings:             FreeMASTER in action screenshot: Enjoy the Freescale Gyro.
View full article
clicktaleID