Diogo Almeida / lora_receiver_embedios

Dependencies:   mbed SoftSerial USBDevice Buffer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * Copyright (c) 2017 Helmut Tschemernjak
00003  * 30826 Garbsen (Hannover) Germany
00004  * Licensed under the Apache License, Version 2.0);
00005  */
00006 #include "main.h"
00007 #include "USBSerial.h"
00008 //#include "BufferedSerial.h"
00009 DigitalOut myled(LED4);
00010 BufferedSerial *ser;
00011 USBSerial usb_serial;
00012 char Buffer_2[8][30];
00013 int x_y;
00014 
00015 
00016 int main() {
00017     SystemClock_Config();
00018     ser = new BufferedSerial(USBTX, USBRX);
00019     ser->baud(115200*2);
00020     ser->format(8);
00021     
00022     wait(5);
00023     while(1){
00024     x_y=Receiver();
00025     
00026     if (x_y==-3){
00027        usb_serial.printf("Saiu"); 
00028         myled=1;
00029         
00030         }
00031     }
00032     
00033 }
00034 
00035 
00036 
00037 
00038 
00039 void mode_buffer(uint8_t buf,int xx){
00040         for(int yy=0;yy<29;yy++){
00041         //Buffer_2[xx][yy] = buf[yy]; 
00042     }
00043    
00044     }
00045 
00046 
00047 void SystemClock_Config(void)
00048 {
00049 #ifdef B_L072Z_LRWAN1_LORA
00050     /* 
00051      * The L072Z_LRWAN1_LORA clock setup is somewhat differnt from the Nucleo board.
00052      * It has no LSE.
00053      */
00054     RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
00055     RCC_OscInitTypeDef RCC_OscInitStruct = {0};
00056 
00057     /* Enable HSE Oscillator and Activate PLL with HSE as source */
00058     RCC_OscInitStruct.OscillatorType      = RCC_OSCILLATORTYPE_HSI;
00059     RCC_OscInitStruct.HSEState            = RCC_HSE_OFF;
00060     RCC_OscInitStruct.HSIState            = RCC_HSI_ON;
00061     RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
00062     RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_ON;
00063     RCC_OscInitStruct.PLL.PLLSource       = RCC_PLLSOURCE_HSI;
00064     RCC_OscInitStruct.PLL.PLLMUL          = RCC_PLLMUL_6;
00065     RCC_OscInitStruct.PLL.PLLDIV          = RCC_PLLDIV_3;
00066 
00067     if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
00068         // Error_Handler();
00069     }
00070 
00071     /* Set Voltage scale1 as MCU will run at 32MHz */
00072     __HAL_RCC_PWR_CLK_ENABLE();
00073     __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
00074 
00075     /* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
00076     while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {};
00077 
00078     /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
00079     clocks dividers */
00080     RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
00081     RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
00082     RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
00083     RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
00084     RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
00085     if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
00086         // Error_Handler();
00087     }
00088 #endif
00089 }
00090 
00091 void dump(const char *title, const void *data, int len, bool dwords)
00092 {
00093     dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len);
00094 
00095     int i, j, cnt;
00096     unsigned char *u;
00097     const int width = 16;
00098     const int seppos = 7;
00099 
00100     cnt = 0;
00101     u = (unsigned char *)data;
00102     while (len > 0) {
00103         ser->printf("%08x: ", (unsigned int)data + cnt);
00104         if (dwords) {
00105             unsigned int *ip = ( unsigned int *)u;
00106             ser->printf(" 0x%08x\r\n", *ip);
00107             u+= 4;
00108             len -= 4;
00109             cnt += 4;
00110             continue;
00111         }
00112         cnt += width;
00113         j = len < width ? len : width;
00114         for (i = 0; i < j; i++) {
00115             ser->printf("%2.2x ", *(u + i));
00116             if (i == seppos)
00117                 ser->putc(' ');
00118         }
00119         ser->putc(' ');
00120         if (j < width) {
00121             i = width - j;
00122             if (i > seppos + 1)
00123                 ser->putc(' ');
00124             while (i--) {
00125                 printf("%s", "   ");
00126             }
00127         }
00128         for (i = 0; i < j; i++) {
00129             int c = *(u + i);
00130             if (c >= ' ' && c <= '~')
00131                 ser->putc(c);
00132             else
00133                 ser->putc('.');
00134             if (i == seppos)
00135                 ser->putc(' ');
00136         }
00137         len -= width;
00138         u += width;
00139         ser->printf("\r\n");
00140     }
00141     ser->printf("--\r\n");
00142 }