-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LiamSmego
committed
Mar 26, 2021
1 parent
8611e95
commit bed5067
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
peripheral_tests/flashExample/flashExample/flashExample.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include <SPIFlash.h> | ||
#include <SPI.h> | ||
//#include <Wire.h> | ||
|
||
#define CHIPSIZE MB64; | ||
uint32_t floatAddr1[2]; | ||
float testFloat1[] = { | ||
3.1415, 6.283 | ||
}; | ||
uint32_t floatAddr2[5]; | ||
float testFloat2[] = { | ||
3.1415, 444, -5.5, 6, 22 | ||
}; | ||
float readDat; | ||
|
||
SPIFlash flash(1); | ||
|
||
void getAddresses(); | ||
void writeDat(); | ||
void readDatf(); | ||
|
||
void setup(){ | ||
Serial.println("Init Flash"); | ||
flash.begin(9600); | ||
flash.eraseChip(); | ||
//seq(); | ||
getAddresses(); | ||
writeDat(); | ||
readDatf(); | ||
|
||
} | ||
|
||
void loop(){ | ||
|
||
} | ||
|
||
void getAddresses(){ | ||
for (uint8_t i = 0; i < arrayLen(floatAddr1); i++) { | ||
floatAddr1[i] = flash.getAddress(sizeof(float)); | ||
Serial.print("Float Address "); | ||
Serial.print(i); | ||
Serial.print(" : "); | ||
Serial.println(floatAddr1[i]); | ||
} | ||
for (uint8_t i = 0; i < arrayLen(floatAddr2); i++) { | ||
floatAddr2[i] = flash.getAddress(sizeof(float)); | ||
Serial.print("Float Address "); | ||
Serial.print(i); | ||
Serial.print(" : "); | ||
Serial.println(floatAddr2[i]); | ||
} | ||
} | ||
|
||
void writeDat(){ | ||
for (uint8_t i = 0; i < arrayLen(floatAddr1); i++) { | ||
if (flash.writeFloat(floatAddr1[i], testFloat1[i])) { | ||
Serial.print(testFloat1[i]); | ||
Serial.print(" written to "); | ||
Serial.println(floatAddr1[i]); | ||
} | ||
} | ||
for (uint8_t i = 0; i < arrayLen(floatAddr2); i++) { | ||
if (flash.writeFloat(floatAddr2[i], testFloat2[i])) { | ||
Serial.print(testFloat2[i]); | ||
Serial.print(" written to "); | ||
Serial.println(floatAddr2[i]); | ||
} | ||
} | ||
} | ||
|
||
void readDatf(){ | ||
for (uint8_t i = 0; i < 2; i++) { | ||
readDat=flash.readFloat(floatAddr1[i]); | ||
Serial.println(readDat); | ||
} | ||
} | ||
|
||
void seq(){ | ||
for (uint8_t i = 0; i < arrayLen(floatAddr1); i++) { | ||
floatAddr1[i] = flash.getAddress(sizeof(float)); | ||
Serial.print("Float Address "); | ||
Serial.print(i); | ||
Serial.print(" : "); | ||
Serial.println(floatAddr1[i]); | ||
} | ||
for (uint8_t i = 0; i < arrayLen(floatAddr1); i++) { | ||
if (flash.writeFloat(floatAddr1[i], testFloat1[i])) { | ||
Serial.print(testFloat1[i]); | ||
Serial.print(" written to "); | ||
Serial.println(floatAddr1[i]); | ||
} | ||
} | ||
for (uint8_t i = 0; i < arrayLen(floatAddr2); i++) { | ||
floatAddr2[i] = flash.getAddress(sizeof(float)); | ||
Serial.print("Float Address "); | ||
Serial.print(i); | ||
Serial.print(" : "); | ||
Serial.println(floatAddr2[i]); | ||
} | ||
for (uint8_t i = 0; i < arrayLen(floatAddr2); i++) { | ||
if (flash.writeFloat(floatAddr2[i], testFloat2[i])) { | ||
Serial.print(testFloat2[i]); | ||
Serial.print(" written to "); | ||
Serial.println(floatAddr2[i]); | ||
} | ||
} | ||
} |