センサの知識ベース

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Sensors Knowledge Base

ディスカッション

ソート順:
Hi Everyone,   In this document I would like to present a very simple bare-metal example code I created for the LM75A. This I 2 C digital temperature sensor offers an improved resolution of 0.125°C with an accuracy of ±2°C from –25°C to 100°C and ±3°C over –55°C to 125°C. It operates with a single supply from 2.8V to 5.5V and has three address pins, allowing up to eight LM75A devices to operate on a single I 2 C bus without address collisions. The device also includes an open-drain output (OS) which becomes active when the temperature exceeds the programmed limits.   NXP offers the OM13257 temperature sensor daughter card for easy evaluation of most NXP’s temperature sensors including the LM75ADP in a small 8-pin TSSOP8 package. The daughter card is shipped with no temperature sensors soldered to the board, so the LM75ADP needs to be purchased and soldered separately. The daughter board is designed to connect directly to the OM13320 Fm+ Development kit, but I have decided to pair it with one of the most popular Freedom development boards – FRDM-KL25Z.   The wiring is very straightforward as shown on the picture below. Both SCL (JP4-2) and SDA (JP3-2) lines are connected through the on-board 10K pull-up resistors to the I2C1 module (PTE1 and PTE0 pins) on the KL25Z128 MCU. The Vcc pin (JP2-2) is connected to the 3.3V supply voltage and the GND pin to common ground. The address select pins A2, A1 and A0 are connected to GND using jumpers between pins 1 and 2 of JP12, JP11 and JP10, resulting in a 7-bit I 2 C slave address of 0x48.       The LM75A does not have a data ready interrupt, so the PIT (Periodic Interrupt Timer) module is used to read the Temp register periodically at a fixed rate of about 10Hz since the temp-to-digital conversion is executed every 100 ms. The MCU is configured as follows.   /************* MCU initialization function ******/   void MCU_Init(void) {   //I2C1 module initialization SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK; // Turn on clock to I2C1 module  SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK; // Turn on clock to Port E module  PORTE_PCR1 |= PORT_PCR_MUX(6); // PTE1 pin is I2C1 SCL line PORTE_PCR0 |= PORT_PCR_MUX(6); // PTE0 pin is I2C1 SDA line I2C1_F  |= I2C_F_ICR(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     //PIT initialization    SIM_SCGC6 |= SIM_SCGC6_PIT_MASK; // Turn on clock to to the PIT module   PIT_LDVAL0 = 1048000; // Timeout period = 100 ms   PIT_MCR = PIT_MCR_FRZ_MASK; // Enable clock for PIT, freeze PIT in debug mode PIT_TCTRL0 = PIT_TCTRL_TIE_MASK | // Enable PIT interrupt   PIT_TCTRL_TEN_MASK; // and PIT     //Enable PIT interrupt on NVIC NVIC_ICPR |= 1 << ((INT_PIT - 16) % 32); NVIC_ISER |= 1 << ((INT_PIT - 16) % 32); }       In the PIT ISR, the Temp register is read and then the real temperature in °C is calculated as shown below. For more information on how to convert the raw values from the Temp register to real values in °C, please refer to the LM75A data sheet (chapter 7.4.3).   /******** Interrupt handler for PIT ************/   void PIT_IRQHandler() {   PIT_TFLG0 |= PIT_TFLG_TIF_MASK; // Clear the PIT interrupt flag I2C_ReadMultiRegisters(LM75A_I2C_ADDRESS, TEMP_REG, 2, TemperatureData); // Read LM75A Temperature register (MSB + LSB)    Temperature_11_bit = ((short) (TemperatureData[0]<<8 | TemperatureData[1])) >> 5; // Compute 11-bit temperature output value   Temperature = ((float) Temperature_11_bit) * 0.125; // Compute temperature in °C }       The screenshot below shows the two bytes read of the Temp register. It also illustrates how the OS output is activated in interrupt mode by crossing the Tos threshold value stored in the Tos register. The threshold value was set to 26°C, which corresponds to 16-bit value of 0x1A00 read out of the Temp register.       The calculated temperature can be watched in the "Variables" window on the top right of the Debug perspective or in the FreeMASTER application. To open and run the FreeMASTER project, install the FreeMASTER 2.0 application and FreeMASTER Communication Driver. You can try touching your finger to the sensor to see the temperature rise.         Attached you can find the complete source code written in the CW for MCU's v10.6 including the FreeMASTER project.   If there are any questions regarding this simple application, please feel free to ask below. Your feedback or suggestions are also welcome.   Regards, Tomas Original Attachment has been moved to: FreeMASTER---FRDM-KL25Z-LM75A-Temperature-reading-using-I2C.rar Original Attachment has been moved to: FRDM-KL25Z-LM75A-Temperature-reading-using-I2C.rar
記事全体を表示
Hi Everyone,   In this document I would like to present a simple bare-metal example code/demo for the FXLN8371Q Xtrinsic three axis, low-power, low-g, analog output accelerometer. I have created it while working with the Freescale FRDM-KL25Z development platform and FXLN8371Q breakout board. The FreeMASTER tool is used to visualize the acceleration data that are read from the FXLN8371Q through ADC.   This example illustrates:   1. Initialization of the MKL25Z128 MCU (mainly ADC, PORT and PIT modules). 2. Simple offset calibration. 3. Accelerometer outputs reading using ADC and conversion of the 10-bit ADC values to real acceleration values in g’s. 4. Visualization of the output values in the FreeMASTER tool.   1. The FXLN8371Q breakout board (schematic is attached below) needs to have the following pins connected to the FRDM-KL25Z board:   J4-1 (VDD) => J9-4 (P3V3) J4-2 (XOUT) => J10-2 (PTB0/ADC0_SE8) J4-3 (YOUT) => J10-4 (PTB1/ADC0_SE9) J4-4 (ZOUT) => J10-6 (PTB2/ ADC0_SE12) J4-6 (GND) => J9-14 (GND) J3-3 (ST) => J9-14 (GND) J3-4 (EN) => J9-4 (P3V3)   The PIT (Periodic Interrupt Timer) is used to read the output data periodically at a fixed rate of ~200Hz. The MCU is, therefore, configured as follows.   void MCU_Init(void) {      //ADC0 module initialization      SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;        // Turn on clock to ADC0 module      SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;       // Turn on clock to Port B module      PORTB_PCR0 |= PORT_PCR_MUX(0x00);        // PTB0 pin is ADC0 SE8 input      PORTB_PCR1 |= PORT_PCR_MUX(0x00);        // PTB1 pin is ADC0 SE9 input      PORTB_PCR2 |= PORT_PCR_MUX(0x00);        // PTB2 pin is ADC0 SE12 input      ADC0_CFG1 |= ADC_CFG1_ADLSMP_MASK | ADC_CFG1_MODE(0x02);             // Long sample time, single-ended 10-bit conversion                           //PIT module initialization      SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;         // Turn on clock to PIT module      PIT_LDVAL0 = 52400;                      // Timeout period = ~5ms (200Hz)      PIT_MCR = PIT_MCR_FRZ_MASK;              // Enable clock for PIT, freeze PIT in debug mode                               //Enable PIT interrupt on NVIC          NVIC_ICPR |= 1 << ((INT_PIT - 16) % 32);      NVIC_ISER |= 1 << ((INT_PIT - 16) % 32); }   2. The simplest offset calibration method consists of placing the board on a flat surface so that X is at 0g, Y is at 0g and Z is at +1g. 16 samples are recorded and then averaged. The known sensitivity needs to be subtracted from the +1g reading to calculate an assumed 0g offset value for Z.   void Calibrate(void) {      unsigned int Count = 0;                    do                   // Accumulate 16 samples for X, Y, Z      {         ADC0_SC1A = ADC_SC1_ADCH(0x08);               // Process ADC measurements on ADC0_SE8/XOUT                                                                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};         Xout_10_bit += ADC0_RA;                                                                                                      ADC0_SC1A = ADC_SC1_ADCH(0x09);               // Process ADC measurements on ADC0_SE9/YOUT                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};         Yout_10_bit += ADC0_RA;                                                                                                            ADC0_SC1A = ADC_SC1_ADCH(0x0C);                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};    // Process ADC measurements on ADC0_SE12/ZOUT               Zout_10_bit += ADC0_RA;                                                         Count++;                        } while (Count < 16);                    X_offset = (float) Xout_10_bit / 16;                             // Compute X-axis offset by averaging all 16 X-axis samples      Y_offset = (float) Yout_10_bit / 16;                             // Compute Y-axis offset by averaging all 16 Y-axis samples      Z_offset = ((float) Zout_10_bit / 16) - SENSITIVITY_2G;          // Compute Z-axis offset by averaging all 16 Z-axis samples and subtracting the known sensitivity                      PIT_TCTRL0 = PIT_TCTRL_TIE_MASK | PIT_TCTRL_TEN_MASK;          // Enable PIT interrupt and PIT                                      }   3. Reading the FXLN8371Q datasheet, the output voltage when there is no acceleration is typically 0.75V and it should typically change by 229mV per 1g of acceleration in ±2g mode. The signal from a 10-bit ADC gives me a number from 0 to 1023. I will call these “ADC units”.  0V maps to 0 ADC units, VDDA (2.95V on the FRDM-KL25Z board) maps to 1023 ADC units and let’s assume it is linear in between. This means that zero acceleration on an axis should give me a reading of 260 ADC units (0.75V / 2.95V x 1023 ADC units) on the pin for that axis. Also, a change of 1 ADC unit corresponds to a voltage difference of 2.95V / 1023 ADC units = 2.884mV/ADC unit. Since the datasheet says a 1g acceleration typically corresponds to 229mV voltage difference, I can easily convert it to ADC units/g:   229 mV/g = 229 mV/g x (1023 ADC units) / 2.95V = 79.4 ADC units/g = SENSITIVITY_2g   Using this calculated sensitivity and measured offset, I convert the 10-bit ADC values to real acceleration values in g’s in the PIT ISR as follows.   void PIT_IRQHandler() {      ADC0_SC1A = ADC_SC1_ADCH(0x08);                    // Process ADC measurements on ADC0_SE8/XOUT                                                  while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};      Xout_10_bit = ADC0_RA;                                         ADC0_SC1A = ADC_SC1_ADCH(0x09);                    // Process ADC measurements on ADC0_SE9/YOUT                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};      Yout_10_bit = ADC0_RA;                                               ADC0_SC1A = ADC_SC1_ADCH(0x0C);                    // Process ADC measurements on ADC0_SE12/ZOUT                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};      Zout_10_bit = ADC0_RA;                    Xout_g = ((float) Xout_10_bit - X_offset) / SENSITIVITY_2G;         // Compute X-axis output value in g's      Yout_g = ((float) Yout_10_bit - Y_offset) / SENSITIVITY_2G;         // Compute Y-axis output value in g's      Zout_g = ((float) Zout_10_bit - Z_offset) / SENSITIVITY_2G;         // Compute Z-axis output value in g's                     PIT_TFLG0 |= PIT_TFLG_TIF_MASK;          // Clear PIT interrupt flag }   4. The calculated values can be watched in the "Variables" window on the top right of the Debug perspective or in the FreeMASTER application. To open and run the FreeMASTER project, install the FreeMASTER application and FreeMASTER Communication Driver.       I guess this is enough to let you start experimenting with the FXLN83xxQ family of analog accelerometers. Attached you can find the complete source code written in the CW for MCU's v10.6 including the FreeMASTER project.   If there are any questions regarding this simple application, do not hesitate to ask below. Your feedback or suggestions are also welcome.   Regards, Tomas Original Attachment has been moved to: FRDM-KL25Z-FXLN8371Q-Basic-read-using-ADC.zip Original Attachment has been moved to: FreeMASTER---FRDM-KL25Z-FXLN8371Q-Basic-read-using-ADC.zip
記事全体を表示
Hi Everyone,   I would like to share here one of my examples I created for the FXLS8471Q accelerometer while working with the Freescale FRDM-KL25Z platform and FRDM-FXS-MULT2-B sensor expansion board. It illustrates the use of the embedded FIFO buffer to collect the 14-bit acceleration data that are read from the FIFO using an interrupt technique through the SPI interface. For details on the configurations of the FIFO buffer as well as more specific examples and application benefits, please refer to the AN4073.   The FXLS8471Q is initialized as follows:   void FXLS8471Q_Init (void) {/* The software reset does not work properly in SPI mode as described in Appendix A of the FXLS8471Q data sheet. Therefore the following piece of the code is not used. I have shortened R46 on the FRDM-FXS-MULTI-B board to activate a hardware reset. FXLS8471Q_WriteRegister(CTRL_REG2, 0x40); // Reset all registers to POR values */   FXLS8471Q_WriteRegister(CTRL_REG1, 0x00); // Standby mode FXLS8471Q_WriteRegister(F_SETUP_REG, 0xA0); // FIFO Fill mode, 32 samples   FXLS8471Q_WriteRegister(CTRL_REG4, 0x40); // Enable FIFO interrupt, push-pull, active low   FXLS8471Q_WriteRegister(CTRL_REG5, 0x40); // Route the FIFO interrupt to INT1 - PTA5   FXLS8471Q_WriteRegister(CTRL_REG1, 0x19); // ODR = 100Hz, Active mode }       In the ISR, only the interrupt flag is cleared and the FIFO_DataReady variable is set to indicate that the FIFO is full.   void PORTA_IRQHandler() { PORTA_PCR5 |= PORT_PCR_ISF_MASK; // Clear the interrupt flag FIFO_DataReady = 1; }       Once the FIFO_DataReady variable is set, the STATUS register (0x00) is read to clear the FIFO interrupt status bit and deassert the INT1 pin. Afterwars the FIFO is read using a 192-byte (3 x 2 x 32 bytes) burst read starting from the OUT_X_MSB register (0x01). Then the raw acceleration data are converted to signed 14-bit values and real values in g’s.   if (FIFO_DataReady) { FIFO_DataReady = 0; FIFO_Status = FXLS8471Q_ReadRegister(STATUS_REG); // Read the Status register to clear the FIFO interrupt status bit FXLS8471Q_ReadMultiRegisters(OUT_X_MSB_REG, 6*Watermark_Val, AccelData); // Read the FIFO using a burst read     for (i = 0; i < Watermark_Val; i++)   { // 14-bit accelerometer data   Xout_Accel_14_bit[i] = ((short) (AccelData[0 + i*6]<<8 | AccelData[1 + i*6])) >> 2; // Compute 14-bit X-axis acceleration output values   Yout_Accel_14_bit[i] = ((short) (AccelData[2 + i*6]<<8 | AccelData[3 + i*6])) >> 2; // Compute 14-bit Y-axis acceleration output values  Zout_Accel_14_bit[i] = ((short) (AccelData[4 + i*6]<<8 | AccelData[5 + i*6])) >> 2; // Compute 14-bit Z-axis acceleration output values   // Accelerometer data converted to g's   Xout_g[i] = ((float) Xout_Accel_14_bit[i]) / SENSITIVITY_2G; // Compute X-axis output values in g's  Yout_g[i] = ((float) Yout_Accel_14_bit[i]) / SENSITIVITY_2G; // Compute Y-axis output values in g's   Zout_g[i] = ((float) Zout_Accel_14_bit[i]) / SENSITIVITY_2G; // Compute Z-axis output values in g's   } }       Deassertion of the INT1 pin after reading the STATUS register (0x00).       ODR is set to 100Hz, so the FIFO is read every 320 ms (10 ms x 32 samples).       The calculated values can be watched in the "Variables" window on the top right of the Debug perspective.       Attached you can find the complete source code written in the CW for MCU's 10.6. If there are any questions regarding this simple example project, please feel free to ask below. Your feedback or suggestions are also welcome.   Regards, Tomas Original Attachment has been moved to: FRDM-KL25Z-FXLS8471Q-FIFO.rar
記事全体を表示
SOP Dual Side Port Package_1351-01
記事全体を表示
Hi Everyone, In this document I would like to present a very simple example code I created for the PCT2075. This I2C digital temperature sensor offers a resolution of 0.125°C with an accuracy of ±1°C over -25°C to 100°C range. It operates with a single supply from 2.7V to 5.5V and has three address pins, allowing up to 27 devices to operate on a single I2C bus without address collisions. The device also includes an open-drain output (OS) which becomes active when the temperature exceeds the programmed limits. NXP offers the PCT2075DP Arduino Shield and GUI for easy evaluation of this temperature sensor. However, I have decided to pair this demo board with the LPC55S06-EVK and create a simple example code in the MCUXpresso IDE using Config tools (Pins, Clocks and Peripherals). The connection is very straightforward. The PCT2075DP-ARD daughter board is inserted to J9, J10, J12 and J13 connectors located on LPC55S06-EVK development board. Both SDA pin (J1-5) and SCL (J1-6) lines are connected through the on-board 5.6K pull-up resistors to the FlexComm1 SDA (PIO0_13, J13_9) and SCL (PIO0_14, J13_11) pins on the LPC55S06-EVK board. The VCC pin (J6-4) is connected to the 3.3V supply voltage and the GND pin to common ground. The address select pins A0, A1 and A2 are connected to GND using jumpers between pins 2 and 3 of J7, J8 and J9, resulting in a 7-bit I2C slave address of 0x48. I created a new project in MCUXpresso IDE v11.3.0 based on SDK_2.8.2_LPCXpresso55S06 using the New project wizard:   It was not necessary to make any changes to the project and I named it LPC55S06 PCT2075 Temp reading using I2C in the wizard:   Let’s start with the Pins Config tool...:   ...to configure PIO0_13 and PIO0_14 for their I2C functions (I2C_SDA and I2C_SCL, respectively). Simply search for each pad in the Pins view:   In the diagram above, I already have PIO0_13 routed for I2C function (it is showing green). However, you may want to check the checkbox in the first column to mark the pin for routing. A dialog pops up, offering you all the possible pin multiplex functions for the pad. Scroll down through the list and select FlexComm1’s SDA function:   When you put a checkmark (“tick”) in the FC1_CTS_SDA row, the Pins Config tool routes the pad and you will see a new entry (in yellow) in the Routed Details view at the bottom of the perspective:   Follow the same procedure to route PIO0_14 for function FC1_SCL. That is already done in the screen-grab above, so I am ready to move to the Peripherals Config tool.  Use the Peripherals icon to switch to the Peripherals perspective:   The Peripherals Config tool identifies that I have set up the pads/pins for FlexComm1 to be used as I2C. But I have not yet set up the I2C peripheral, and so the tool reports a Warning:   There is a very simple fix, proposed by the tool. Select the FLEXCOMM1 warning line, and right-click to bring up a context menu:   Selecting “Initialize FLEXCOMM1 peripheral” opens a dialog where I can select the desired function for FlexComm1… in this case I want I2C configuration. So I select I2C and click [OK]:   The Peripherals Config tool displays the Flexcomm Interface I2C configuration screen. This shows all of the ‘top level’ settings for the I2C module. I configured it as follows:   As the PCT2075 does not have a data ready interrupt, I use the MicroTick (UTICK0) timer to read the Temp register periodically at a fixed rate of about 10Hz since the temp-to-digital conversion is executed every 100 ms. The UTICK0 is configured in the Peripherals Config tool as follows:   I am ready to move to the final, Clocks Config tool:   I chose to use the BOARD_BootClockFRO12M() functional group:   Then I enabled the clock to FlexComm1, since this is the FlexComm module that I use for I2C. I used the fro_12m as the clock source for FlexComm1 I2C:   Finally I enabled the fro_1m and attached the fro_1m to the UTICK timer:   All the configuration is now complete. I can click “Update Code” at the top of the screen to generate all of the necessary configuration code, accept the changes, and return to the C/C++ Develop perspective. In the UTICK0_Callback function, the Temp register is read and then the real temperature in °C is calculated as shown below. For more information on how to convert the raw values from the Temp register to real values in °C, please refer to the PCT2075 data sheet (Chapter 7.4.3).   This screenshot shows the two bytes read of the Temp register (0x00).    The calculated temperature can be watched either in the "Global Variables" window on the top right of the Debug perspective...:   ...or in the Console window:   Attached you can find the complete project developed in the MCUXpresso IDE v11.3.0. If there are any questions regarding this simple application, please feel free to ask below.   Regards, Tomas
記事全体を表示
Hi Everyone,   In this document I would like to go through a simple bare-metal example code I created for the recently released FRDMSTBC-A8471 development board with the NXP FXLS8471Q 3-axis linear accelerometer. This board is compatible with most NXP Freedom development boards and I decided to use one of the most popular - FRDM-KL25Z. The FreeMASTER tool is used to visualize the acceleration data that are read from the FXLS8471Q using an interrupt technique through the SPI interface. I will not cover the Sensor Toolbox software and Intelligent Sensing Framework (ISF) which also support this board.   This example illustrates:   1. Initialization of the MKL25Z128 MCU (mainly SPI and PORT modules). 2. SPI data write and read operations. 3. Initialization of the FXLS8471Q to achieve the highest resolution. 4. Simple offset calibration based on the AN4069. 5. Output data reading using an interrupt technique. 6. Conversion of the output values from registers 0x01 – 0x06 to real acceleration values in g’s. 7. Visualization of the output values in the FreeMASTER tool.     1. As you can see in the FRDMSTBC-A8471​/FRDM-KL25Z​ schematics and the image below, SPI signals are routed to the SPI0 module of the KL25Z MCU and the INT1 output is connected to the PTD4 pin. The PTD0 pin (Chip Select) is not controlled automatically by SPI0 module, hence it is configured as a general-purpose output. The INT1 output of the FXLS8471Q is configured as a push-pull active-low output, so the corresponding PTD4 pin configuration is GPIO with an interrupt on falling edge.The core/system clock frequency is 20.97 MHz and SPI clock is 524.25 kHz.     The MCU is, therefore, configured as follows.   /****************************************************************************** * MCU initialization function ******************************************************************************/   void MCU_Init(void) {   //SPI0 module initialization   SIM_SCGC4 |= SIM_SCGC4_SPI0_MASK; // Turn on clock to SPI0 module   SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK; // Turn on clock to Port D module   PORTD_PCR1 = PORT_PCR_MUX(0x02); // PTD1 pin is SPI0 CLK line   PORTD_PCR2 = PORT_PCR_MUX(0x02); // PTD2 pin is SPI0 MOSI line   PORTD_PCR3 = PORT_PCR_MUX(0x02); // PTD3 pin is SPI0 MISO line   PORTD_PCR0 = PORT_PCR_MUX(0x01); // PTD0 pin is configured as GPIO (CS line driven manually)   GPIOD_PSOR |= GPIO_PSOR_PTSO(0x01); // PTD0 = 1 (CS inactive)   GPIOD_PDDR |= GPIO_PDDR_PDD(0x01); // PTD0 pin is GPIO output     SPI0_C1 = SPI_C1_SPE_MASK | SPI_C1_MSTR_MASK; // Enable SPI0 module, master mode   SPI0_BR = SPI_BR_SPPR(0x04) | SPI_BR_SPR(0x02); // BaudRate = BusClock / ((SPPR+1) * 2^(SPR+1)) = 20970000 / ((4+1) * 2^(2+1)) = 524.25 kHz     //Configure the PTD4 pin (connected to the INT1 of the FXLS8471Q) for falling edge interrupts   PORTD_PCR4 |= (0|PORT_PCR_ISF_MASK| // Clear the interrupt flag                   PORT_PCR_MUX(0x1)| // PTD4 is configured as GPIO                   PORT_PCR_IRQC(0xA)); // PTD4 is configured for falling edge interrupts     //Enable PORTD interrupt on NVIC   NVIC_ICPR |= 1 << ((INT_PORTD - 16)%32);   NVIC_ISER |= 1 << ((INT_PORTD - 16)%32); }     2. The FXLS8471Q uses the ‘Mode 0′ SPI protocol, which means that an inactive state of clock signal is low and data are captured on the leading edge of clock signal and changed on the falling edge.   The falling edge on the CS pin starts the SPI communication. A write operation is initiated by transmitting a 1 for the R/W bit. Then the 8-bit register address, ADDR[7:0] is encoded in the first and second serialized bytes. Data to be written starts in the third serialized byte. The order of the bits is as follows:   Byte 0: R/W, ADDR[6], ADDR[5], ADDR[4], ADDR[3], ADDR[2], ADDR[1], ADDR[0] Byte 1: ADDR[7], X, X, X, X, X, X, X Byte 2: DATA[7], DATA[6], DATA[5], DATA[4], DATA[3], DATA[2], DATA[1], DATA[0]   The rising edge on the CS pin stops the SPI communication.   Below is the write operation which writes the value 0x3D to the CTRL_REG1 (0x3A).   Similarly a read operation is initiated by transmitting a 0 for the R/W bit. Then the 8-bit register address, ADDR[7:0] is encoded in the first and second serialized bytes. The data is read from the MISO pin (MSB first).   The screenshot below shows the read operation which reads the correct value 0x6A from the WHO_AM_I register (0x0D).   Multiple read operations are performed similar to single read except bytes are read in multiples of eight SCLK cycles. The register address is auto incremented so that every eighth next clock edges will latch the MSB of the next register.   A burst read of 6 bytes from registers 0x01 to 0x06 is shown below. It also shows how the INT1 pin is automatically cleared by reading the acceleration output data.     3. The dynamic range is set to ±2g and to achieve the highest resolution, the LNOISE bit is set and the lowest ODR (1.56Hz) and the High Resolution mode are selected (more details in AN4075). The DRDY interrupt is enabled and routed to the INT1 interrupt pin that is configured to be a push-pull, active-low output.   /****************************************************************************** * FXLS8471Q initialization function ******************************************************************************/   void FXLS8471Q_Init (void) {   FXLS8471Q_WriteRegister(CTRL_REG2, 0x02); // High Resolution mode   FXLS8471Q_WriteRegister(CTRL_REG3, 0x00); // Push-pull, active low interrupt   FXLS8471Q_WriteRegister(CTRL_REG4, 0x01); // Enable DRDY interrupt   FXLS8471Q_WriteRegister(CTRL_REG5, 0x01); // DRDY interrupt routed to INT1-PTD4   FXLS8471Q_WriteRegister(CTRL_REG1, 0x3D); // ODR = 1.56Hz, Reduced noise, Active mode   }     4. A simple offset calibration method is implemented according to the AN4069​.   /****************************************************************************** * Simple accelerometer offset calibration ******************************************************************************/   void FXLS8471Q_Calibrate (void) {   unsigned char reg_val = 0;     while (!reg_val) // Wait for a first set of data    {     reg_val = FXLS8471Q_ReadRegister(STATUS_REG) & 0x08;   }      FXLS8471Q_ReadMultiRegisters(OUT_X_MSB_REG, 6, AccData); // Read data output registers 0x01-0x06       Xout_14_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 2; // Compute 14-bit X-axis output value   Yout_14_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 2; // Compute 14-bit Y-axis output value   Zout_14_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 2; // Compute 14-bit Z-axis output value      Xoffset = Xout_14_bit / 8 * (-1); // Compute X-axis offset correction value   Yoffset = Yout_14_bit / 8 * (-1); // Compute Y-axis offset correction value   Zoffset = (Zout_14_bit - SENSITIVITY_2G) / 8 * (-1); // Compute Z-axis offset correction value      FXLS8471Q_WriteRegister(CTRL_REG1, 0x00); // Standby mode to allow writing to the offset registers   FXLS8471Q_WriteRegister(OFF_X_REG, Xoffset);   FXLS8471Q_WriteRegister(OFF_Y_REG, Yoffset);   FXLS8471Q_WriteRegister(OFF_Z_REG, Zoffset);      FXLS8471Q_WriteRegister(CTRL_REG1, 0x3D); // ODR = 1.56Hz, Reduced noise, Active mode }     5. In the ISR, only the interrupt flag is cleared and the DataReady variable is set to indicate the arrival of new data.   /****************************************************************************** * PORT D Interrupt handler ******************************************************************************/   void PORTD_IRQHandler() {   PORTD_PCR4 |= PORT_PCR_ISF_MASK; // Clear the interrupt flag   DataReady = 1; }     6. The output values from accelerometer registers 0x01 – 0x06 are first converted to signed 14-bit values and afterwards to real values in g’s.   if (DataReady)     // Is a new set of data ready? {   DataReady = 0;     FXLS8471Q_ReadMultiRegisters(OUT_X_MSB_REG, 6, AccData); // Read data output registers 0x01-0x06                                                    Xout_14_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 2; // Compute 14-bit X-axis output value   Yout_14_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 2; // Compute 14-bit Y-axis output value   Zout_14_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 2; // Compute 14-bit Z-axis output value                                        Xout_g = ((float) Xout_14_bit) / SENSITIVITY_2G; // Compute X-axis output value in g's   Yout_g = ((float) Yout_14_bit) / SENSITIVITY_2G; // Compute Y-axis output value in g's   Zout_g = ((float) Zout_14_bit) / SENSITIVITY_2G; // Compute Z-axis output value in g's }     7. The calculated values can be watched in the "Variables" window on the top right of the Debug perspective or in the FreeMASTER application. To open and run the FreeMASTER project, install the FreeMASTER 2.0 application and FreeMASTER Communication Driver.         Attached you can find the complete source code written in the CW for MCU's v10.6​ including the FreeMASTER project.   If there are any questions regarding this simple application, please feel free to ask below. Your feedback or suggestions are also welcome.   Regards, Tomas
記事全体を表示
Freescale’s FXOS8700CQ 6-axis sensor combines industry leading accelerometer and magnetometer sensors in a small 3 x 3 x 1.2 mm QFN plastic package. The 14-bit accelerometer and 16-bit magnetometer are combined with a high-performance ASIC to enable an eCompass solution capable of a typical orientation resolution of 0.1 degrees and sub 5 degree compass heading accuracy for most applications. Applications include eCompass, enhanced user interface, augmented reality, and location based services (static geographic heading). Target products include smartphones, tablets, personal navigation devices, remote controls for smart TV’s, watches, gaming controllers, robotics, and unmanned air vehicles (UAVs). Here is a Render of the FXOS8700 Breakout- Board downloaded from OSH Park: And here is an image of the 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 for this Breakout-board. If you are interested in more designs like this breakout board for other sensors, please go to Freescale Sensors Breakout Boards Designs – HOME
記事全体を表示
Reading and Writing to SD Card Description: A small project made with mbed (mbed.org) on the FRDM-MK64 using the SD card capabilities. The program will open a file called test.txt in the root of the SD card, and will create one if it does not exist. It will then write "one two three four five" in the .txt file. It will then read the text and output the result. You will need a terminal application (I recommend Termite) in order to see the outputs. The current program overwrites anything that was previous on the SD card. To prevent this, change the "w" to "a" during the writing process. This changes the instruction from a 'write' to an 'append'. This should be compatible with all boards that have an SD card connected. However the appropriate pins from SDFileSystem will have to be changed to suit the board. Check your board's schematic for the appropriate pins.
記事全体を表示
The FRDM33772BSPIEVB serves as a 6-channel and FRDM33771BSPIVB as a 14 channel battery cell controller with a passive cell balancing. A FRDM-KL25Z evaluation board is used for communication with FRDM3377xBSPIEVB and a computer through SPI interface. The kit together with BATT-6EMULATOR 6-cell battery emulator  for the FRDM33772BSPIEVB and BATT-14EMULATOR 14-cell battery emulator for FRDM33771BSPIVB or a battery pack BATT-14AAAPACK for either of them is dedicated to support customer development and evaluation. For a status reading and settings an MC3377x EvalGUI is used. Figure 1. FRDM33771SPI evaluation board Figure 2. BATT-14AAAPACK battery pack Figure 3. BATT-14EMULATOR to supply MC33771 EVBs MC3377x EvalGUI The Graphic User Interface MC3377x EvalGUI is intended to use for evaluation of MC3377x cell controllers. Figure 4. MC3377x Evaluation GUI version 4.02 Hardware setup The GUI supports two types of BMS architectures. Central, only one cluster and distributed, up to 15 clusters. For the central BMS architecture an MC33771 EVB or MC33772 EVB must be stacked on top of an FRDM-KL25Z board. One of the battery emulators or the battery pack is connected through a 34-pin cells connector. For the distributed BMS architecture a MC33664 evaluation board stacked on top of a FRDM-KL25Z is used. The MC3377x evaluation boards are connected to the MC33664 EVB through a twisted pair TPL bus. Connection to a computer is made through OpenSDA port on FRDM-KL25Z and USB on the computer side. Figure 5. FRDM-33771SPIEVB stacked on top of FRDM-KL25Z and BATT-14AAAPACK connected as central BMS architecture After hardware setup is done start the MC3377x EvalGUI and follow instructions for Initial Configuration in MC33771/772 Evaluation GUI Documentation. For access click info->Open docu in MC33771/772 Evaluation GUI. Figure 6. Access to MC33771/772 Evaluation GUI document When the initial configuration is done, voltage reading of every battery cell and overall voltage of all connected batteries in series is enabled. However current measurement is disabled by default. Figure 7. Battery cells measurement with current measurement disabled Enablement of current measurement is done in Cluster view by setting a Bit9 (IMeasEn) in in SYS_CFG1 register to logic 1. The field changes from dark green to  light green and the current measurement is enabled. Figure 8. Enablement of the current measurement Figure 9. Current measurement enabled Current in the GUI is displayed in mV and for the current consumption has to be calculated. Because shunt resistor is Rshunt=100mΩ and measured voltage 1.243mV, thus for this case the current consumption is I=Ushunt/Rshunt = 12.43mA. The shunt resistor has to be chosen so the voltage doesn’t exceed +/-150mV. The voltage is sensed on SENSE_P and SENSE_N pins of the MC3377x controller. Figure 10. Shunt resistor R1 on the BATT-14AAAPACK It’s also possible to use a resistor in the battery pack as a load. The resistor is not populated. Recommended value is 1kΩ, 3W , SMT 2512. The resistor can be connected and disconnected with SW3 switch. Figure 11. Recommended load resistor R7 and toggle switch SW3
記事全体を表示
SOP Top Side Port Package_1369-01  
記事全体を表示
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
記事全体を表示
Hi Everyone,   As I am often asked for a simple bare metal example code illustrating the use of the accelerometer transient detection function, I have decided to share here one of my examples I created for the FXLS8471Q accelerometer while working with the NXP FRDM-KL25Z platform and FRDM-FXS-MULT2-B sensor expansion board.   This example code complements the Python code snippet from the AN4693. The FXLS8471Q is set for detection of an “instantaneous” acceleration change exceeding 315mg for a minimum period of 40 ms on either the X or Y axes. Once an event is triggered, an interrupt will be generated on the INT1 pin:   void FXLS8471Q_Init (void) { FXLS8471Q_WriteRegister(TRANSIENT_THS_REG, 0x85); // Set threshold to 312.5mg (5 x 62.5mg ) FXLS8471Q_WriteRegister(TRANSIENT_COUNT_REG, 0x02); // Set debounce timer period to 40ms FXLS8471Q_WriteRegister(TRANSIENT_CFG_REG, 0x16); // Enable transient detection for X and Y axis, latch enabled FXLS8471Q_WriteRegister(CTRL_REG4, 0x20); // Acceleration transient interrupt enabled FXLS8471Q_WriteRegister(CTRL_REG5, 0x20); // Route acceleration transient interrupt to INT1 - PTA5 FXLS8471Q_WriteRegister(CTRL_REG1, 0x29); // ODR = 12.5Hz, Active mode } ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍     In the ISR, only the interrupt flag is cleared and the TRANSIENT_SRC (0x1E) register is read in order to clear the SRC_TRANS status bit and deassert the INT1 pin, as shown on the screenshot below.   void PORTA_IRQHandler() { PORTA_PCR5 |= PORT_PCR_ISF_MASK; // Clear the interrupt flag IntSource = FXLS8471Q_ReadRegister(TRANSIENT_SRC_REG); // Read the TRANSIENT_SRC register to clear the SRC_TRANS flag in the INT_SOURCE register 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
記事全体を表示
Hi Everyone,   If you are interested in a simple bare metal example code illustrating the use of the magnetic threshold detection function, please find below one of my examples I created for the FXOS8700CQ while working with the NXP FRDM-KL25Z platform and FRDM-FXS-MULT2-B sensor expansion board.   The FXOS8700CQ is set to detect magnetic field exceeding 12.8uT (128 counts) for a minimum period of 100ms on the X-axis. Once an event is triggered, an active low interrupt will be generated on the INT1 pin:   void FXOS8700CQ_Init (void) { I2C_WriteRegister(FXOS8700CQ_I2C_ADDRESS, M_THS_X_MSB_REG, 0x00); // Threshold value MSB I2C_WriteRegister(FXOS8700CQ_I2C_ADDRESS, M_THS_X_LSB_REG, 0x80); // Threshold value LSB I2C_WriteRegister(FXOS8700CQ_I2C_ADDRESS, M_THS_CFG_REG, 0xCB); // Event flag latch enabled, logic OR of enabled axes, only X-axis enabled, threshold interrupt enabled and routed to INT1 I2C_WriteRegister(FXOS8700CQ_I2C_ADDRESS, M_THS_COUNT_REG, 0x0A); // 100ms at 100Hz ODR and magnetometer mode only I2C_WriteRegister(FXOS8700CQ_I2C_ADDRESS, M_CTRL_REG1, 0x1D); // Max OSR, only magnetometer is active I2C_WriteRegister(FXOS8700CQ_I2C_ADDRESS, CTRL_REG3, 0x00); // Push-pull, active low interrupt I2C_WriteRegister(FXOS8700CQ_I2C_ADDRESS, CTRL_REG1, 0x19); // ODR = 100Hz, Active mode }‍‍‍‍‍‍‍‍‍‍     In the ISR, only the interrupt flag is cleared and the M_THS_SRC (0x53) register is read in order to clear the SRC_M_THS flag in the M_INT_SRC register and deassert the INT1 pin, as shown on the screenshot below.   void PORTD_IRQHandler() { PORTD_PCR4 |= PORT_PCR_ISF_MASK; // Clear the interrupt flag M_Ths_src=I2C_ReadRegister(FXOS8700CQ_I2C_ADDRESS, M_THS_SRC_REG); // Read the M_THS_SRC register to clear the SRC_M_THS flag in the M_INT_SRC register and deassert the INT1 pin Event_Counter++; }‍‍‍‍‍‍       Attached you can find the complete source code. If there are any questions regarding this simple example code, please feel free to ask below.    Regards, Tomas
記事全体を表示
Hi Folks, Due to a very high number of questions from our customers regarding how to select the proper Freescale Pressure Sensor for their applications I have decided to create this illustrated, step-by-step easy to follow guideline about how to do it by yourself. Step 1: Go to http://www.freescale.com/webapp/parametricSelector.sp Then click on “Pressure Sensors” Now you should see the following window: And at this point everything is intuitive and basically the rest for select the proper Freescale Pressure Sensor depends on the requirements of your application. However, in order to trying to give you a better explanation, I’m doing an example: For this example let assume that my application requirements are as follow: Pressure measurement range up to 100kPa (higher priority parametric search for my app) Absolute Pressure Sensor Analog Output Integrated Side Ported Mount surface Package: SOP 8 (*I added the “Package Type” Parametric Search) (lower priority) *You can add or remove search parameters clicking on the “Show/Hide Parameters” button.  Based on the mentioned requirements, I selected the check boxes on the Parametric Search Window starting from the parametric with higher priority and leaving the parametric with lower priority at the end, and as a result I will get something like the image below: * You can leave unselected check boxes if are not important for your application, for my example from the image above I leave the “Ambient Operating Temperature” option unselected. So, from the initial 37 pressure sensors options I have to select, now the list it’s reduced to only 1 option, so, for this particular example, the MPXV5100 is the best solution for my application. If there are any questions regarding this guideline, please feel free to ask below. Your feedback or suggestions are also welcome. Regards, Jose
記事全体を表示
Hi Everyone,   If you are interested in a simple bare metal example code illustrating the use of the accelerometer motion detection function, please find below one of my examples I created for the FXLS8471Q accelerometer while working with the NXP FRDM-KL25Z platform and FRDMSTBC-A8471 board.   The FXLS8471Q is set to detect motion exceeding 315mg for a minimum period of 40 ms on either the X or Y axis. Once an event is triggered, an interrupt will be generated on the INT1 pin:   void FXLS8471Q_Init (void) { FXLS8471Q_WriteRegister(FT_MT_THS_REG, 0x85); // Set threshold to 312.5mg (5 x 62.5mg ) FXLS8471Q_WriteRegister(FF_MT_COUNT_REG, 0x02); // Set debounce timer period to 40ms FXLS8471Q_WriteRegister(FF_MT_CFG_REG, 0xD8); // Latch enabled, motion detection enabled for X and Y axis FXLS8471Q_WriteRegister(CTRL_REG4, 0x04); // Motion interrupt enabled FXLS8471Q_WriteRegister(CTRL_REG5, 0x04); // Route motion interrupt to INT1 - PTD4 FXLS8471Q_WriteRegister(CTRL_REG1, 0x29); // ODR = 12.5Hz, Active mode }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍     In the ISR, only the interrupt flag is cleared and the FF_MT_SRC (0x16) register is read in order to clear the SRC_FFMT flag in the INT_SOURCE register and deassert the INT1 pin, as shown on the screenshot below.   void PORTD_IRQHandler() { PORTD_PCR4 |= PORT_PCR_ISF_MASK; // Clear the interrupt flag IntSource = FXLS8471Q_ReadRegister(FF_MT_SRC_REG); // Read the FF_MT_SRC register to clear the SRC_FFMT flag in the INT_SOURCE register 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.    Regards, Tomas
記事全体を表示
  LGA 8 PACKAGE 5.0 mm x 3.0 mm x 1.1 mm  
記事全体を表示
Hi Everyone, In this document I would like to present a simple example code I created for the FRDMKL25-P3115 kit using the KDS 3.0.2 and KSDK 2.0. I will not cover the Sensor Toolbox – CE and Intelligent Sensing Framework (ISF) which primarily support this kit. The FreeMASTER tool is used to visualize both the pressure/altitude and temperature data that are read from the MPL3115A2 using an interrupt technique through the I 2 C interface. This example illustrates: 1. Initialization of the MKL25Z128 MCU (mainly PORT and I 2 C modules). 2. I 2 C data write and read operations. 3. Initialization of the MPL3115A2. 4. Output data reading using an interrupt technique. 5. Conversion of the output values from registers 0x01 – 0x05 to real values in Pascals/meters and °C 6. Visualization of the calculated values in the FreeMASTER tool. 1. As you can see in the FRDMSTBC-P3115 schematic and the image below, with jumpers J7 and J8 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 INT1 output is connected to the PTA5 pin and configured as push-pull active-low output, so the corresponding PTA5 pin configuration is GPIO with an interrupt on falling edge. The configuration is done in the BOARD_InitPins() function. void BOARD_InitPins(void) {     CLOCK_EnableClock(kCLOCK_PortC);                                            /* Port C Clock Gate Control: Clock enabled */     CLOCK_EnableClock(kCLOCK_I2c1);                                             /* I2C1 Clock Gate Control: Clock enabled */     PORT_SetPinMux(PORTC, PIN1_IDX, kPORT_MuxAlt2);                             /* PORTC1 (pin 56) is configured as I2C1_SCL */     PORT_SetPinMux(PORTC, PIN2_IDX, kPORT_MuxAlt2);                             /* PORTC2 (pin 57) is configured as I2C1_SDA */     CLOCK_EnableClock(kCLOCK_PortA);                                            /* Port A Clock Gate Control: Clock enabled */     PORT_SetPinMux(PORTA, PIN5_IDX, kPORT_MuxAsGpio);                           /* PORTA5 (pin 31) is configured as PTA5 */     PORT_SetPinInterruptConfig(PORTA, PIN5_IDX, kPORT_InterruptFallingEdge);    /* PTA5 is configured for falling edge interrupts */     NVIC_EnableIRQ(PORTA_IRQn);                                                 /* Enable PORTA interrupt on NVIC */ } 2. The 7-bit I 2 C address of the MPL3115A2 is a fixed value 0x60 (defined in the MPL3115A2.h file) which translates to 0xC0 for a write and 0xC1 for a read. As mentioned before, the SCL line is connected to the PTC1 pin and SDA line to the PTC2 pin. The I 2 C clock frequency is 100 kHz. The I2C_Init() function is used to enable and configure the I2C1 module. void I2C_Init(void) {     i2c_master_config_t config = {     .enableMaster = true,     .enableStopHold = false,     .enableHighDrive = false,     .baudRate_Bps = 100000,     .glitchFilterWidth = 0      };     I2C_MasterInit(I2C1, &config, 24000000U);     I2C_MasterTransferCreateHandle(I2C1, &p_handle, i2c_master_callback, NULL); } The screenshot below shows the write operation which writes the value 0x39 to the CTRL_REG1 register (0x26). Here is a burst read of 5 bytes from registers 0x01 to 0x05. It also shows how the INT1 pin is automatically deasserted by reading the output registers. 3. At the beginning of the initialization, all MPL3115A2 registers are reset to their default values by setting the RST bit of the CTRL_REG1 register. The DRDY interrupt is enabled and routed to the INT1 pin that is configured to be a push-pull, active-low output. Further, the OSR ratio of 128 is selected and finally the part goes into Active barometer (eventually altimeter) mode. void MPL3115A2_Init (void) {     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG1, 0x04);               /* Reset all registers to POR values */     Pause(0xC62);          // ~1ms delay     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, PT_DATA_CFG_REG, 0x07);         /* Enable data flags */     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG3, 0x00);               /* Push-pull, active low interrupt */     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG4, 0x80);               /* Enable DRDY interrupt */     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG5, 0x80);               /* DRDY interrupt routed to INT1 - PTA13 */     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG1, 0x39);               /* Active barometer mode, OSR = 128 */     //I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG1, 0xB9);             /* Active altimeter mode, OSR = 128 */ } 4. 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(void) {     PORT_ClearPinsInterruptFlags(PORTA, 1<<5);                /* Clear the interrupt flag */     DataReady = 1; } 5. In the main loop, the DataReady variable is periodically checked and if it is set, both pressure (eventually altitude) and temperature data are read and then calculated. if (DataReady)                  /* Is a new set of data ready? */ {     DataReady = 0;     I2C_ReadMultiRegisters(I2C1, MPL3115A2_I2C_ADDRESS, OUT_P_MSB_REG, RawData, 5);                      /* Read data output registers 0x01-0x05 */     /* Get pressure, the 20-bit measurement in Pascals is comprised of an unsigned integer component and a fractional component.     The unsigned 18-bit integer component is located in OUT_P_MSB, OUT_P_CSB and bits 7-6 of OUT_P_LSB.     The fractional component is located in bits 5-4 of OUT_P_LSB. Bits 3-0 of OUT_P_LSB are not used. */     Pressure = (float) (((RawData[0] << 16) | (RawData[1] << 8) | (RawData[2] & 0xC0)) >> 6) + (float) ((RawData[2] & 0x30) >> 4) * 0.25;     /* Get temperature, the 12-bit temperature measurement in °C is comprised of a signed integer component and a fractional component.     The signed 8-bit integer component is located in OUT_T_MSB. The fractional component is located in bits 7-4 of OUT_T_LSB.     Bits 3-0 of OUT_T_LSB are not used. */     Temperature = (float) ((short)((RawData[3] << 8) | (RawData[4] & 0xF0)) >> 4) * 0.0625;     /* Get altitude, the 20-bit measurement in meters is comprised of a signed integer component and a fractional component.     The signed 16-bit integer component is located in OUT_P_MSB and OUT_P_CSB.     The fraction component is located in bits 7-4 of OUT_P_LSB. Bits 3-0 of OUT_P_LSB are not used */     //Altitude = (float) ((short) ((RawData[0] << 8) | RawData[1])) + (float) (RawData[2] >> 4) * 0.0625; } 6.  The calculated values can be watched in the Debug perspective or in the FreeMASTER application. To open and run the FreeMASTER project, install the FreeMASTER 2.0 application and FreeMASTER Communication Driver. Attached you can find the complete source code written in the KDS 3.0.2 including the FreeMASTER project. If there are any questions regarding this simple application, do not hesitate to ask below. Your feedback or suggestions are also welcome. Best regards, Tomas
記事全体を表示
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
記事全体を表示
Hi Everyone, This tutorial is a detailed guide on how to import an ISSDK based example project (e.g. mma845x_interrupt) into MCUXpresso IDE, build and run it on the Freedom board (e.g. FRDM-KL27Z). If you intend to use another ISSDK example project/board, you can always follow this guide. A complete list of MCU boards, sensor kits and sensors supported by ISSDK is available in the ISSDK Release notes. 1. Download the FRDM-KL27Z SDK Open a web browser, navigate to the MCUXpresso homepage and select “Login to view configurations” to start a new configuration. You will be redirected to login to nxp.com. Enter your account information or register for a new account. Back on the MCUXpresso homepage, select the drop-down box to create a New Configuration. Select the board (FRDM-KL27Z) from the list and provide a name for the configuration. Select “Specify Additional Configuration Settings” to choose the Host OS, Toolchain (MCUXpresso IDE) and Middleware (ISSDK). Select Configuration Settings: Host OS (example: Windows) Toolchain/IDE (MCUXpresso IDE) Middleware (ISSDK) Once the configurations are set, select “Go to SDK Builder”.   Select “Request Build” to download the SDK. Once the build request is completed, download the SDK. Agree to Software Terms and Conditions. Unzip SDK to a folder (e.g. SDK_2.2.1_FRDM-KL27Z). 2. Import the SDK_2.1.1_FRDM-KL27Z into MCUXpresso IDE Open MCUXpresso IDE. Set the workspace directory of your choice and click on OK. Switch to the Installed SDKs view within the MCUXpresso IDE window. Open Windows Explorer, and drag and drop the SDK_2.2.1_FRDM-KL27Z (unzipped) file into the installed SDKs view. You will get the following pop-up so click on OK to continue the import.   The installed SDK will appear in the Installed SDKs view. 3. Import and build the ISSDK based mma845x_interrupt example project Find the Quickstart Panel in the lower left hand corner and select Import SDK example(s) Click on the FRDM-KL27Z board and then click on Next. Use the arrow button to expand the issdk_examples category, and then click the checkbox next to mma845x_interrupt to select that project. Then, click on Next. On the next screen, click the checkbox to Redirect printf/scanf to UART so that the terminal output gets sent out the UART instead of using semi-hosting through the debugger. Then click on Finish. Now build the project by clicking on the project name in the Project Explorer view and then click on the Build icon in the Quickstart Panel. You can see the status of the build in the Console view. 4. Run the mma845x_interrupt example project   Now that the project has been compiled, we can flash it to the board and run it. Make sure the FRDM-KL27Z board is plugged in, and click on Debug ‘frdmkl27z_issdk_examples_sensors_mma8451q_mma845x_interrupt’ [Debug] MCUXpresso will probe for connected boards and should find the OpenSDA debug probe that is part of the integrated OpenSDA circuit on the FRDM-KL27Z board. Click on OK to continue. The firmware will be downloaded to the board and the debugger started. Open a Terminal program (e.g. Tera Term) and connect to the FRDM-KL27Z COM port that it enumerated as. Use 115200 baud, 8 data, 1 stop, no parity. Start the application in the MCUXpresso IDE by clicking the "Resume" button. The application is now running and signed 14-bit accelerometer output values are displayed on the terminal. To modify the initial register settings of the MMA8451 accelerometer, find the mma845x_Config_Isr[] structure and change it according to your needs. Well done if you managed to follow along and get it all working. If there are any questions, do not hesitate to ask below. Your feedback or suggestions are also welcome. Regards, Tomas
記事全体を表示
Hi Everyone, In one of my previous documents I presented a simple example code/demo that reads both the altitude and temperature data from the Xtrinsic MPL3115A2 pressure sensor and visualizes them using the FreeMASTER tool via USBDM interface. This time I would like to share another example with the MPL3115A2 programmed to measure pressure (barometer mode) and temperature. The Freescale FRDM-KL25Z board coupled with the Xtrinsic MEMS sensors board was used for this project. The initialization of the Kinetis KL25Z128 MCU remains the same, the only small change is in the initialization of the MPL3115A2, this time the barometer mode is selected with the OSR of 128. void MPL3115A2_Init (void) {      unsigned char reg_val = 0;                 I2C_WriteRegister(MPL3115A2_I2C_ADDRESS, CTRL_REG1, 0x04);               // Reset all registers to POR values          do            // Wait for the RST bit to clear      {        reg_val = I2C_ReadRegister(MPL3115A2_I2C_ADDRESS, CTRL_REG1) & 0x04;      } while (reg_val);      I2C_WriteRegister(MPL3115A2_I2C_ADDRESS, PT_DATA_CFG_REG, 0x07);         // Enable data flags      I2C_WriteRegister(MPL3115A2_I2C_ADDRESS, CTRL_REG3, 0x11);               // Open drain, active low interrupts      I2C_WriteRegister(MPL3115A2_I2C_ADDRESS, CTRL_REG4, 0x80);               // Enable DRDY interrupt      I2C_WriteRegister(MPL3115A2_I2C_ADDRESS, CTRL_REG5, 0x00);               // DRDY interrupt routed to INT2 - PTD3      I2C_WriteRegister(MPL3115A2_I2C_ADDRESS, CTRL_REG1, 0x39);               // Active barometer mode, OSR = 128           } In the main loop, both pressure and temperature data are read and then calculated as follows. if (DataReady)          // Is a new set of data ready? {                  DataReady = 0;           /* Read both the pressure and temperature data */                       OUT_P_MSB = I2C_ReadRegister(MPL3115A2_I2C_ADDRESS, OUT_P_MSB_REG);             OUT_P_CSB = I2C_ReadRegister(MPL3115A2_I2C_ADDRESS, OUT_P_CSB_REG);             OUT_P_LSB = I2C_ReadRegister(MPL3115A2_I2C_ADDRESS, OUT_P_LSB_REG);             OUT_T_MSB = I2C_ReadRegister(MPL3115A2_I2C_ADDRESS, OUT_T_MSB_REG);             OUT_T_LSB = I2C_ReadRegister(MPL3115A2_I2C_ADDRESS, OUT_T_LSB_REG);                                  /* Get pressure, the 20-bit measurement in Pascals is comprised of an unsigned integer component and a fractional component.      The unsigned 18-bit integer component is located in OUT_P_MSB, OUT_P_CSB and bits 7-6 of OUT_P_LSB.      The fractional component is located in bits 5-4 of OUT_P_LSB. Bits 3-0 of OUT_P_LSB are not used.*/                       Pressure = (float) (((OUT_P_MSB << 16) | (OUT_P_CSB << 😎 | (OUT_P_LSB & 0xC0)) >> 6) + (float) ((OUT_P_LSB & 0x30) >> 4) * 0.25;                          /* Get temperature, the 12-bit temperature measurement in °C is comprised of a signed integer component and a fractional component.      The signed 8-bit integer component is located in OUT_T_MSB. The fractional component is located in bits 7-4 of OUT_T_LSB.      Bits 3-0 of OUT_T_LSB are not used. */                          Temperature = (float) ((signed char) OUT_T_MSB) + (float) (OUT_T_LSB >> 4) * 0.0625;                                                        }         As usual, the calculated values can be watched in the "Variables" window on the top right of the Debug perspective or in the FreeMASTER application. The complete source code written in the CW 10.3 as well as the FreeMASTER project is attached to this document. If there are any questions regarding this simple application, please feel free to ask below. Your feedback or suggestions are also welcome. Regards, Tomas
記事全体を表示
clicktaleID