gs fan
/
gswifi_spi_bridge
GainSpan Wi-Fi module, test for SPI interface.
main.cpp@0:de199215b4c0, 2014-04-03 (annotated)
- Committer:
- gsfan
- Date:
- Thu Apr 03 14:05:40 2014 +0000
- Revision:
- 0:de199215b4c0
- Child:
- 1:de94ad0f7925
1st build
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsfan | 0:de199215b4c0 | 1 | #include "mbed.h" |
gsfan | 0:de199215b4c0 | 2 | |
gsfan | 0:de199215b4c0 | 3 | DigitalOut myled(LED1); |
gsfan | 0:de199215b4c0 | 4 | Serial pc(USBTX, USBRX); |
gsfan | 0:de199215b4c0 | 5 | |
gsfan | 0:de199215b4c0 | 6 | // (GS1011MxxS / pin) |
gsfan | 0:de199215b4c0 | 7 | SPI gs(p5, p6, p7); // mosi(DIN/5), miso(DOUT/8), sck(CLK/7) |
gsfan | 0:de199215b4c0 | 8 | DigitalOut cs(p8); // cs(CS/6) |
gsfan | 0:de199215b4c0 | 9 | DigitalIn hw(p9); // host wakeup(GPIO28/2) |
gsfan | 0:de199215b4c0 | 10 | |
gsfan | 0:de199215b4c0 | 11 | int main() { |
gsfan | 0:de199215b4c0 | 12 | char c; |
gsfan | 0:de199215b4c0 | 13 | |
gsfan | 0:de199215b4c0 | 14 | pc.baud(115200); |
gsfan | 0:de199215b4c0 | 15 | gs.format(8, 0); |
gsfan | 0:de199215b4c0 | 16 | gs.frequency(3000000); |
gsfan | 0:de199215b4c0 | 17 | hw.mode(PullDown); |
gsfan | 0:de199215b4c0 | 18 | myled = 1; |
gsfan | 0:de199215b4c0 | 19 | cs = 1; |
gsfan | 0:de199215b4c0 | 20 | |
gsfan | 0:de199215b4c0 | 21 | for (;;) { |
gsfan | 0:de199215b4c0 | 22 | if (pc.readable()) { |
gsfan | 0:de199215b4c0 | 23 | cs = 0; |
gsfan | 0:de199215b4c0 | 24 | c = gs.write(pc.getc()); |
gsfan | 0:de199215b4c0 | 25 | if (c != 0xf5) |
gsfan | 0:de199215b4c0 | 26 | pc.printf("%02x_", c); |
gsfan | 0:de199215b4c0 | 27 | cs = 1; |
gsfan | 0:de199215b4c0 | 28 | } |
gsfan | 0:de199215b4c0 | 29 | if (hw == 1) { |
gsfan | 0:de199215b4c0 | 30 | cs = 0; |
gsfan | 0:de199215b4c0 | 31 | c = gs.write(0xf5); |
gsfan | 0:de199215b4c0 | 32 | cs = 1; |
gsfan | 0:de199215b4c0 | 33 | if ((c >= 0x20 && c < 0x7f) || c == 0x0d || c == 0x0a) { |
gsfan | 0:de199215b4c0 | 34 | pc.printf("%c", c); |
gsfan | 0:de199215b4c0 | 35 | } else |
gsfan | 0:de199215b4c0 | 36 | if (c != 0xf5) { |
gsfan | 0:de199215b4c0 | 37 | pc.printf("%02x ", c); |
gsfan | 0:de199215b4c0 | 38 | } |
gsfan | 0:de199215b4c0 | 39 | } |
gsfan | 0:de199215b4c0 | 40 | } |
gsfan | 0:de199215b4c0 | 41 | } |