void plotPoint(void){ ST7735_PlotPoint(temperature); // Measured temperature if((j&(N-1))==0){ // fs sampling, fs/N samples plotted per second ST7735_PlotNextErase(); // overwrites N points on same line } j++; // counts the number of samples }
int main(void){ char* lab9greeting = "Welcome to Lab 9!"; int temp; // int Temperature = 100; // DisableInterrupts(); // PLL_Init(Bus80MHz); // //ST7735_InitR(INITR_REDTAB); // Output_Init(); // UART0 only used for debugging // ST7735_Output_Init(); // ADC0_InitSWTriggerSeq3_Ch9(); //initialize the ADC // Timer0A_Init20HzInt(); //initialize the timer // ST7735_DrawString(0,0, lab9greeting, ST7735_WHITE); // EnableInterrupts(); PLL_Init(Bus80MHz); // 80 MHz SYSCTL_RCGCGPIO_R |= 0x20; // activate port F ADC0_InitSWTriggerSeq3_Ch9(); // allow time to finish activating Timer0A_Init20HzInt(); // set up Timer0A for 100 Hz interrupts GPIO_PORTF_DIR_R |= 0x06; // make PF2, PF1 out (built-in LED) GPIO_PORTF_AFSEL_R &= ~0x06; // disable alt funct on PF2, PF1 GPIO_PORTF_DEN_R |= 0x06; // enable digital I/O on PF2, PF1 // configure PF2 as GPIO GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF00F)+0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF PF2 = 0; // turn off LED ST7735_Output_Init(); ST7735_DrawString(0,0, lab9greeting, ST7735_WHITE); //Init_Plot(); //ST7735_SetCursor(0,0); ST7735_OutString("Lab 9"); ST7735_PlotClear(1000,4000); // range from 0 to 4095 ST7735_SetCursor(0,1); ST7735_OutString("N="); ST7735_SetCursor(0,2); ST7735_OutString("T="); //ST7735_DecOut2(2500); ST7735_OutString(" C"); EnableInterrupts(); while(1){ ST7735_SetCursor(3,1); ST7735_OutUDec(ADCvalue); // 0 to 4095 if(refresh){ refresh = 0; samples++; ST7735_PlotPoint(ADCvalue); // Measured temperature if((samples&(N-1))==0){ // fs sampling, fs/N samples plotted per second ST7735_PlotNextErase(); // overwrites N points on same line } if((samples%fs)==0){ // fs sampling, 1 Hz display of numerical data //do conversion here, set it equal to temp. temp = get_temp(ADCvalue); ST7735_SetCursor(3,1); ST7735_OutUDec(ADCvalue); // 0 to 4095 ST7735_SetCursor(3,2);ST7735_DecOut2(temp); // 0.01 C } } } }
// "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers", // ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014, Volume 2, Program 11.3 int main3(void){ UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr, LocalAddr; UINT16 AddrSize = 0; INT16 SockID = 0; INT16 Status = 1; // ok UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); initClk(); // PLL 50 MHz, ADC needs PPL active 16 ST7735_InitR(INITR_REDTAB); // Initialize 17 ST7735_OutString("Internet of Things\n"); // 18 ST7735_OutString("Embedded Systems\n"); // 19 ST7735_OutString("Vol. 2, Valvano"); // 20 ST7735_PlotClear(0,4095); // range from 0 to 4095 21 sl_Start(0, 0, 0); // Initializing the CC3100 device 22 WlanConnect(); // connect to AP 23 sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, // 24 (unsigned char *)&ipV4); // 25 LocalAddr.sin_family = SL_AF_INET; // 26 LocalAddr.sin_port = sl_Htons((UINT16)PORT_NUM); // 27 LocalAddr.sin_addr.s_addr = 0; // 28 AddrSize = sizeof(SlSockAddrIn_t); // 29 while(1){ SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); // 31 Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, // 32 AddrSize); // 33 Status = sl_RecvFrom(SockID, uBuf, BUF_SIZE, 0, // 34 (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize );// 35 if((uBuf[0]==ATYPE)&&(uBuf[1]== '=')){ // 36 int i,bOk; uint32_t place; // 37 data = 0; bOk = 1; // 38 i=4; // ignore possible negative sign 39 for(place = 1000; place; place = place/10){ // 40 if((uBuf[i]&0xF0)==0x30){ // ignore spaces 41 data += place*(uBuf[i]-0x30); // 42 }else{ // 43 if((uBuf[i]&0xF0)!= ' '){ // 44 bOk = 0; // 45 } // 46 } // 47 i++; // 48 } // 49 if(bOk){ // 50 ST7735_PlotLine(data); // 51 ST7735_PlotNextErase(); // 51 } } } }
void ST7735_UpdateTemperatureGraph(uint32_t numSamples, uint16_t adcValue) { uint16_t temperature = getTemp(adcValue); // DEBUG // Magnify the plot to see the noise distribution better // ST7735_PlotPoint((temperature - 2200)*15); ST7735_PlotPoint(temperature); // Measured temperature if((numSamples&(N-1))==0){ // fs sampling, fs/N samples plotted per second ST7735_PlotNextErase(); // overwrites N points on same line } if((numSamples%FS)==0){ // fs sampling, 1 Hz display of numerical data ST7735_SetCursor(3,1); ST7735_OutUDec(adcValue); // 0 to 4095 ST7735_OutString(" "); // clear previous number ST7735_SetCursor(3,2); ST7735_sDecOut2(temperature); // 0.01 C } }
int main(void){ UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; SlSockAddrIn_t LocalAddr; UINT16 AddrSize = 0; INT16 SockID = 0; INT16 Status = 1; // ok UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); stopWDT(); // Stop WDT initClk(); // PLL 50 MHz, ADC needs PPL active Board_Init(); // initialize LaunchPad I/O ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); UARTprintf("This node is configured to receive UDP packets\n"); UARTprintf("This node should be at IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); ST7735_InitR(INITR_REDTAB); ST7735_OutString("Internet of Things\n"); ST7735_OutString("Embedded Systems\n"); ST7735_OutString("Vol. 2, Valvano"); ST7735_PlotClear(0,4095); // range from 0 to 4095 while(1){ sl_Start(0, 0, 0); /* Initializing the CC3100 device */ /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); // connect to AP /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4); UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); while(Status > 0){ UARTprintf("\nReceiving a UDP packet ..."); LocalAddr.sin_family = SL_AF_INET; LocalAddr.sin_port = sl_Htons((UINT16)PORT_NUM); LocalAddr.sin_addr.s_addr = 0; AddrSize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); if( SockID < 0 ){ UARTprintf("SockIDerror\n"); Status = -1; // error }else{ Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize); if( Status < 0 ){ sl_Close(SockID); UARTprintf("Sock Bind error\n"); }else{ Status = sl_RecvFrom(SockID, uBuf, BUF_SIZE, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize ); if( Status <= 0 ){ sl_Close(SockID); UARTprintf("Receive error %d ",Status); }else{ LED_Toggle(); sl_Close(SockID); UARTprintf("ok %s ",uBuf); if((uBuf[0]==ATYPE)&&(uBuf[1]== '=')){ int i,bOk; uint32_t place; data = 0; bOk = 1; i=4; // ignore possible negative sign for(place = 1000; place; place = place/10){ if((uBuf[i]&0xF0)==0x30){ // ignore spaces data += place*(uBuf[i]-0x30); }else{ if((uBuf[i]&0xF0)!= ' '){ bOk = 0; } } i++; } if(bOk){ ST7735_PlotLine(data); ST7735_PlotNextErase(); } } } } } ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 120ms } } }