-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoNano.ino
65 lines (53 loc) · 1.31 KB
/
ArduinoNano.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "w25qxx_Demo.h"
#define USER_LED_PIN 13
volatile uint32_t uwTick;
void setup() {
IO_Init();
Timer2_Init();
Serial.begin(9600);
SPI.begin();
SPI.beginTransaction(SPISettings(1e5, MSBFIRST, SPI_MODE0));
sei();
Serial.println("Type \"begin\" for demo");
while (true) {
String response = Serial.readString();
if (response == "begin\n")
break;
}
}
void loop() {
if (w25qxx_Demo(w25qxx_Print))
Error_Handler();
}
static void IO_Init(void) {
/* User LED */
pinMode(USER_LED_PIN, OUTPUT);
digitalWrite(USER_LED_PIN, LOW);
/* SPI NSS */
pinMode(SPI1_CS0_PIN, OUTPUT);
digitalWrite(SPI1_CS0_PIN, HIGH);
}
static void Timer2_Init(void) {
SET_BIT(TCCR2A, 1 << WGM21); // CTC
SET_BIT(TCCR2B, 1 << CS22); // clkT2S/64 (from prescaler)
OCR2A = 250 - 1;
SET_BIT(TIMSK2, 1 << OCIE2A); // Timer/Counter2 Output Compare Match A Interrupt Enable
}
ISR(TIMER2_COMPA_vect) {
++uwTick;
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void) {
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
digitalWrite(USER_LED_PIN, HIGH);
Serial.flush();
Serial.end();
SPI.end();
cli();
while (1) {}
/* USER CODE END Error_Handler_Debug */
}