A Nucleo program using a CC3000 wifi chip to ping

Dependencies:   NVIC_set_all_priorities TextLCD cc3000_hostdriver_mbedsocket mbed

Files at this revision

API Documentation at this revision

Comitter:
MarcoAmerena
Date:
Thu Jul 10 12:26:06 2014 +0000
Commit message:
NucleoWifi 1.1

Changed in this revision

NVIC_set_all_priorities.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
cc3000_hostdriver_mbedsocket.lib Show annotated file Show diff for this revision Revisions of this file
init.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NVIC_set_all_priorities.lib	Thu Jul 10 12:26:06 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MarcoAmerena/code/NVIC_set_all_priorities/#2a99ff9f16e8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Thu Jul 10 12:26:06 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cc3000_hostdriver_mbedsocket.lib	Thu Jul 10 12:26:06 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/#ca8c234997c0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/init.cpp	Thu Jul 10 12:26:06 2014 +0000
@@ -0,0 +1,61 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "main.h"
+#include "mbed.h"
+#include "NVIC_set_all_priorities.h"
+
+#if (MY_BOARD == WIGO)
+void init() 
+{
+    DigitalOut PWR_EN1(PTB2);
+    DigitalOut PWR_EN2(PTB3);
+
+    // Wi-Go set current to 500mA since we're turning on the Wi-Fi
+    PWR_EN1 = 0;
+    PWR_EN2 = 1;
+
+    NVIC_set_all_irq_priorities(3);
+    NVIC_SetPriority(SPI0_IRQn, 0x0);     // Wi-Fi SPI interrupt must be higher priority than SysTick
+    NVIC_SetPriority(PORTA_IRQn, 0x1);
+    NVIC_SetPriority(SysTick_IRQn, 0x2);  // SysTick set to lower priority than Wi-Fi SPI bus interrupt
+    PORTA->PCR[16] |=PORT_PCR_ISF_MASK;
+    PORTA->ISFR |= (1 << 16);
+}
+
+#elif (MY_BOARD == WIFI_DIPCORTEX)
+void init() 
+{
+    NVIC_SetPriority(SSP1_IRQn, 0x0);
+    NVIC_SetPriority(PIN_INT0_IRQn, 0x1);
+
+    // SysTick set to lower priority than Wi-Fi SPI bus interrupt
+    NVIC_SetPriority(SysTick_IRQn, 0x2);
+}
+
+#elif (MY_BOARD == WIFI_SHIELD_ADAFRUIT)
+void init() 
+{
+    NVIC_SetPriority(SPI1_IRQn, 0x0);
+    NVIC_SetPriority(FPU_IRQn, 0x1);
+    NVIC_SetPriority(SysTick_IRQn, 0x2);
+}
+
+#else
+void init()
+{
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 10 12:26:06 2014 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "cc3000.h"
+#include "main.h"
+
+
+using namespace mbed_cc3000;
+
+#if (MY_BOARD == WIFI_SHEILD_ADAFRUIT)
+cc3000 wifi(PB_3, PB_4, PB_6, SPI(PA_7, PA_6, PA_5), "SSID", "PASSWORD", WPA, false); //irq, en, cs, spi, irq-port
+Serial pc(USBTX, USBRX); // tx, rx
+#endif
+
+TextLCD lcd(PC_8, PC_6, PC_5, PB_15, PB_14, PB_12); // rs, e, d4-d7
+DigitalOut led(PC_10);
+
+int main() 
+{
+    lcd.cls();
+    lcd.printf("CC3000 Ping");
+    
+    led = 0;
+    wifi.init();
+    
+    if (wifi.connect(5000) == false) 
+    {
+        lcd.locate(0, 0);
+        lcd.printf("Return 1");
+    } 
+    else 
+    {
+        lcd.cls();
+        lcd.locate(0, 0);
+        lcd.printf("IP address:");
+        lcd.locate(0, 1);
+        lcd.printf("%s",wifi.getIPAddress());
+    }
+    
+     wait(5);
+    
+    uint32_t ip;
+    uint8_t *site = (uint8_t *)"google.com";
+    
+    printf("IP of %s ",site);
+    if (wifi._socket.gethostbyname(site,strlen((const char *)site), &ip)) 
+    {
+        uint8_t add0 = (ip >> 24);
+        uint8_t add1 = (ip >> 16);
+        uint8_t add2 = (ip >> 8);
+        uint8_t add3 = (ip >> 0);
+        printf("IP address of %s: %d:%d:%d:%d \r\n", site, add0, add1, add2, add3);
+        led = 1;
+    } 
+    else 
+    {
+        lcd.locate(0, 0);
+        lcd.printf("Return 2");
+    }
+    wait(3);
+
+    printf("Starting sending ping. \r\n");
+    uint32_t reply_count = wifi.ping(ip, 5, 500, 32);
+    lcd.cls();
+    lcd.locate(0, 0);
+    lcd.printf("Recieved:");
+    lcd.locate(0, 1);
+    lcd.printf("%d", reply_count);
+    printf("Ping demo completed. \r\n");
+    wifi.disconnect();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Thu Jul 10 12:26:06 2014 +0000
@@ -0,0 +1,26 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef MAIN_H
+#define MAIN_H
+
+#define WIGO           1
+#define WIFI_DIPCORTEX 2
+#define WIFI_SHEILD_ADAFRUIT    3
+
+#define MY_BOARD WIFI_SHEILD_ADAFRUIT 
+void init();
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jul 10 12:26:06 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae
\ No newline at end of file