Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit b10c64a

Browse files
authored
v1.3.0
### Releases v1.3.0 1. Add [**NRF52_MBED_TimerInterrupt Library**](https://github.com/khoih-prog/NRF52_MBED_TimerInterrupt) to support **NRF52840-based board using mbed-RTOS such as Nano-33-BLE.** 2. Add support for UNO, Nano, Mini, Arduino Ethernet, Fio, BT, LilyPad, Pro, Pro Mini, NG, UNO WiFi.
1 parent a2bd42f commit b10c64a

File tree

1 file changed

+152
-30
lines changed

1 file changed

+152
-30
lines changed

README.md

+152-30
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,18 @@ This file must be copied into the directory:
228228

229229
- `~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/platform.txt`
230230

231-
6. ***To be able to automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the file [Seeeduino SAMD platform.txt](Packages_Patches/Seeeduino/hardware/samd/1.8.1) into Adafruit samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.1).
231+
6. ***To be able to automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the files in [Seeeduino SAMD core](Packages_Patches/Seeeduino/hardware/samd/1.8.1) into Adafruit samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.1).
232232

233233
Supposing the Seeeduino SAMD core version is 1.8.1. This file must be copied into the directory:
234234

235235
- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.1/platform.txt`
236+
- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.1/cores/arduino/Arduino.h`
236237

237238
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
238239
This file must be copied into the directory:
239240

240241
- `~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/platform.txt`
242+
- `~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Arduino.h`
241243

242244
7. **To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/1.9.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/1.9.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.
243245

@@ -661,15 +663,15 @@ NRF52Timer ITimer(NRF_TIMER_2);
661663
662664
// Init NRF52_ISR_Timer
663665
// Each NRF52_ISR_Timer can service 16 different ISR-based timers
664-
NRF52_ISR_Timer ISR_Timer;
666+
ISR_Timer NRF52_ISR_Timer;
665667
```
666668

667669
#### 2.2 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
668670

669671
```
670672
void TimerHandler(void)
671673
{
672-
ISR_Timer.run();
674+
NRF52_ISR_Timer.run();
673675
}
674676
675677
#define HW_TIMER_INTERVAL_MS 50L
@@ -717,10 +719,10 @@ void setup()
717719
718720
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
719721
// You can use up to 16 timer for each ISR_Timer
720-
ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
721-
ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
722-
ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
723-
ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
722+
NRF52_ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
723+
NRF52_ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
724+
NRF52_ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
725+
NRF52_ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
724726
}
725727
```
726728

@@ -775,15 +777,15 @@ SAMDTimer ITimer0(TIMER_TC3);
775777
776778
// Init SAMD_ISR_Timer
777779
// Each SAMD_ISR_Timer can service 16 different ISR-based timers
778-
SAMD_ISR_Timer ISR_Timer;
780+
ISR_Timer SAMD_ISR_Timer;
779781
```
780782

781783
#### 2.2 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
782784

783785
```
784786
void TimerHandler(void)
785787
{
786-
ISR_Timer.run();
788+
SAMD_ISR_Timer.run();
787789
}
788790
789791
#define HW_TIMER_INTERVAL_MS 50L
@@ -831,10 +833,10 @@ void setup()
831833
832834
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
833835
// You can use up to 16 timer for each ISR_Timer
834-
ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
835-
ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
836-
ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
837-
ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
836+
SAMD_ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
837+
SAMD_ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
838+
SAMD_ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
839+
SAMD_ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
838840
}
839841
```
840842

@@ -901,9 +903,13 @@ attachDueInterrupt(TIMER1_INTERVAL_MS * 1000, TimerHandler1, "ITimer1");
901903
#### 2.2 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
902904

903905
```
906+
// Init SAMDUE_ISR_Timer
907+
// Each SAMDUE_ISR_Timer can service 16 different ISR-based timers
908+
ISR_Timer SAMDUE_ISR_Timer;
909+
904910
void TimerHandler(void)
905911
{
906-
ISR_Timer.run();
912+
SAMDUE_ISR_Timer.run();
907913
}
908914
909915
#define HW_TIMER_INTERVAL_MS 1L
@@ -961,10 +967,10 @@ void setup()
961967
962968
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
963969
// You can use up to 16 timer for each ISR_Timer
964-
ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
965-
ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
966-
ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
967-
ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
970+
SAMDUE_ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
971+
SAMDUE_ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
972+
SAMDUE_ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
973+
SAMDUE_ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
968974
}
969975
```
970976

@@ -1021,15 +1027,15 @@ TeensyTimer ITimer(TEENSY_TIMER_1);
10211027
10221028
// Init Teensy_ISR_Timer
10231029
// Each Teensy_ISR_Timer can service 16 different ISR-based timers
1024-
Teensy_ISR_Timer ISR_Timer;
1030+
ISR_Timer Teensy_ISR_Timer;
10251031
```
10261032

10271033
#### 2.2 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
10281034

10291035
```
10301036
void TimerHandler(void)
10311037
{
1032-
ISR_Timer.run();
1038+
Teensy_ISR_Timer.run();
10331039
}
10341040
10351041
#define HW_TIMER_INTERVAL_MS 50L
@@ -1077,10 +1083,10 @@ void setup()
10771083
10781084
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
10791085
// You can use up to 16 timer for each ISR_Timer
1080-
ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
1081-
ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
1082-
ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
1083-
ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
1086+
Teensy_ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
1087+
Teensy_ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
1088+
Teensy_ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
1089+
Teensy_ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
10841090
}
10851091
```
10861092

@@ -1131,15 +1137,15 @@ STM32Timer ITimer(TIM1);
11311137
11321138
// Init STM32_ISR_Timer
11331139
// Each STM32_ISR_Timer can service 16 different ISR-based timers
1134-
STM32_ISR_Timer ISR_Timer;
1140+
ISR_Timer STM32_ISR_Timer;
11351141
```
11361142

11371143
#### 2.2 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
11381144

11391145
```
11401146
void TimerHandler(void)
11411147
{
1142-
ISR_Timer.run();
1148+
STM32_ISR_Timer.run();
11431149
}
11441150
11451151
#define HW_TIMER_INTERVAL_US 100L
@@ -1187,10 +1193,126 @@ void setup()
11871193
11881194
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
11891195
// You can use up to 16 timer for each ISR_Timer
1190-
ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
1191-
ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
1192-
ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
1193-
ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
1196+
STM32_ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
1197+
STM32_ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
1198+
STM32_ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
1199+
STM32_ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
1200+
}
1201+
```
1202+
1203+
---
1204+
1205+
## Usage for NRF52840-based board using mbed-RTOS such as Nano-33-BLE.
1206+
1207+
Before using any Timer, you have to make sure the Timer has not been used by any other purpose.
1208+
1209+
### 1. Using only Hardware Timer directly
1210+
1211+
#### 1.1 Init Hardware Timer
1212+
1213+
```
1214+
// Depending on the board, you can select NRF52 Hardware Timer from NRF_TIMER_1-NRF_TIMER_4 (1 to 4)
1215+
// If you select the already-used NRF_TIMER_0, it'll be auto modified to use NRF_TIMER_1
1216+
1217+
// Init NRF52 timer NRF_TIMER1
1218+
NRF52_MBED_Timer ITimer(NRF_TIMER_1);
1219+
```
1220+
1221+
#### 1.2 Set Hardware Timer Interval and attach Timer Interrupt Handler function
1222+
1223+
```
1224+
void TimerHandler(void)
1225+
{
1226+
// Doing something here inside ISR
1227+
}
1228+
1229+
#define TIMER_INTERVAL_MS 1000 // 1s = 1000ms
1230+
void setup()
1231+
{
1232+
....
1233+
1234+
// Interval in microsecs
1235+
if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler0))
1236+
Serial.println("Starting ITimer OK, millis() = " + String(millis()));
1237+
else
1238+
Serial.println("Can't set ITimer. Select another freq. or timer");
1239+
}
1240+
```
1241+
1242+
### 2. Using 16 ISR_based Timers from 1 Hardware Timers
1243+
1244+
1245+
#### 2.1 Init Hardware Timer and ISR-based Timer
1246+
1247+
```
1248+
/// Depending on the board, you can select NRF52 Hardware Timer from NRF_TIMER_1-NRF_TIMER_4 (1 to 4)
1249+
// If you select the already-used NRF_TIMER_0, it'll be auto modified to use NRF_TIMER_1
1250+
1251+
// Init NRF52 timer NRF_TIMER2
1252+
NRF52_MBED_Timer ITimer(NRF_TIMER_2);
1253+
1254+
// Init NRF52_ISR_Timer
1255+
// Each NRF52_ISR_Timer can service 16 different ISR-based timers
1256+
ISR_Timer NRF52_ISR_Timer;
1257+
```
1258+
1259+
#### 2.2 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
1260+
1261+
```
1262+
void TimerHandler(void)
1263+
{
1264+
NRF52_ISR_Timer.run();
1265+
}
1266+
1267+
#define HW_TIMER_INTERVAL_MS 50L
1268+
1269+
#define TIMER_INTERVAL_2S 2000L
1270+
#define TIMER_INTERVAL_5S 5000L
1271+
#define TIMER_INTERVAL_11S 11000L
1272+
#define TIMER_INTERVAL_101S 101000L
1273+
1274+
// In NRF52, avoid doing something fancy in ISR, for example complex Serial.print with String() argument
1275+
// The pure simple Serial.prints here are just for demonstration and testing. Must be eliminate in working environment
1276+
// Or you can get this run-time error / crash
1277+
void doingSomething2s()
1278+
{
1279+
// Doing something here inside ISR
1280+
}
1281+
1282+
void doingSomething5s()
1283+
{
1284+
// Doing something here inside ISR
1285+
}
1286+
1287+
void doingSomething11s()
1288+
{
1289+
// Doing something here inside ISR
1290+
}
1291+
1292+
void doingSomething101s()
1293+
{
1294+
// Doing something here inside ISR
1295+
}
1296+
1297+
void setup()
1298+
{
1299+
....
1300+
1301+
// Interval in microsecs
1302+
if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_MS * 1000, TimerHandler))
1303+
{
1304+
lastMillis = millis();
1305+
Serial.println("Starting ITimer OK, millis() = " + String(lastMillis));
1306+
}
1307+
else
1308+
Serial.println("Can't set ITimer correctly. Select another freq. or interval");
1309+
1310+
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
1311+
// You can use up to 16 timer for each ISR_Timer
1312+
NRF52_ISR_Timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
1313+
NRF52_ISR_Timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
1314+
NRF52_ISR_Timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
1315+
NRF52_ISR_Timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
11941316
}
11951317
```
11961318

0 commit comments

Comments
 (0)