MK22 Core:Project Transplanting Note

From Microduino Wiki
Jump to: navigation, search


Steps of Development

  • 1、Enter mbed Mainpage, and register.
  • 2、After the registeration, return to Mainpage, and click the “Compiler” on the top right corner, to enter the online compiling mode.
  • 3、After compiling, clicking “Compile” can automatically download file bin after the success of compiling and linking.
  • 4、Download JFlash:
  • 5、Download bin to MK22 through JFlash to run it.

Program Code

Notes of Transplanting Codes from Arduino to Mbed

  • Study guide about mbed won’t be said here any more, because there are many materials online.
  • You can see File:MBed Study Guide.pdf here.


  • The entry of Arduino is the setup and loop function in .ino file, and the entry of mbed is the main function in main.cpp. While(true) can be used to realize the function of function loop in Arduino in main function.
  • PinMode in Arduino needs to be changed into the instance of classes such as AnalogIn, AnalogOut, DigitalOut and DigitalIn of mbed.
  • In Arduino, analogWrite can be used to realize the output of PWM, and it should be changed into the instance of class PwmOut in mbed. In mbed, the output frequency and width of PWM both can be dynamically set through API.
  • In Arduino, class Serial is used to output serial port, and the instance of class Serial should be used to take place of it in mbed
  • Function millis and micros in Arduino should be altered into the instance of class Timer in mbed.Besides, in mbed, the effects of class Timeout and Ticker are respectively to realize single operation and timed repeat operation.
  • Function pgm_read_byte in Arduino is to read data from flash. And you can directly operate pointer uint8_t in mbed, and don’t need single function to read data from flash.
  • Wire is be used for the operation of the I2C in Arduino, and it should be taken place by the instance of class I2C in mbed.
  • The interval of taking the temperature of AM2321 is must bigger than 2s, or i2c won’t work.
  • SimpleTimer has a bug, which will result in a quick calling of two timing function. For example, setInterval(4000, sendCH4), execute function sendCH4 once every 4s, but in the actual runtime, the execution interval of sendCH4 will be less than 4s.

You can sen an email to me if you have any, and let us talk about the word of mbed.

  • About the definition of pins, you can clone mbed source code to local:
    • In the directory hal\targets\hal\TARGET_Freescale\TARGET_KSDK2_MCUS\TARGET_K22F\TARGET_FRDM, the PinNames.h file has the definition of all pins of MK22.

  • mbed has realizes the TARGET MK22.

  • Enter the directory of TARGET_Freescale, you can see mbed has realized the following specific MCU:


  • MCU not listed can’t use mbed platform now.