Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Digital input management class (mwx::periph_buttons)
Detects changes in digital inputs. This class detects changes when the same detected value is obtained multiple times. This is useful for reducing the effect of chattering on mechanical buttons.
The parameter max_history
is the maximum number of references that can be set with begin()
. Memory is allocated and initialized here.
Starts the Buttons
operation, the first parameter bmPortMask
specifies the bitmap of digital inputs to be monitored. bit 0 corresponds to DIO 0, ... , bit N corresponds to DIO N. More than one can be specified: the second u8HistoryCount
is the number of times required to confirm the value; the third tick_delta
specifies the interval in ms between value checks; the fourth u8HistoryCount
is the number of times to confirm the value.
It will take u8HistoryCount*tick_delta
[ms] to confirm the value. For example, if u8HistoryCount
=5 and tick_delta
=4, it will take at least 20ms to confirm the state.
The confirmation is done in the TickTimer
event handler. Since it is not an interrupt handler, it is affected by delays in processing, etc., but it is sufficient to suppress chattering of mechanical buttons, etc.
Terminates the Buttons
operation.
Returns true
when a change is detected. It is cleared when read()
is executed.
Called when u32port
becomes available. u32portis the bitmap of the current input DIO and
u32changed` is the bitmap of the DIO where the change was detected.
Returns false
if Buttons is not working.
When Buttons starts to operate, the input status of DIO is not yet determined. When the value is determined, it becomes available. At this time, the MSB (bit31) of the bitmap read by read()
is set to 1.
Since this function requires the operation to be determined, it cannot be used to monitor ports whose input values change constantly.
If Buttons is in operation before Sleep, it will resume after it is restored. After resumption, initial determination is performed.
system timer (mwx::periph_ticktimer)
TickTimer is used for internal control of TWENET and is implicitly executed. The period of the timer is 1ms. Only the available()
method is defined in loop()
for the purpose of describing processing every 1ms by the TickTimer event.
Note that it is not always available in 1ms increments.
There are cases in which events are skipped due to a large delay caused by factors such as the contents of the user program description or the system's internal interrupt processing.
available()
It is set after the TickTimer interrupt occurs and becomes true
in the loop()
immediately following it. It is cleared after loop()
ends.
SPI access (using helper class)
The helper class version is a more abstract implementation. Creating a transceiver
object for reading and writing is the start of using the bus, and destroying the object is the end of using the bus.
By creating the object in the decision expression of the if statement, the validity period of the object is limited to the scope of the if clause, and the object is destroyed when it exits the if clause, at which point the bus usage termination procedure is performed.
In addition, read/write objects implement the mwx::stream
interface, allowing the use of the <<
operator, etc.
The start and end of bus usage is aligned with the validity period of the object to improve the visibility of the source code and to prevent omissions in the termination procedure, etc.
Unify read/write procedures with the mwx::stream
interface
Reading process and its termination procedure in scope if() { ... }
to do the reading with a helper class.
In the above, the x
object created by the get_rwer()
method is used to read and write one byte at a time. 1.
create x
object in if(...)
Generate the x
object in the get_rwer()
method. At the same time, set the select pin of the SPI bus. (The type is resolved with the universal reference auto&&
by type inference. 2.)
the generated x
object has a operator bool ()
defined, which is used to evaluate the decision expression, which is always true
for the SPI bus.
x
object defines uint8_t transfer(uint8_t)
method, which is called to perform 8bit read/write transfer to SPI. 4. 4.if() { ... }
Destructor of x
is called at the end of the scope to release the select pin of the SPI bus.
Obtains the worker object used to read/write the SPI bus.
Each transfers 8-bit, 16-bit, and 32-bit data, and returns the read result with the same data width as the written data width.
The int
and uint8_t
types perform 8-bit transfer.
Types uint16_t
and uint32_t
perform 16-bit and 32-bit transfers, respectively.
The transfer result is stored in an internal FIFO queue of up to 16 bytes and read by the >>
operator. Since the buffer is not large, it is assumed to be read out after each transfer.
Specify a variable with the same data width as the previous transfer.
If the result of the read is not needed, use the null_stream() object; it skips reading by the data byte specified by i. If the result of the read is not needed, use the null_stream() object.
SPI access (using member functions)
After initializing the hardware by the begin()
method, the bus can be read and written by beginTransaction()
. Executing beginTransaction()
selects the SPI select pin. Read/write is done with the transfer()
function; SPI reads and writes at the same time.
Starts the use of the bus; sets the SPI select pin.
If called with the settings
parameter given, the bus is set.
Terminates the use of the bus; releases the SPI select pin.
Reads and writes the bus. transfer()
transfers 8 bits, transfer16()
transfers 16 bits, and transfer32()
transfers 32 bits.
format input parser for serial input (mwx::serial_parser)
This built-in class is defined as a built-in object, intended to be used for format input via serial port.
It is defined as a mwx::serial_parser<mwx::alloc_heap<uint8_t>>
type that allocates buffer space for internal use from the heap at initialization (begin()
).
For details, see class serparser for details.
Class Objects
Class objects are predefined objects in the MWX library, such as the_twelite
, which handles TWENET, and objects for using peripherals.
Each object must be initialized by calling the .setup()
or .begin()
method. (Only Serial objects that use UART0 do not require initialization.)
The core class object of TWENET (mwx::twenet)
The the_twelite
object summarizes the procedures for using TWENET and includes procedures for operating the wireless microcontroller, such as basic wireless settings, sleep, and other procedures.
the_twelite
is set up in the setup()
function, which also calls the_twelite.begin()
to start the process. It is not possible to set up the_twelite
except in setup()
.
In the above example, the application ID is set, the communication channel is set, and the receiving circuit is set.
Various procedures are included.
It is also possible to register classes that handle wireless networks, classes that summarize board support, and classes that perform event-driven processing described by the user. By registering these classes, dedicated functions can be easily used. These classes are referred to as "behaviors" in this explanation.
In the above example, two types of behaviors are registered: environmental sensor pal behavior <PAL_AMB>
and simple relay network <NWK_SIMPLE>
. By registering these, hardware such as sensors on the environmental sensor pal can be easily handled. In addition, the complicated handling of wireless packets can be implicitly provided with functions such as relay processing and automatic discarding of duplicate packet arrivals.
The MWX library defines other methods in addition to those introduced here.
Act descriptions include those that are not directly related to the act description, those that are set up but do not function effectively, and those that are used internally.
<<operator
(setting)The <<
operator is used to initialize the object the_twelite
.
The following configuration class objects are used as input, and default values are applied if no configuration is made.
Set the parameter id
to the specified application ID. This is a required specification.
Reading the settings is done with uint32_t the_twelite.get_appid()
.
Set the specified channel number (11
..26
) in parameter ch
.
Reading the settings is done with uint8_t
the_twelite.get_channel()
.
Parameter pw
is set to (0
. 3
) for the radio output. The default is (3: no output attenuation).
Reading the settings is done with uint8_t the_twelite.get_tx_power()
.
If the parameter bEnable
is 1
, the receiver circuit is always activated and can receive radio packets from others. The default is 0
, which is dedicated to transmission only.
Reading the settings is done with uint8_t the_twelite.get_rx_when_idle()
.
Enables the channel manager. If multiple channels are specified, sending/receiving is performed on multiple channels; if 0 is specified for ch2 and ch3, the specification is disabled.
Reflects the setting values in interactive mode.
The items that will be reflected are as follows
app_id
channel
tx_power
Number of retransmissions when MAC ack is used
There are other settings in the MWX library code that are irrelevant to the library's functionality at this time or that may cause conflicts if set.
It is executed after preconfiguration (see <<
operator) and registration of the behavior. It is usually placed at the end of the setup()
function.
the_twelite
finished setting up
Behavior initialization
TWENET initialization is also performed after the setup()
function exits. Since many processes are to be executed after setup()
exits, do not do anything other than initialization here.
Changes channel settings. On failure, the channel is not changed and false
is returned.
Obtains the currently set channel number (11..26) from the MAC layer API.
Get the module serial number.
Put the module to sleep.
Before sleep, the on_sleep()
method of the built-in object or behavior is called to perform the pre-sleep procedure. After returning from sleep, the opposite procedure is performed by the on_wakeup()
method.
Returns true
if the return factor from sleep is the specified digital pin.
Returns true
if the wake-up timer is the wake-up factor for returning from sleep.
Resets the system. After reset, the process starts from setup()
.
Stops the watchdog timer. Stop the timer if you are going to wait for polling for a long time.
The watchdog timer is restarted each time in the main loop inside the library. It takes about 4 seconds for the timer to run out and reset.
Restart the watchdog timer.
Three behaviors can be registered with the_twelite
, and the following class objects are defined to store them.
network
: A behavior that implements a network. Normally, <NWK_SIMPLE>
is registered.
network2
: BEHAVIOR that implements networking. Use this behavior if you want another network BEHAVIOR to process packets which were not accepted by the first network
due to the data structure of the payload or other reasons. (Reference: Using NWK_LAYERED and NWK_SIMPLE together)
board
: Behaviors for board support. Procedures for using each device on the board are added.
app
: Behaviors describing user applications. Behaviors can be written in terms of interrupts, events, and state transitions using state machines. It is also easy to define multiple application descriptions and select an application with completely different behavior at startup.
settings
: Behavior for performing configuration (interactive mode). Registers <STG_STD>
.
Register behavior . Registration is done within setup()
. The return value is a reference to the object corresponding to the registered behavior.
After registration, the object is retrieved in the same way as at the time of registration.
If an incorrect behavior is specified, a panic operation (infinite loop) occurs and program operation stops.
It is not intended to declare objects of the behavior as global variables. Please use use<B>()
for each use.
However, it is possible to define a pointer to an object in a global variable and write as follows (The MWX library has a policy of minimizing the use of pointer types and using reference types, so the following description is not recommended.)
the_twelite
defines the three class objects board
, network
, and app
mentioned above, but also the following
Notification of transmission completion status.
The description of the event-driven behavior is managed by the transmit_complete()
callback.
Returns true
when the packet with the specified ID has completed transmission.
Returns true
when the packet with the specified ID has completed transmission and has been successfully sent.
Retrieve incoming packets.
In the event-driven behavior description, it is obtained in the receive()
callback.
The received packet data obtained by the read()
method is designed to be overwritten when subsequent packets are received and processed. If you read the data immediately after available()
and do some short processing, this will not be a problem, but as a general rule, read the data, copy the data needed for application use, and finish loop()
promptly. For example, a long delay()
during loop()
will cause incoming packets to be dropped.
Returns true
if there is an incoming packet that has not yet been read.
Read packets.
Read/write two-wire serial (I2C) master (mwx::periph_wire)
Reads and writes two-wire serial (I2C) master.
The mwx::periph_wire<MWX_TWOWIRE_RCVBUFF>
can be referred as TwoWire
.
The following definition types describe the types of arguments and return values.
Some APIs make calls where the STOP bit is not strictly handled.
write(), writer::operator() ()
has several arguments defined in addition to the ones described here.
fixed array type
uint8_t cmds[]={11,12};
...
Wire.write(cmds);
initializer_list<>
型
Wire.write({11,12})
Instance creation and necessary initialization is done in the library. In user code, it is made available by calling Wire.begin()
.
When using the requestFrom()
method, you can specify the size of the FIFO queue for temporary data storage. At compile time, compile the macro MWX_TWOWIRE_BUFF
with the required number of bytes. The default is 32 bytes.
Example:
-DMWX_TWOWIRE_BUFF=16
Initialize hardware.
Performing any Wire operation without initialization will cause the TWELITE radio module to hang.
When waking from sleep, if the module was operating just before sleep, it will return to the previous state.
There are two types of read/write procedures. Select and use one of them.
Member function (input/output using the following member functions)
requestFrom(), beginTransmission(), endTransmission(), write()
Helper class (stream function available)
reader, writer
Checks if the device specified by address
is responding. If the device exists, true
is returned.
The procedure is originally intended to change the bus frequency, but no action is taken.
accessing Wire (using helper class)
The helper class version is a more abstract implementation. Creating objects reader, writer
for reading and writing is the start of using the bus, and destroying the objects is the end of using the bus.
By creating the object in the decision expression of the if statement, the validity period of the object is limited to the scope of the if clause, and the object is destroyed when it exits the if clause, at which point the bus usage termination procedure is performed.
Also, read/write objects implement the mwx::stream
interface, so you can use the <<
operator, etc.
Aligning the start and end of bus usage with the validity period of objects improves the visibility of source code and prevents omissions of termination procedures.
Unification of read/write procedures by mwx::stream
interface
Loading process and its termination procedure in scope if() { ... }
in scope.
The above reads one byte at a time using the rdr
object generated by the get_readr()
method. The parameter of the method is the two-line serial ID to be read. 1.
in if(...) Create a
rdrobject in
. (The type is resolved with the universal reference auto&&
by type inference. 2.) The generated rdr
object defines an operator bool ()
, which is used to evaluate the decision expression. If communication is possible with the specified ID, true
is returned. 3. The rdr
object defines an int operator () (void)
operator, which is called to read one byte of data from the 2-wire serial bus. If the read fails, -1
is returned, and if it succeeds, the read byte value is returned. 4.
if() { ... }
The destructor of rdr
is called at the end of the scope to STOP
the two-wire serial bus.
I2C 読み出しに用いるワーカーオブジェクトを取得します。
Reading with a helper class to perform the writing process and its termination procedure in scope if() { ... }
in scope.
In the above, the wrt
object generated by the get_writer()
method is used to write one byte at a time. The method parameter is the two-line serial ID to be read.
if(...) Generate a
wrtobject in
. (The type name is resolved with auto' because it is long. 2.) The generated
wrtobject defines an
operator bool (), which is used to evaluate the decision expression. If communication is possible with the specified ID,
trueis returned. 3. The
wrtobject defines an
int operator () (void)operator, which is called to write one byte of data to the 2-wire serial bus. If it fails,
-1` is returned, and if it succeeds, the written byte value is returned. 4.
if() { ... }
The destructor of wrt
is called at the end of the scope
to STOP
the two-wire serial bus.
Obtains the worker object used for I2C export.
The int
and uint8_t
types transfer 8 bits.
Write out 1 byte.
Reads only the size of each data type.
Reads 1 byte. Returns -1 if there is an error, returns the byte value read if normal.
If b_stop
is set to true
, the STOP bit is issued on that read.
The following example shows a measurement example of the temperature/humidity sensor SHTC3 of the environmental sensor PAL.
ADC (mwx::periph_analogue.hpp)
Analogue performs ADC and acquires values. It can continuously acquire multiple channels at a time, and can do so sequentially according to a timer or other cycle.
constant | classification | Pin name in standard apps |
---|---|---|
In the standard application (App_Twelite), the pin names ADC2/ADC3 in the semiconductor data sheet are AI3/AI2 to match the TWELITE DIP. Please note this.
*1 ADC2/ADC3 pins for both digital and analog are subject to usage procedures and restrictions.
Assume no pull-up on the pin to be used before the ADC starts. If this is not done, the pull-up voltage will always be observed in the ADC.
In a normal circuit configuration, current leakage occurs during sleep. It cannot be circumvented by software description alone.
To avoid current leakage during sleep, the GND of the analog circuit section should be disconnected with a FET switch or the like and left floating during sleep. Also, before sleep, set the pin to input and pull-up state.
Initializes ADCs. setup() starts the regulator inside the semiconductor, specifies the timer device for periodic execution, and specifies the callback function to be called when all ADCs on the specified channel have completed.
The first parameter specifies the port where the ADC is to be made. The port specification is a bitmap with the bits set corresponding to the port numbers mentioned in the pin definition.For example, if you want to get the values of two pins PIN_ANALOGUE::A2
and PIN_ANALOGUE::VCC
, specify (1 <<PIN_ANALOGUE::A1 | 1<<PIN_ANALOGUE::VCC )
. You can also use pack_bits
and write pack_bits(PIN_ANALOGUE::A1,PIN_ANALOGUE::VCC)
.
After calling begin()
, the first ADC processing starts immediately, and the processing of the next pin starts from its end interrupt. When all processing is finished (if specified), the callback function is called. It waits until the next timer interrupt occurs before starting a new ADC process.
The second parameter specifies the number of timer interrupts before AC starts. For example, TickTimer
is called every 1 ms, but if you specify 16 for the parameter, it will be processed every 16 ms.
Starts ADC processing with default ADC pins (PIN_ANALOGUE::A1
, PIN_ANALOGUE::A2
). end()
resumes the interrupted ADC processing.
ADC processing is terminated and the regulator inside the semiconductor is stopped.
The value of the ADC is set to true
after the acquisition. After confirmation by this function, it is false
until the next ADC completion.
Reads ADC values. The parameter specifies the ADC pin to be read. read()
returns the read value converted to mV and read_raw() returns the ADC value (0..1023).
It is recommended to read Vcc with read()
. This is because a special conversion formula must be applied to convert from read_raw()
values to mV.
After ADC completion (available), if the value is read after a delay until near the timing when the next ADC process is executed, the next ADC value may be returned, because the ADC process is executed by an interrupt handler and the value is updated even during the loop()
process.
The ADC interrupt handler is set to periph_analogue::ADC_handler()
when setup()
is called.
If a different handler is specified by the semiconductor peripheral library, it will not work properly.
If the ADC is in cyclic execution state by begin()
, ADC processing is resumed after returning from sleep.
UART0 port of TWELITE (mwx::serial_jen)
Implement mwx::stream
and input/output with UART0 of TWELITE.
The Serial
object is initialized at system startup with UART0, 115200 bps, and the initialization process is performed in the library. On the user code, it is available from setup()
.
The Serial1
object is provided in the library, but no initialization process is performed; to enable UART1, perform the necessary initialization procedures Serial1.setup(), Serial1.begin()
.
Output may become unstable during setup(), wakeup()
just after startup or flush
process just before sleep.
Initialize objects.
Allocate memory for FIFO buffers for TX/RX
Allocating memory for TWE_tsFILE structure
Serial
(UART0) will automatically call setup()
in the library. There is no need for a user call.
Also, the buffer size of Serial
(UART0) is determined at compile time. You can change it by the macro MWX_SER_TX_BUFF
(768 if not specified) or MWX_SER_RX_BUFF
(256 if not specified).
Parameter | Description |
---|---|
Initialize hardware.
The Serial
(UART0) has an automatic begin()
call in the library. No user call is required.
The last two digits of the specified baud rate are rounded to zero. Also, due to hardware limitations, there may be an error from the specified baud rate.
When specifying 9600, 38400, or 115200, the baud rate is calculated without division. See constexpr uint16_t _serial_get_hect_baud(uint32_t baud)
for details of processing.
(Not implemented) Stop using hardware.
Get a structure in the TWE_tsFILE*
format used in the C library.
In Serial (UART), the _sSerial
structure is defined.
Wire (using member function)
The method using member functions has a relatively low level of abstraction and follows the general API system as provided by the C library. The procedures for operating the two-wire serial bus are more intuitive.
However, it is necessary to be explicitly aware of the start and end of bus usage.
Reads the specified number of bytes at once. Since the result of reading is stored in a queue, call the .read()
method immediately afterward until the queue is empty.
Parameters | Description |
---|---|
Writing is performed by the write()
method after executing beginTransmission()
. Call endTranmission()
after a series of writing is finished.
Initialize the export transfer. Call endTransmission()
as soon as the writing process is finished.
Writes one byte.
Writes a byte sequence.
Processes the end of the export.
Reads and writes the SPI bus (as Controller).
Reads and writes the SPI bus (as Controller).
Constant | Meaning |
---|---|
The procedure for using the SPI bus depends on the begin()
method.
Reads and writes the SPI bus (MASTER).
Initialize hardware.
This process is also required after sleep recovery.
Terminate the use of SPI hardware.
There are two types of read/write procedures. Select and use one of them.
Member function version (input/output using the following member functions) beginTransaction(), endTransaction(), transfer(), transfer16(), transfer32()
Helper class version (stream function available) transceiver
PulseCounter (mwx::periph_pulse_counter)
The pulse counter is a circuit that reads and counts pulses even when the microcontroller CPU is not running. There are two systems of pulse counters: PC0 is assigned to PulseCounter0
and PC1 to PulseCounter1
.
PC0 is assigned to PulseCounter0
and PC1 is assigned to PulseCounter1
.
Initializes the object and starts counting. the first parameter refct
is the count number on which interrupts and available decisions are based. When this number is exceeded, it is reported to the application. You can also set refct
to 0. In this case, it is not a sleep wake-up factor.
The second parameter edge
specifies whether the interrupt is rising (PIN_INT_MODE::RISING
) or falling (PIN_INT_MODE::FALLING
).
The third debounce
takes the values 0, 1, 2, or 3. 1, 2, or 3 settings require the same consecutive value to detect a change in value to reduce the effect of noise.
setting | number of consecutive samples | maximum detection frequency |
---|
Discontinue detection.
If the specified count (refct
in begin()
) is 0, true
is returned when the count exceeds 1.
If the specified count (refct
in begin()
) is 1 or more, true
is returned when the number of detections exceeds the specified count.
Reads the count value. Resets the count value to 0 after reading.
parameter | explanation |
---|---|
Parameters | Description |
---|---|
Parameters | Description |
---|---|
Parameters | Description |
---|---|
parameter | explanation |
---|---|
Parameters | Description |
---|---|
Parameters | Description |
---|---|
Parameters | Description |
---|---|
Parameters | Description |
---|---|
Parameters | Description |
---|---|
Parameters | Description |
---|---|
u32Periodms
Sleep duration[ms]
bPeriodic
Recalculate the next wake-up time based on the previous wake-up time. ※It may be from the current timing for reasons such as the next wake-up timing is imminent.
bRamoff
Set to true
to sleep without retaining RAM (must be reinitialized from setup()
instead of wakeup()
after wakeup)
u8Device
Designation of a wake-up timer to be used for sleep. Specify
TWENET::SLEEP_WAKETIMER_PRIMARY
orTWENET::SLEEP_WAKETIMER_SECONDARY
.
uint8_t PIN_ANALOGUE::A1 = 0
ADC1 pin
AI1
uint8_t PIN_ANALOGUE::A2 = 1
ADC2 pin
AI3
uint8_t PIN_ANALOGUE::A3 = 2
uint8_t PIN_ANALOGUE::D0 = 2
ADC3 pin (DIO0) *1
AI2
uint8_t PIN_ANALOGUE::A4 = 3
uint8_t PIN_ANALOGUE::D1 = 3
ADC4 pin (DIO1) *1
AI4
uint8_t PIN_ANALOGUE::VCC = 4
Vcc Supply voltage
bWaitInit
If true is specified, waits for initialization of the regulator inside the semiconductor.
kick_ev
Specify the timer device to be specified for cyclic execution. The following five types of devices can be specified, and AD is started in the interrupt handler except for the first time.
E_AHI_DEVICE_TICK_TIMER (TickTimer)
E_AHI_DEVICE_TIMER0 .. 4 (Timer0 .. 4)
fp_on_finish
This callback function is called from within the interrupt handler after all ADCs on the specified ports have finished, and is used when ADC measurement values are to be stored separately in a FIFO queue, etc.
buf_tx
FIFO buffer size for TX
buf_rx
FIFO buffer size for RX
speed
Specifies the baud rate of the UART.
config
When the serial_jen::E_CONF::PORT_ALT
bit is specified, UART1 is initialized with DIO14,15. If not specified, initializes UART1 with DIO11(TxD),9(RxD).
u8mode
Specifies the bus frequency. Default is 100Khz (WIRE_CONF::WIRE_100KHZ
)
The frequency is specified by WIRE_CONF::WIRE_? KHZ
and ? KHZ
can be 50
,66
,80
,100
,133
,160
,200
,266
,320
,400
.
b_portalt
Change hardware pin assignments.
u8address
I2C address to be read
length
Number of bytes read
b_send_stop=true
When true
, the STOP
bit is set at the end of reading.
return type size_type
Number of bytes read. 0
means read failure.
u8address
I2C address to be written out
Return value value
Bytes to be written.
Return value size_type
Number of bytes written. A value of 0
is an error.
*value
the byte sequence to be written
Return value size_type
Number of bytes to be written.
Return value size_type
Number of bytes written. 0 is an error.
sendStop = true
Issue the STOP bit.
Return value uint8_t
0: Success 4: Failure
const uint8_t
SPI_CONF::MSBFIRST
MSB as the first bit
const uint8_t
SPI_CONF::LSBFIRST
make LSB the first bit
const uint8_t
SPI_CONF::SPI_MODE0
set SPI MODE 0
const uint8_t
SPI_CONF::SPI_MODE1
set to SPI MODE 1
const uint8_t
SPI_CONF::SPI_MODE2
set to SPI MODE 2
const uint8_t
SPI_CONF::SPI_MODE3
set to SPI MODE 3
slave_select
Specify the SPI slave select pin to be used. 0 : DIO19
, 1 : DIO0
(DIO 19 is reserved), 2 : DIO1
(DIO 0,19 is reserved)
settings
Specifies the SPI bus setting.
The clock
[hz] specifies the SPI bus frequency. A divisor closer to the specified frequency will be selected: 16Mhz or 16Mhz divided by an even number.
bitOrder
specifies SPI_CONF::MSBFIRST
or SPI_CONF::LSBFIRST
.
dataMode
specifies SPI_CONF::SPIMODE0..3
.
addr
I2C address for reading
read_count
Number of bytes to read (specifying this value will issue a STOP bit on the last transfer); specifying 0 will result in no STOP bit (some devices may work)
addr
I2C address for writing out
| - | 100Khz |
| 2 | 3.7Khz |
| 4 | 2.2Khz |
| 8 | 1.2Khz |
EEPROM
TWELITE Reads and writes to the built-in EEPROM of the wireless microcontroller.
The built-in EEPROM has 3480 bytes available from address 0x000 to 0xEFF.
The first part is Settings (Interactive settings mode), so it is recommended to use the second half of the address when used together. The amount of space consumed by the settings (Interactive settings mode) depends on its implementation. Even with minimal settings, up to 256 bytes are used from the beginning, so use of the later addresses is recommended.
Read the data corresponding to address
from EEPROM.
No error detection.
Write value
from EEPROM to address
.
No error detection.
This function is used when you want to reduce the number of rewrites in consideration of the rewrite life of EEPROM.
Obtain a helper object to read and write using mwx::stream
described below.
stream_helper helper object mwx::stream
operators and methods. Using mwx::stream
, you can read and write integer types such as uint16_t
and uint32_t
types, read and write fixed-length array types such as uint8_t
, and format them using format()
objects.
Interfaces defined in mwx::stream
, such as the <<
operator, can be used on this object.
.seek()
is used to move the EEPROM address to 1024.
The above writes an 8-byte string (00bc614e
), a 4-byte integer (0x12ab34cd
), a 16-byte byte string (HELLO WORLD!....
), and a 1-byte terminating character.
Move the EEPROM address to 1024 using .seek()
.
Reads the data sequence written out earlier. In order, 8-byte characters, 4-byte integers, and 16-byte strings are read out using the >>
operator.
Timers, PWM (mwx::periph_timer)
The timer has two functions: to generate a software interrupt at a specified period, and to output a PWM at a specified period. 5 timers in total are available in the TWELITE radio module, from 0...4.
The name of the built-in object is Timer0..4
, but will be referred to as TimerX
on this page.
Initializes the timer. This call allocates the necessary memory space.
Starts a timer; the first parameter is the period of the timer in Hz; setting the second parameter to true
enables software interrupts; setting the third parameter to true
true` enables PWM output.
You can change the frequency with change_hz()
. The change_hz()
allows more detailed specification than the begin()
specification.
The duty ratio of PWM output can be changed with change_duty()
.
To describe the processing of the interrupt handler, specify it in the application behavior definition.
Stops the timer operation.
It becomes true
at loop()
immediately after a timer interrupt occurs, and becomes false
when loop()
ends.
Set the duty ratio. the first parameter specifies the duty ratio (a small value makes the average of the waveform closer to the GND level, a large value makes it closer to the Vcc level). the second parameter specifies the maximum duty ratio value of the duty ratio.
It is recommended that duty_max
be one of 1024,4096,16384
.
The internal calculation of the count value involves division, but only for these three values is bit shifting used, while for other values, a computationally expensive division process is performed.
Sets the frequency of the timer; the second parameter is an integer with three decimal places for the frequency. For example, to set the frequency to 10.4 Hz, specify hz=10, mil=400
.