aboutsummaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/main.cpp b/main.cpp
index 5e3ddf3..7771fa7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -6,19 +6,29 @@
static const uint8 slave_address = 0b1010001;
-#define NR_ELEMENTS 64
+#define NR_ELEMENTS 4
uint8 buf0[NR_ELEMENTS + 2] = {0x0, 0x0};
uint8 buf1[] = {0x0, 0x0};
uint8 buf2[NR_ELEMENTS];
+i2c_msg msgs[3];
+
+void toggle(void) {
+ digitalWrite(2, HIGH);
+ digitalWrite(2, LOW);
+}
+
void setup() {
- i2c_msg msgs[3];
uint32 i;
pinMode(BOARD_LED_PIN, OUTPUT);
+ pinMode(2, OUTPUT);
+ Serial2.begin(9600);
+ Serial2.println("Hello!");
+ digitalWrite(2, LOW);
- for (i = 0; i < sizeof buf0; i++) {
- buf0[i + 2] = i & 0xFF;
+ for (i = 2; i < sizeof buf0; i++) {
+ buf0[i] = i - 2;
}
i2c_master_enable(I2C1, 0);
@@ -31,6 +41,11 @@ void setup() {
i2c_master_xfer(I2C1, msgs, 1);
delay(5);
+}
+
+void loop() {
+ delay(100);
+ toggleLED();
/* Write slave address to read */
msgs[1].addr = slave_address;
msgs[1].flags = 0;
@@ -45,11 +60,6 @@ void setup() {
i2c_master_xfer(I2C1, msgs + 1, 2);
}
-void loop() {
- toggleLED();
- delay(100);
-}
-
// Force init to be called *first*, i.e. before static object allocation.
// Otherwise, statically allocated object that need libmaple may fail.
__attribute__(( constructor )) void premain() {