This project serves as a template for work with the Freescale FRDM-KL46 board. Support will be added to all on-board peripherals, sensors and I/O.
Dependencies: FRDM_MMA8451Q MAG3110 TSI mbed
Fork of FRDM-KL46-Template by
Project Information:
Theory
This project has been created to serve as a template for those who wish to use the Freescale Freedom FRDM-KL46Z board. Existing drivers within mbed have been brought together and board specific configurations for certain inputs and outputs have included.
Libraries
- TSI (source: http://mbed.org/users/emilmont/code/TSI/ ) Capacitive Touch library to support the on-board Touch-Slider
- FRDM_MMA8451Q (source: http://mbed.org/users/clemente/code/FRDM_MMA8451Q/ ) Freescale MMA8451 Accelerometer connected on I2C0
- MAG3110 (source: http://mbed.org/users/mmaas/code/MAG3110/) (based on: http://mbed.org/users/SomeRandomBloke/code/MAG3110/)
TODOs
- Add support for Segment LCD - intend to use driver in example code: http://cache.freescale.com/files/32bit/software/KL46_SC.exe
Hardware Information:
FRDM-KL46Z Information
- User Guide Guide: http://cache.freescale.com/files/microcontrollers/doc/user_guide/FRDM-KL46Z_UM.pdf
- Schematics: http://cache.freescale.com/files/microcontrollers/hardware_tools/schematics/FRDM-KL46Z_SCH.pdf
Freescale Kinetis L-Series Microcontroller Information
- Kinetis KL46 Drop Page: http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=KL4x
- Kinetis KL46 Fact Sheet: http://cache.freescale.com/files/microcontrollers/doc/fact_sheet/LSERIESKL4FS.pdf
- Kinetis KL46 Reference Manual: http://cache.freescale.com/files/microcontrollers/doc/ref_manual/KL46P121M48SF4RM.pdf
- Kinetis KL46 Data Sheet: http://cache.freescale.com/files/microcontrollers/doc/data_sheet/KL46P121M48SF4.pdf
Freescale Sensor Information
MMA8451Q
MAG3110
Diff: main.cpp
- Revision:
- 4:6cb640167538
- Parent:
- 3:1e85b49a3e18
- Child:
- 6:aaf347dfd538
--- a/main.cpp Thu Dec 19 20:05:17 2013 +0000 +++ b/main.cpp Tue Dec 31 17:16:57 2013 +0000 @@ -52,7 +52,6 @@ // Include support for USB Serial console Serial pc(USBTX, USBRX); - ////////////////////////////////////////////////////////////////////// // Include support for on-board green and red LEDs #define LED_ON 0 @@ -91,6 +90,7 @@ pc.baud( 230400 ); pc.printf("Hello World\r\n"); + // Turn on pull up resistors on pushbutton inputs sw1.mode(PullUp); sw3.mode(PullUp); @@ -105,7 +105,7 @@ wait(1); - + // Get some values printf("DR_STATUS %X\r\n", mag.readReg( MAG_DR_STATUS )); printf("WHO_AM_I %X\r\n", mag.readReg( MAG_WHO_AM_I )); @@ -120,19 +120,22 @@ printf("CTRL_REG2 %X\r\n", mag.readReg( MAG_CTRL_REG2 )); - // Calibrate the magnetomoter - calXY(); + printf("Press and release SW1, rotate the board 360 degrees and then press and release SW1 to complete the calibration process.\r\n"); + + mag.calXY(PTC3, 0); + + printf("Calibration complete.\r\n"); + - // Loop: Blink LEDs, report pushbutton status, mag data, accel data while(1) { - + // Get Magnetometer data int xVal = mag.readVal(MAG_OUT_X_MSB); int yVal = mag.readVal(MAG_OUT_Y_MSB); - float heading = mag.getHeading(); - - // Do something with heading - display direction + float heading = mag.getHeading(); + + // Do something with heading - display direction printf("Heading: "); if (abs(heading) <= 22.5) printf("N "); if (abs(heading) >= 157.5) printf("S "); @@ -144,8 +147,8 @@ if (heading < -112.5 && heading > -157.5) printf("SW "); if (heading < 0) heading += 360.0; printf("%f\r\n", heading); - - + + greenLED = LED_ON; redLED = LED_OFF; @@ -163,38 +166,7 @@ void calXY() //magnetometer calibration: finding max and min of X, Y axis { - int tempXmax, tempXmin, tempYmax, tempYmin, newX, newY; - - - printf("Press and release SW1 to Initiate Mag Calibration\r\n"); - // Wait for SW1 press and release - while( sw1 == 1 ) { - } - while( sw1 == 0 ) { - } - - printf("Rotate the board 360 degrees on a level plane then press and release SW1\r\n"); - - tempXmax = tempXmin = mag.readVal(MAG_OUT_X_MSB); - tempYmax = tempYmin = mag.readVal(MAG_OUT_Y_MSB); - - while(sw1 == 1) { - - newX = mag.readVal(MAG_OUT_X_MSB); - newY = mag.readVal(MAG_OUT_Y_MSB); - if (newX > tempXmax) tempXmax = newX; - if (newX < tempXmin) tempXmin = newX; - if (newY > tempYmax) tempYmax = newY; - if (newY < tempYmin) tempYmin = newY; - } - - mag.setCalibration( tempXmin, tempXmax, tempYmin, tempYmax ); - - // Wait for release - while( sw1 == 0 ) { - } - - printf("Calibration complete.\r\n"); + }