+/EE445L
embedded systems
git clone https://git.julia.blue/+/EE445L
99480b6
master
1// ------------------------------------------------------------------- 2// File name: Blynk.c 3// Description: This code is used to bridge the TM4C123 board and the Blynk Application 4// via the ESP8266 WiFi board 5// Author: Mark McDermott and Andrew Lynch (Arduino source) 6// Converted to EE445L style Jonathan Valvano 7// Orig gen date: May 21, 2018 8// Last update: Sept 20, 2018 9// 10// Download latest Blynk library here: 11// https://github.com/blynkkk/blynk-library/releases/latest 12// 13// Blynk is a platform with iOS and Android apps to control 14// Arduino, Raspberry Pi and the likes over the Internet. 15// You can easily build graphic interfaces for all your 16// projects by simply dragging and dropping widgets. 17// 18// Downloads, docs, tutorials: http://www.blynk.cc 19// Sketch generator: http://examples.blynk.cc 20// Blynk community: http://community.blynk.cc 21// 22//------------------------------------------------------------------------------ 23 24// TM4C123 ESP8266-ESP01 (2 by 4 header) 25// PE5 (U5TX) to Pin 1 (Rx) 26// PE4 (U5RX) to Pin 5 (TX) 27// PE3 output debugging 28// PE2 nc 29// PE1 output Pin 7 Reset 30// PE0 input Pin 3 Rdy IO2 31// Pin 2 IO0, 10k pullup to 3.3V 32// Pin 8 Vcc, 3.3V (separate supply from LaunchPad 33// Gnd Pin 4 Gnd 34// Place a 4.7uF tantalum and 0.1 ceramic next to ESP8266 3.3V power pin 35// Use LM2937-3.3 and two 4.7 uF capacitors to convert USB +5V to 3.3V for the ESP8266 36// http://www.ti.com/lit/ds/symlink/lm2937-3.3.pdf 37#include <stdint.h> 38#include <string.h> 39#include <stdlib.h> 40#include "tm4c123gh6pm.h" 41#include "ST7735.h" 42#include "PLL.h" 43#include "Timer2.h" 44#include "Timer3.h" 45#include "UART.h" 46#include "PortF.h" 47#include "esp8266.h" 48 49void EnableInterrupts (void );// Defined in startup.s 50void DisableInterrupts (void );// Defined in startup.s 51void WaitForInterrupt (void );// Defined in startup.s 52 53uint32_t LED ;// VP1 54uint32_t LastF ;// VP74 55// These 6 variables contain the most recent Blynk to TM4C123 message 56// Blynk to TM4C123 uses VP0 to VP15 57char serial_buf [64 ]; 58char Pin_Number [2 ]= "99" ;// Initialize to invalid pin number 59char Pin_Integer [8 ]= "0000" ;// 60char Pin_Float [8 ]= "0.0000" ;// 61uint32_t pin_num ; 62uint32_t pin_int ; 63 64// ----------------------------------- TM4C_to_Blynk ------------------------------ 65// Send data to the Blynk App 66// It uses Virtual Pin numbers between 70 and 99 67// so that the ESP8266 knows to forward the data to the Blynk App 68void TM4C_to_Blynk (uint32_t pin ,uint32_t value ){ 69if ((pin < 70 )|| (pin > 99 )){ 70return ;// ignore illegal requests 71 } 72// your account will be temporarily halted 73// if you send too much data 74ESP8266_OutUDec (pin );// Send the Virtual Pin # 75ESP8266_OutChar (',' ); 76ESP8266_OutUDec (value );// Send the current value 77ESP8266_OutChar (',' ); 78ESP8266_OutString ("0.0\n" );// Null value not used in this example 79} 80 81 82// ------------------------- Blynk_to_TM4C ----------------------------------- 83// This routine receives the Blynk Virtual Pin data via the ESP8266 and parses the 84// data and feeds the commands to the TM4C. 85void Blynk_to_TM4C (void ){int j ;char data ; 86// Check to see if a there is data in the RXD buffer 87if (ESP8266_GetMessage (serial_buf )){// returns false if no message 88// Read the data from the UART5 89#ifdef DEBUG1 90j = 0 ; 91do { 92data = serial_buf [j ]; 93UART_OutChar (data );// Debug only 94j ++ ; 95 }while (data != '\n' ); 96UART_OutChar ('\r' ); 97#endif 98 99// Rip the 3 fields out of the CSV data. The sequence of data from the 8266 is: 100// Pin #, Integer Value, Float Value. 101strcpy (Pin_Number ,strtok (serial_buf ,"," )); 102strcpy (Pin_Integer ,strtok (NULL ,"," ));// Integer value that is determined by the Blynk App 103strcpy (Pin_Float ,strtok (NULL ,"," ));// Not used 104pin_num = atoi (Pin_Number );// Need to convert ASCII to integer 105pin_int = atoi (Pin_Integer ); 106// ---------------------------- VP #1 ---------------------------------------- 107// This VP is the LED select button 108if (pin_num == 0x01 ) { 109LED = pin_int ; 110PortF_Output (LED <<2 );// Blue LED 111#ifdef DEBUG3 112Output_Color (ST7735_CYAN ); 113ST7735_OutString ("Rcv VP1 data=" ); 114ST7735_OutUDec (LED ); 115ST7735_OutChar ('\n' ); 116#endif 117 }// Parse incoming data 118#ifdef DEBUG1 119UART_OutString (" Pin_Number = " ); 120UART_OutString (Pin_Number ); 121UART_OutString (" Pin_Integer = " ); 122UART_OutString (Pin_Integer ); 123UART_OutString (" Pin_Float = " ); 124UART_OutString (Pin_Float ); 125UART_OutString ("\n\r" ); 126#endif 127 } 128} 129 130void SendInformation (void ){ 131uint32_t thisF ; 132thisF = PortF_Input (); 133// your account will be temporarily halted if you send too much data 134if (thisF != LastF ){ 135TM4C_to_Blynk (74 ,thisF );// VP74 136#ifdef DEBUG3 137Output_Color (ST7735_WHITE ); 138ST7735_OutString ("Send 74 data=" ); 139ST7735_OutUDec (thisF ); 140ST7735_OutChar ('\n' ); 141#endif 142 } 143LastF = thisF ; 144} 145 146 147int main (void ){ 148PLL_Init (Bus80MHz );// Bus clock at 80 MHz 149DisableInterrupts ();// Disable interrupts until finished with inits 150PortF_Init (); 151LastF = PortF_Input (); 152#ifdef DEBUG3 153Output_Init ();// initialize ST7735 154ST7735_OutString ("EE445L Lab 4D\nBlynk example\n" ); 155#endif 156#ifdef DEBUG1 157UART_Init (5 );// Enable Debug Serial Port 158UART_OutString ("\n\rEE445L Lab 4D\n\rBlynk example" ); 159#endif 160ESP8266_Init ();// Enable ESP8266 Serial Port 161ESP8266_Reset ();// Reset the WiFi module 162ESP8266_SetupWiFi ();// Setup communications to Blynk Server 163 164Timer2_Init (& Blynk_to_TM4C ,800000 ); 165// check for receive data from Blynk App every 10ms 166 167Timer3_Init (& SendInformation ,40000000 ); 168// Send data back to Blynk App every 1/2 second 169EnableInterrupts (); 170 171while (1 ) { 172WaitForInterrupt ();// low power mode 173 } 174} 175 176