Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mpu9250_i2c IM920 BMP180 GPS millis
Revision 4:756dc42397cb, committed 2016-11-22
- Comitter:
- ryood
- Date:
- Tue Nov 22 10:05:18 2016 +0000
- Parent:
- 3:3ce322ac8193
- Child:
- 5:b0bb11afabfd
- Commit message:
- Test SDFileSystem & MCP23S17 with the same SPI bus.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ExioBufferdController.lib Tue Nov 22 10:05:18 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/ryood/code/ExioBufferdController/#cc3b65d44e9e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MCP23S17.lib Tue Nov 22 10:05:18 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/stjo2809/code/MCP23S17/#b2a44e1e54b8
--- a/SDFileSystem.lib Tue Nov 22 08:55:44 2016 +0000 +++ b/SDFileSystem.lib Tue Nov 22 10:05:18 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/neilt6/code/SDFileSystem/#e4d2567200db +https://developer.mbed.org/users/neilt6/code/SDFileSystem/#0475419924d4
--- a/main.cpp Tue Nov 22 08:55:44 2016 +0000
+++ b/main.cpp Tue Nov 22 10:05:18 2016 +0000
@@ -1,6 +1,6 @@
/*
* SDFileSystem Binary R/W Test
- *
+ *
* Library
* SDFileSystem: https://developer.mbed.org/users/neilt6/code/SDFileSystem/ Revision:26
* mbed: Revision: 124
@@ -9,12 +9,15 @@
* 2016.11.22 created
*
*/
-
+
#include "mbed.h"
#include "rtos.h"
#include "SDFileSystem.h"
-SPI Spi(PC_12, PC_11, PC_10); // SPI3: mosi, miso, sclk
+#include "ExioMcp23s17.h"
+#include "ExioInBuffer.h"
+#include "ExioBufferedIn.h"
+#include "ExioBufferedDebounceIn.h"
typedef struct {
uint8_t x;
@@ -22,84 +25,120 @@
uint8_t z;
} DataT;
+//SPI Spi(PC_12, PC_11, PC_10); // SPI3: mosi, miso, sclk
+SDFileSystem sd(PC_12, PC_11, PC_10, PA_14, "sd"); // SPI3: mosi, miso, sclk, cs
+
void writeSD(DataT* data)
{
- SDFileSystem sd(PC_12, PC_11, PC_10, PA_14, "sd"); // SPI3: mosi, miso, sclk, cs
-
//Mount the filesystem
sd.mount();
-
+
//Perform a write test
- printf("\nWriting binary data to SD card...");
+ printf("\r\nWriting binary data to SD card...");
FileHandle* file = sd.open("Test File.bin", O_WRONLY | O_CREAT | O_TRUNC);
- if (file != NULL)
- {
- if (file->write(data, sizeof(*data)) != sizeof(*data))
- {
- error("write error!\n");
+ if (file != NULL) {
+ if (file->write(data, sizeof(*data)) != sizeof(*data)) {
+ error("write error!\r\n");
}
- if (file->close())
- {
- printf("failed to close file!\n");
+ if (file->close()) {
+ printf("failed to close file!\r\n");
+ } else {
+ printf("done!\r\n");
}
- else
- {
- printf("done!\n");
- }
- }
- else
- {
- printf("failed to create file!\n");
+ } else {
+ printf("failed to create file!\r\n");
}
-
+
//Unmount the filesystem
sd.unmount();
}
void readSD(DataT* data)
{
- SDFileSystem sd(PC_12, PC_11, PC_10, PA_14, "sd"); // SPI3: mosi, miso, sclk, cs
-
//Mount the filesystem
sd.mount();
-
+
//Perform a read test
- printf("\nReading binary data from SD card...");
+ printf("\r\nReading binary data from SD card...");
FileHandle* file = sd.open("Test File.bin", O_RDONLY);
- if (file != NULL)
- {
- if (file->read(data, sizeof(*data)) != sizeof(*data))
- {
- error("read error!\n");
+ if (file != NULL) {
+ if (file->read(data, sizeof(*data)) != sizeof(*data)) {
+ error("read error!\r\n");
}
- if (file->close())
- {
- printf("failed to close file!\n");
+ if (file->close()) {
+ printf("failed to close file!\r\n");
+ } else {
+ printf("done!\r\n");
}
- else
- {
- printf("done!\n");
- }
- }
- else
- {
- printf("failed to open file!\n");
+ } else {
+ printf("failed to open file!\r\n");
}
-
+
//Unmount the filesystem
sd.unmount();
}
-
+
int main()
{
- DataT data, rdata;
-
+ DataT data, rdata;
+
data.x = 0xff;
data.y = 0x55;
data.z = 0xaa;
+
+ printf("*** Test SDFileSystem & ExioBufferedDebounceIn ***\r\n");
+ // ExioMcp23s17(int hardwareaddress, SPI& spi, PinName nCs, PinName nReset);
+ ExioMcp23s17 Exio(0x00, *sd.SpiPointer(), PD_2, PA_13);
+
+ // Reset MCP23S17 (初期化時にreset()が必要)
+ Exio.reset();
+
+ ExioInBuffer inBufferB(&Exio, ExioPortB);
+ ExioBufferedDebounceIn inB[] = {
+ ExioBufferedDebounceIn(&inBufferB, 0),
+ ExioBufferedDebounceIn(&inBufferB, 1),
+ ExioBufferedDebounceIn(&inBufferB, 2),
+ ExioBufferedDebounceIn(&inBufferB, 3),
+ ExioBufferedDebounceIn(&inBufferB, 4),
+ ExioBufferedDebounceIn(&inBufferB, 5),
+ ExioBufferedDebounceIn(&inBufferB, 6),
+ ExioBufferedDebounceIn(&inBufferB, 7)
+ };
+
+ // Start Timers
+ inBufferB.run(10);
+ for (int i = 0; i < 8; i++) {
+ inB[i].set_debounce_us(10000);
+ }
+
+ // SDカードの読み書きの前にExioのSPIアクセスを停止
+ inBufferB.stop();
+
writeSD(&data);
readSD(&rdata);
- printf("data: x:%02x y:%02x z:%02x\n", rdata.x, rdata.y, rdata.z);
+ // ExioのSPIアクセスを再開
+ inBufferB.run(10);
+
+ printf("data: x:%02x y:%02x z:%02x\r\n", rdata.x, rdata.y, rdata.z);
+
+ while(1) {
+ uint8_t x = 0;
+ for (int i = 0; i < 8; i++) {
+ int vb = inB[i].read();
+ x |= (vb << i);
+ }
+ if (x != 0 && data.x != x) {
+ data.x = x;
+ printf("Write to SD: x:%02x y:%02x z:%02x\r\n", data.x, data.y, data.z);
+ // SDカードの読み書きの前にExioのSPIアクセスを停止
+ inBufferB.stop();
+ writeSD(&data);
+ readSD(&rdata);
+ // ExioのSPIアクセスを再開
+ inBufferB.run(10);
+ printf("Read from SD: x:%02x y:%02x z:%02x\r\n", rdata.x, rdata.y, rdata.z);
+ }
+ }
}