air101#

This chapter describes how to use the mcu library of LuatOS

Introduction#

mcu library encapsulates some special operations corresponding to mcu

Hardware preparation#

Air101 Development Board

Software part#

Interface documentation can be referred to:mcu library

Set the main frequency and query the set main frequency#

air101 The main frequency that can be set is as follows. Generally speaking, the lower the main frequency, the lower the power consumption

  • 2MHz

  • 40MHz

  • 80MHz

  • 160MHz

  • 240MHz

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
function test()
    -- When the clock frequency is set to 2MHz, the log port needs to set the baud rate 115200
    uart.setup(0, 115200)
    log.info(PROJECT .. ".setClk", mcu.setClk(2))
    log.info(PROJECT .. ".getClk", mcu.getClk())
    log.info(PROJECT .. ".setClk", mcu.setClk(40))
    log.info(PROJECT .. ".getClk", mcu.getClk())
    log.info(PROJECT .. ".setClk", mcu.setClk(80))
    log.info(PROJECT .. ".getClk", mcu.getClk())
    log.info(PROJECT .. ".setClk", mcu.setClk(160))
    log.info(PROJECT .. ".getClk", mcu.getClk())
    log.info(PROJECT .. ".setClk", mcu.setClk(240))
    log.info(PROJECT .. ".getClk", mcu.getClk())
end
sys.taskInit(test)
sys.run()

The log is as follows

I/user.mcu.setClk true
I/user.mcu.getClk 2
I/user.mcu.setClk true
I/user.mcu.getClk 40
I/user.mcu.setClk true
I/user.mcu.getClk 80
I/user.mcu.setClk true
I/user.mcu.getClk 160
I/user.mcu.setClk true
I/user.mcu.getClk 240

Get Device Unique id#

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
function test()
    log.info(PROJECT .. ".unique_id", mcu.unique_id():toHex())
end
sys.taskInit(test)
sys.run()

The log is as follows

I/user.mcu.unique_id 6808454646333A0CBB8E 20

Get the number of ticks after startup and the number of ticks per second#

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
function test()
    log.info(PROJECT .. ".ticks1", mcu.ticks())
    log.info(PROJECT .. ".hz", mcu.hz())
    sys.wait(5000)
    log.info(PROJECT .. ".ticks2", mcu.ticks())
end
sys.taskInit(test)
sys.run()

The log is as follows

I/user.mcu.ticks1 35
-- 1S 1000 One tick
I/user.mcu.hz 1000
-- There are 5000 more tick queries after 5S delay than the first query.tick
I/user.mcu.ticks2 5037

Convert decimal number to hexadecimal string output#

The code is as follows

PROJECT = "mcu"
VERSION = "1.0.0"
sys = require("sys")
function test()
    -- Maximum conversion of 4 bytes of numbers
    log.info(PROJECT .. ".x32", mcu.x32(305419896)) -- 0x12345678
end
sys.taskInit(test)
sys.run()

The log is as follows

I/user.mcu.x32 0x12345678