Tsungta Wu
/
mbed_SPIS_multiByte_example_SOG
fork from Sog
Fork of mbed_SPIS_multiByte_example_SOG by
Revision 7:0ea5460e0de3, committed 2017-06-21
- Comitter:
- tsungta
- Date:
- Wed Jun 21 08:54:26 2017 +0000
- Parent:
- 6:bce37a45b9cb
- Commit message:
- Add TCP send function
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.mbedignore Wed Jun 21 08:54:26 2017 +0000 @@ -0,0 +1,1 @@ +mbed-os/features/netsocket/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NNN50_WIFI_API.lib Wed Jun 21 08:54:26 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/Delta/code/NNN50_WIFI_API/#a588c7f472ba
--- a/main.cpp Tue Jun 13 12:46:50 2017 +0000 +++ b/main.cpp Wed Jun 21 08:54:26 2017 +0000 @@ -28,12 +28,17 @@ #include "mbed.h" #include "SPISlave_multiByte.h" -//SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel +#include "EthernetInterface.h" +#include "WIFIDevice.h" + +SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel //SPISlave_multiByte device(p15, p9, p11, p29); // mosi, miso, sclk, ssel -SPISlave_multiByte device(A1, A0, A3, A2); // mosi, miso, sclk, ssel +//SPISlave_multiByte device(A1, A0, A3, A2); // mosi, miso, sclk, ssel Serial uart(USBTX, USBRX); DigitalOut myled(LED1); +char* TCP_SERVER_ADDRESS = "192.168.2.7"; +int TCP_SERVER_PORT = 1030; inline void hexview(const char *buffer, unsigned int size) { char byte[50]; @@ -68,12 +73,40 @@ uart.printf("\n"); } +void scanCallback(tstrM2mWifiscanResult result) +{ + printf("SSID: %s \n", result.au8SSID); + printf("RSSI: %i \n", result.s8rssi); +} + int main() { uart.baud(115200); uart.printf("START!"); device.format(8,0); myled = 1; + + EthernetInterface eth; + WIFIDevice wifi; + + eth.init(); + + wifi.apScan(scanCallback); + + wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "TWCYNPC0209_Mac mini", "mayday55555"); + eth.connect(); + + if(wifi.is_AP_connected()) + uart.printf("Connect Success! \n"); + else + uart.printf("Connect Fail! \n"); + + TCPSocketConnection tcp; + tcp.set_blocking(false, 1500); + tcp.connect(TCP_SERVER_ADDRESS, TCP_SERVER_PORT); + + char out_buffer[] = "Hello World"; + while(1) { uart.printf("Add: %p \r\n", device.read()); @@ -82,10 +115,12 @@ while (!device.readable()) { __WFE(); } - hexview((const char *)0x200032D0, 224); + hexview((const char *)0x20003384, 224); //hexview((const char *)ptr, 224); //uart.printf("%c\r\n",m_rx_buf[3]); + tcp.send(out_buffer, strlen(out_buffer)); + myled = !myled; wait_ms(200); }