From 777340ab365c3ff2e53f1cafbef737999b5a43c0 Mon Sep 17 00:00:00 2001 From: df8oe Date: Tue, 6 Jun 2017 08:23:47 +0200 Subject: [PATCH 1/7] more personalization possibilities --- config.h | 5 +++-- main.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config.h b/config.h index 09b79d6..e9c5a43 100644 --- a/config.h +++ b/config.h @@ -10,8 +10,9 @@ #else //**************config************** -#define CALLSIGN "NO1LIC-1" // put your callsign here -#define APRS_CALLSIGN "NO1LIC" +#define CALLSIGN "DF8OE" // put your callsign here +#define APRS_CALLSIGN "DF8OE-10" +#define RTTY_GREETING "$$$$$$RS41 modified for amateur radio use by DF8OE, enjoy and see you on the HUB... \n\r" #define APRS_SSID 'B' #define RTTY_TO_APRS_RATIO 5 diff --git a/main.c b/main.c index 4d0fe58..23ea18e 100644 --- a/main.c +++ b/main.c @@ -36,7 +36,7 @@ int napiecie; volatile char flaga = 0;//((((tx_delay / 1000) & 0x0f) << 3) | Smoc); uint16_t CRC_rtty = 0x12ab; //checksum char buf_rtty[200]; -char menu[] = "$$$$$$STM32 RTTY tracker by Blasiu, enjoy and see you on the HUB... \n\r"; +char menu[] = RTTY_GREETING; char init_trx[] = "\n\rPowering up TX\n\r"; volatile unsigned char pun = 0; volatile unsigned int cun = 10; From faf8d3118a3e7a12345c2ad444006475e65898ef Mon Sep 17 00:00:00 2001 From: df8oe Date: Tue, 6 Jun 2017 09:23:55 +0200 Subject: [PATCH 2/7] added Linux support to cmake --- CMakeLists.txt | 14 +++++++++----- main.c | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edbf738..0984f7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,16 @@ include(CMakeForceCompiler) SET(CMAKE_SYSTEM_NAME "Generic") SET(CMAKE_SYSTEM_VERSION 1) -set(TOOLCHAIN_DIR D:/Programy/arm_gcc/bin/) - -CMAKE_FORCE_C_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-gcc.exe GNU) -CMAKE_FORCE_CXX_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-g++.exe GNU) - +if(UNIX) + set(TOOLCHAIN_DIR /opt/gcc-arm-none-eabi-5_4-2016q3/bin/) + CMAKE_FORCE_C_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-gcc GNU) + CMAKE_FORCE_CXX_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-g++ GNU) +else() + set(TOOLCHAIN_DIR D:/Programy/arm_gcc/bin/) + CMAKE_FORCE_C_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-gcc.exe GNU) + CMAKE_FORCE_CXX_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-g++.exe GNU) +endif() project(STM32_RTTY C ASM CXX) diff --git a/main.c b/main.c index 23ea18e..60350fe 100644 --- a/main.c +++ b/main.c @@ -172,8 +172,8 @@ int main(void) { radio_enable_tx(); uint8_t rtty_before_aprs_left = RTTY_TO_APRS_RATIO; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wmissing-noreturn" +//#pragma clang diagnostic push +//#pragma clang diagnostic ignored "-Wmissing-noreturn" while (1) { if (tx_on == 0 && tx_enable) { if (rtty_before_aprs_left){ @@ -197,7 +197,7 @@ int main(void) { __WFI(); } } -#pragma clang diagnostic pop +//#pragma clang diagnostic pop } void send_rtty_packet() { From b0c3512dc96f2071c172c56decc857a4ae6a8b0e Mon Sep 17 00:00:00 2001 From: df8oe Date: Tue, 6 Jun 2017 20:03:06 +0200 Subject: [PATCH 3/7] some cleanups --- CMakeLists.txt | 13 ++++++++----- aprs.cpp | 5 +++-- config.h | 2 +- main.c | 7 ------- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0984f7c..9da2a8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,21 +5,22 @@ SET(CMAKE_SYSTEM_VERSION 1) if(UNIX) - set(TOOLCHAIN_DIR /opt/gcc-arm-none-eabi-5_4-2016q3/bin/) + set(TOOLCHAIN_DIR "/opt/gcc-arm-none-eabi-5_4-2016q3/bin/") CMAKE_FORCE_C_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-gcc GNU) CMAKE_FORCE_CXX_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-g++ GNU) else() - set(TOOLCHAIN_DIR D:/Programy/arm_gcc/bin/) + set(TOOLCHAIN_DIR "D:/Programy/arm_gcc/bin/") CMAKE_FORCE_C_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-gcc.exe GNU) CMAKE_FORCE_CXX_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-g++.exe GNU) endif() -project(STM32_RTTY C ASM CXX) +project(STM32_RTTY C CXX ASM) add_definitions(-DSTM32F100C8) add_definitions(-DSTM32F10X_MD_VL) add_definitions(-DUSE_STDPERIPH_DRIVER) +add_definitions(-DSUPPORT_CPLUSPLUS) add_definitions(-D__ASSEMBLY__) @@ -28,7 +29,7 @@ SET(LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/arm-gcc-link.ld) SET(COMMON_FLAGS " -mcpu=cortex-m3 -mthumb -Wall -ffunction-sections -g -O3 -g -nostartfiles ") SET(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11") SET(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-Map=${CMAKE_BINARY_DIR}/${PROJECT_NAME}.map -O3 -Wl,--gc-sections -T ${LINKER_SCRIPT}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-Map=${CMAKE_BINARY_DIR}/${PROJECT_NAME}.map -lstdc++ -O3 -Wl,--gc-sections --specs=nano.specs -T ${LINKER_SCRIPT}") file(GLOB_RECURSE USER_SOURCES "*.c") file(GLOB_RECURSE USER_SOURCES_CXX "*.cpp") @@ -53,7 +54,9 @@ set(BIN_FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin) add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex $ ${HEX_FILE} COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${BIN_FILE} - COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}") + COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}" + COMMAND ${TOOLCHAIN_DIR}/arm-none-eabi-size ${PROJECT_NAME}.elf) + set(CMAKE_CXX_STANDARD 11) add_custom_target(program diff --git a/aprs.cpp b/aprs.cpp index 66c8923..8299752 100644 --- a/aprs.cpp +++ b/aprs.cpp @@ -61,7 +61,7 @@ void aprs_send_position(GPSEntry gpsData, int8_t temperature, uint16_t voltage) aprs_packet_counter ++; sprintf(packet_buffer, - ("!%02d%02d.%02u%c/%03d%02u.%02u%cO/A=%06ld/P%dS%dT%dV%d Hello from the sky!"), + ("!%02d%02d.%02u%c/%03d%02u.%02u%cO/A=%06ld/P%dS%dT%dV%d%s"), abs(la_degrees), la_minutes, la_h_minutes, la_degrees > 0 ? 'N' : 'S', abs(lo_degrees), lo_minutes, lo_h_minutes, @@ -70,7 +70,8 @@ void aprs_send_position(GPSEntry gpsData, int8_t temperature, uint16_t voltage) aprs_packet_counter, gpsData.sats_raw, temperature, - voltage + voltage, + APRS_COMMENT ); qaprs.sendData(packet_buffer); } diff --git a/config.h b/config.h index e9c5a43..e85ed0d 100644 --- a/config.h +++ b/config.h @@ -12,8 +12,8 @@ //**************config************** #define CALLSIGN "DF8OE" // put your callsign here #define APRS_CALLSIGN "DF8OE-10" -#define RTTY_GREETING "$$$$$$RS41 modified for amateur radio use by DF8OE, enjoy and see you on the HUB... \n\r" #define APRS_SSID 'B' +#define APRS_COMMENT "Hello from the sky!" #define RTTY_TO_APRS_RATIO 5 //*************frequency******************** diff --git a/main.c b/main.c index 60350fe..1a8f202 100644 --- a/main.c +++ b/main.c @@ -36,11 +36,8 @@ int napiecie; volatile char flaga = 0;//((((tx_delay / 1000) & 0x0f) << 3) | Smoc); uint16_t CRC_rtty = 0x12ab; //checksum char buf_rtty[200]; -char menu[] = RTTY_GREETING; -char init_trx[] = "\n\rPowering up TX\n\r"; volatile unsigned char pun = 0; volatile unsigned int cun = 10; -unsigned char dev = 0; volatile unsigned char tx_on = 0; volatile unsigned int tx_on_delay; volatile unsigned char tx_enable = 0; @@ -48,7 +45,6 @@ rttyStates send_rtty_status = rttyZero; volatile char *rtty_buf; volatile uint16_t button_pressed = 0; volatile uint8_t disable_armed = 0; -unsigned char cun_off = 0; void send_rtty_packet(); @@ -172,8 +168,6 @@ int main(void) { radio_enable_tx(); uint8_t rtty_before_aprs_left = RTTY_TO_APRS_RATIO; -//#pragma clang diagnostic push -//#pragma clang diagnostic ignored "-Wmissing-noreturn" while (1) { if (tx_on == 0 && tx_enable) { if (rtty_before_aprs_left){ @@ -197,7 +191,6 @@ int main(void) { __WFI(); } } -//#pragma clang diagnostic pop } void send_rtty_packet() { From c746fee8ff3fdab8ab7f13d262a051f35619868f Mon Sep 17 00:00:00 2001 From: df8oe Date: Fri, 9 Jun 2017 11:00:58 +0200 Subject: [PATCH 4/7] better documentation in config.h, beginning of renaming variables to english --- config.h | 54 +++++++++++++++++++++++++++++++++++++++--------------- main.c | 4 ++-- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/config.h b/config.h index b1f5856..e693554 100644 --- a/config.h +++ b/config.h @@ -9,30 +9,54 @@ #include "config_external.h" #else -//**************config************** -#define CALLSIGN "DF8OE" // put your callsign here -#define APRS_CALLSIGN "DF8OE-10" -#define APRS_SSID 'B' +//**************config********************** +#define CALLSIGN "DF8OE" // put your RTTY callsign here +#define APRS_CALLSIGN "DF8OE" // put your APRS callsign here +#define APRS_SSID 'B' // put your APRS SSID here +// 0 --> Your primary station usually fixed and message capable +// 1 --> generic additional station, digi, mobile, wx, etc. +// 2 --> generic additional station, digi, mobile, wx, etc. +// 3 --> generic additional station, digi, mobile, wx, etc. +// 4 --> generic additional station, digi, mobile, wx, etc. +// 5 --> Other network sources (Dstar, Iphones, Blackberry's etc) +// 6 --> Special activity, Satellite ops, camping or 6 meters, etc. +// 7 --> walkie talkies, HT's or other human portable +// 8 --> boats, sailboats, RV's or second main mobile +// 9 --> Primary Mobile (usually message capable) +// 10 --> internet, Igates, echolink, winlink, AVRS, APRN, etc. +// 11 --> balloons, aircraft, spacecraft, etc. +// 12 --> APRStt, DTMF, RFID, devices, one-way trackers*, etc. +// 13 --> Weather stations +// 14 --> Truckers or generally full time drivers +// 15 --> generic additional station, digi, mobile, wx, etc. + #define APRS_COMMENT " Hello from the sky!" -#define RTTY_TO_APRS_RATIO 5 +#define RTTY_TO_APRS_RATIO 5 //transmit APRS packet with each x RTTY packet //*************frequency******************** #define RTTY_FREQUENCY 434.500f //Mhz middle frequency #define APRS_FREQUENCY 432.500f //Mhz middle frequency -//************rtty speed****************** si4032 -#define RTTY_SPEED 300 -// SHITY -> 450Hz -//************rtty bits****************** si4032 -#define RTTY_7BIT 1 -//************rtty stop bits****************** si4032 +//************rtty speed*********************** si4032 +#define RTTY_SPEED 75 // RTTY baudrate +// SHIFT is always 450Hz +//************rtty bits************************ si4032 +#define RTTY_7BIT 1 // if 0 --> 5 bits +//************rtty stop bits******************* si4032 #define RTTY_USE_2_STOP_BITS 0 //********* power definition************************** -#define Smoc 7 // PWR 0...7 0- MIN ... 7 - MAX -// 7 -> 42.95 mW@434.150 MHz na E4406A -//*************************************************** +#define TX_POWER 0 // PWR 0...7 0- MIN ... 7 - MAX +// 0 --> -8dBm +// 1 --> -5dBm +// 2 --> -2dBm +// 3 --> 1dBm +// 4 --> 4dBm +// 5 --> 7dBm +// 6 --> 10dBm +// 7 --> 13dBm +//**************************************************** // WARNING: do not use this in flying tracker! #define ALLOW_DISABLE_BY_BUTTON 1 -//********** frame delay in msec********** +//********** frame delay in msec********************** #define tx_delay 5000 #endif diff --git a/main.c b/main.c index 7314437..68341a8 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,7 @@ unsigned int send_cun; //frame counter char status[2] = {'N'}; int napiecie; -volatile char flaga = 0;//((((tx_delay / 1000) & 0x0f) << 3) | Smoc); +volatile char flaga = 0;//((((tx_delay / 1000) & 0x0f) << 3) | TX_POWER); uint16_t CRC_rtty = 0x12ab; //checksum char buf_rtty[200]; @@ -149,7 +149,7 @@ int main(void) { radio_set_tx_frequency(RTTY_FREQUENCY); // Programowanie mocy nadajnika - radio_rw_register(0x6D, 00 | (Smoc & 0x0007), 1); + radio_rw_register(0x6D, 00 | (TX_POWER & 0x0007), 1); radio_rw_register(0x71, 0x00, 1); radio_rw_register(0x87, 0x08, 0); From 6426f48ff37a7498fe90634133eb63c1e1be7809 Mon Sep 17 00:00:00 2001 From: df8oe Date: Fri, 9 Jun 2017 13:34:48 +0200 Subject: [PATCH 5/7] some more refactorings, adding license text as original author's license wish --- LICENSE.txt | 75 ++++++++ README.md | 7 + f_rtty.c | 74 ++++---- f_rtty.h | 24 +-- init.c | 490 ++++++++++++++++++++++++------------------------- init.h | 42 ++--- main.c | 514 ++++++++++++++++++++++++++++------------------------ radio.c | 4 +- 8 files changed, 676 insertions(+), 554 deletions(-) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..f21e37e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,75 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the \ No newline at end of file diff --git a/README.md b/README.md index d3fc3c4..8f3d7ab 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,19 @@ # STM32_RTTY STM32 & SI4032 rtty test +Released under GPL v2 + Use: https://www.wyzbee.com/download/Utilities/Software/CoIDE-1.7.8.exe And: https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-win32.exe +Using Linux: +cd into main folder +cmake . +make + Have a nice day ;) #Changelog diff --git a/f_rtty.c b/f_rtty.c index d22b9c4..eb7e81d 100644 --- a/f_rtty.c +++ b/f_rtty.c @@ -1,37 +1,37 @@ -#include "f_rtty.h" - -uint8_t start_bits; -rttyStates send_rtty(char *znak) { - static uint8_t nr_bit = 0; - nr_bit++; - if (start_bits){ - start_bits--; - return rttyOne; - } - - if (nr_bit == 1) { - return rttyZero; - } - if (nr_bit > 1 && nr_bit < (RTTY_7BIT ? 9 : 10)) { - if ((*(znak) >> (nr_bit - 2)) & 0x01) { - return rttyOne; - } else { - return rttyZero; - } - } - - #ifdef RTTY_7BIT - nr_bit++; - #endif - - if (nr_bit == 10) { - return rttyOne; - } - #ifdef RTTY_USE_2_STOP_BITS - if (nr_bit == 11) { - return rttyOne; - } - #endif - nr_bit = 0; - return rttyEnd; -} +#include "f_rtty.h" + +uint8_t start_bits; +rttyStates send_rtty(char *znak) { + static uint8_t nr_bit = 0; + nr_bit++; + if (start_bits){ + start_bits--; + return rttyOne; + } + + if (nr_bit == 1) { + return rttyZero; + } + if (nr_bit > 1 && nr_bit < (RTTY_7BIT ? 9 : 10)) { + if ((*(znak) >> (nr_bit - 2)) & 0x01) { + return rttyOne; + } else { + return rttyZero; + } + } + + #ifdef RTTY_7BIT + nr_bit++; + #endif + + if (nr_bit == 10) { + return rttyOne; + } + #ifdef RTTY_USE_2_STOP_BITS + if (nr_bit == 11) { + return rttyOne; + } + #endif + nr_bit = 0; + return rttyEnd; +} diff --git a/f_rtty.h b/f_rtty.h index 92c7d40..11e0fbc 100644 --- a/f_rtty.h +++ b/f_rtty.h @@ -1,12 +1,12 @@ -#include -#include "config.h" - -typedef enum { - rttyZero = 0, - rttyOne = 1, - rttyEnd = 2 -} rttyStates; -static const uint8_t RTTY_PRE_START_BITS = 10; - -rttyStates send_rtty(char *znak); -extern uint8_t start_bits; \ No newline at end of file +#include +#include "config.h" + +typedef enum { + rttyZero = 0, + rttyOne = 1, + rttyEnd = 2 +} rttyStates; +static const uint8_t RTTY_PRE_START_BITS = 10; + +rttyStates send_rtty(char *znak); +extern uint8_t start_bits; diff --git a/init.c b/init.c index 979af2d..ca1a028 100644 --- a/init.c +++ b/init.c @@ -1,246 +1,246 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "init.h" -#include "radio.h" - -SPI_InitTypeDef SPI_InitStructure; -USART_InitTypeDef USART_InitStructure; -GPIO_InitTypeDef GPIO_Conf; -ADC_InitTypeDef ADC_InitStructure; -DMA_InitTypeDef DMA_InitStructure; - - -#define ADC1_DR_Address ((uint32_t)0x4001244C) -#if defined(STM32F10X_CL) -#error "Bedzie problem z kwarcem!" -#endif -void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) { - NVIC_DisableIRQ(USART1_IRQn); - USART_ITConfig(USART1, USART_IT_RXNE, DISABLE); - USART_ClearITPendingBit(USART1, USART_IT_RXNE); - USART_ClearITPendingBit(USART1, USART_IT_ORE); - - USART_Cmd(USART1, DISABLE); - - RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);// | RCC_APB2Periph_AFIO, ENABLE); - USART_InitStructure.USART_BaudRate = speed; //0x9c4; - USART_InitStructure.USART_WordLength = USART_WordLength_8b; - USART_InitStructure.USART_StopBits = USART_StopBits_1; - USART_InitStructure.USART_Parity = USART_Parity_No; - USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; - USART_Init(USART1, &USART_InitStructure); - - NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure - NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - - USART_Cmd(USART1, ENABLE); - if (enable_irq){ - USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); - NVIC_EnableIRQ(USART1_IRQn); - } -} - -void init_usart_debug() { - NVIC_DisableIRQ(USART3_IRQn); - USART_Cmd(USART3, DISABLE); - - RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);// | RCC_APB2Periph_AFIO, ENABLE); - USART_InitStructure.USART_BaudRate = 19200; //0x9c4; - USART_InitStructure.USART_WordLength = USART_WordLength_8b; - USART_InitStructure.USART_StopBits = USART_StopBits_1; - USART_InitStructure.USART_Parity = USART_Parity_No; - USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; - USART_Init(USART3, &USART_InitStructure); - USART_Cmd(USART3, ENABLE); -} - -void NVIC_Conf() -{ -#ifdef VECT_TAB_RAM - NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); -#else // VECT_TAB_FLASH - NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); -#endif -} - -void RCC_Conf() -{ - ErrorStatus HSEStartUpStatus; - RCC_DeInit(); - RCC_HSEConfig(RCC_HSE_ON); - HSEStartUpStatus = RCC_WaitForHSEStartUp(); - if(HSEStartUpStatus == SUCCESS) - { - FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); - FLASH_SetLatency(FLASH_Latency_2); - RCC_HCLKConfig(RCC_SYSCLK_Div4); // 24 / 4 -> 6 - RCC_PCLK2Config(RCC_HCLK_Div4); // 6 / 4 = 1,5 -> APB2 -> TIMERS x 2 - RCC_PCLK1Config(RCC_HCLK_Div2); // 6 / 2 = 3 -> APB1 -> TIMERS x 2 - RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); // 24 - while(RCC_GetSYSCLKSource() != 0x04); - } -} - -void init_port() -{ - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); - GPIO_Conf.GPIO_Pin = GPIO_Pin_12; - GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(GPIOA, &GPIO_Conf); - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); - GPIO_Conf.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 ;//| GPIO_Pin_10; - GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(GPIOB, &GPIO_Conf); - - // SPI2_SCK & SPI2_MOSI - GPIO_Conf.GPIO_Pin = GPIO_Pin_13 | radioSDIpin; - GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(GPIOB, &GPIO_Conf); - - // SPI2_MISO - GPIO_Conf.GPIO_Pin = GPIO_Pin_14; - GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(GPIOB, &GPIO_Conf); - - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); - - // radioNSELpin - GPIO_Conf.GPIO_Pin = radioNSELpin; - GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(GPIOC,&GPIO_Conf); - - spi_init(); - - GPIO_Conf.GPIO_Pin = GPIO_Pin_9; - GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(GPIOA, &GPIO_Conf); - GPIO_Conf.GPIO_Pin = GPIO_Pin_10; - GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(GPIOA, &GPIO_Conf); - - init_usart_gps(9600, 0); - - GPIO_Conf.GPIO_Pin = GPIO_Pin_10; - GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(GPIOB, &GPIO_Conf); - GPIO_Conf.GPIO_Pin = GPIO_Pin_11; - GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_Init(GPIOB, &GPIO_Conf); - - init_usart_debug(); - - RCC_AHBPeriphClockCmd ( RCC_AHBPeriph_DMA1 , ENABLE ) ; - DMA_DeInit(DMA1_Channel1); - DMA_InitStructure.DMA_BufferSize = 2; - DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; - DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; - DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &ADCVal; - ADC_DMACmd(ADC1, ENABLE); - DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; - DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; - DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_Init(DMA1_Channel1, &DMA_InitStructure); - DMA_Cmd(DMA1_Channel1, ENABLE); - GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "init.h" +#include "radio.h" + +SPI_InitTypeDef SPI_InitStructure; +USART_InitTypeDef USART_InitStructure; +GPIO_InitTypeDef GPIO_Conf; +ADC_InitTypeDef ADC_InitStructure; +DMA_InitTypeDef DMA_InitStructure; + + +#define ADC1_DR_Address ((uint32_t)0x4001244C) +#if defined(STM32F10X_CL) +#error "Bedzie problem z kwarcem!" +#endif +void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) { + NVIC_DisableIRQ(USART1_IRQn); + USART_ITConfig(USART1, USART_IT_RXNE, DISABLE); + USART_ClearITPendingBit(USART1, USART_IT_RXNE); + USART_ClearITPendingBit(USART1, USART_IT_ORE); + + USART_Cmd(USART1, DISABLE); + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);// | RCC_APB2Periph_AFIO, ENABLE); + USART_InitStructure.USART_BaudRate = speed; //0x9c4; + USART_InitStructure.USART_WordLength = USART_WordLength_8b; + USART_InitStructure.USART_StopBits = USART_StopBits_1; + USART_InitStructure.USART_Parity = USART_Parity_No; + USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; + USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; + USART_Init(USART1, &USART_InitStructure); + + NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure + NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + USART_Cmd(USART1, ENABLE); + if (enable_irq){ + USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); + NVIC_EnableIRQ(USART1_IRQn); + } +} + +void init_usart_debug() { + NVIC_DisableIRQ(USART3_IRQn); + USART_Cmd(USART3, DISABLE); + + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); + USART_InitStructure.USART_BaudRate = 19200; //0x9c4; + USART_InitStructure.USART_WordLength = USART_WordLength_8b; + USART_InitStructure.USART_StopBits = USART_StopBits_1; + USART_InitStructure.USART_Parity = USART_Parity_No; + USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; + USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; + USART_Init(USART3, &USART_InitStructure); + USART_Cmd(USART3, ENABLE); +} + +void NVIC_Conf() +{ +#ifdef VECT_TAB_RAM + NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); +#else // VECT_TAB_FLASH + NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); +#endif +} + +void RCC_Conf() +{ + ErrorStatus HSEStartUpStatus; + RCC_DeInit(); + RCC_HSEConfig(RCC_HSE_ON); + HSEStartUpStatus = RCC_WaitForHSEStartUp(); + if(HSEStartUpStatus == SUCCESS) + { + FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); + FLASH_SetLatency(FLASH_Latency_2); + RCC_HCLKConfig(RCC_SYSCLK_Div4); + RCC_PCLK2Config(RCC_HCLK_Div4); + RCC_PCLK1Config(RCC_HCLK_Div2); + RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); + while(RCC_GetSYSCLKSource() != 0x04); + } +} + +void init_port() +{ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + GPIO_Conf.GPIO_Pin = GPIO_Pin_12; + GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(GPIOA, &GPIO_Conf); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); + GPIO_Conf.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8; + GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(GPIOB, &GPIO_Conf); + + // SPI2_SCK & SPI2_MOSI + GPIO_Conf.GPIO_Pin = GPIO_Pin_13 | radioSDIpin; + GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(GPIOB, &GPIO_Conf); + + // SPI2_MISO + GPIO_Conf.GPIO_Pin = GPIO_Pin_14; + GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init(GPIOB, &GPIO_Conf); + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); + + // radioNSELpin + GPIO_Conf.GPIO_Pin = radioNSELpin; + GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(GPIOC,&GPIO_Conf); + + spi_init(); + + GPIO_Conf.GPIO_Pin = GPIO_Pin_9; + GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(GPIOA, &GPIO_Conf); + GPIO_Conf.GPIO_Pin = GPIO_Pin_10; + GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init(GPIOA, &GPIO_Conf); + + init_usart_gps(9600, 0); + + GPIO_Conf.GPIO_Pin = GPIO_Pin_10; + GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(GPIOB, &GPIO_Conf); + GPIO_Conf.GPIO_Pin = GPIO_Pin_11; + GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init(GPIOB, &GPIO_Conf); + + init_usart_debug(); + + RCC_AHBPeriphClockCmd ( RCC_AHBPeriph_DMA1 , ENABLE ) ; + DMA_DeInit(DMA1_Channel1); + DMA_InitStructure.DMA_BufferSize = 2; + DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; + DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; + DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &ADCVal; + ADC_DMACmd(ADC1, ENABLE); + DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; + DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; + DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; + DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; + DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; + DMA_InitStructure.DMA_Priority = DMA_Priority_High; + DMA_Init(DMA1_Channel1, &DMA_InitStructure); + DMA_Cmd(DMA1_Channel1, ENABLE); + GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN; GPIO_Conf.GPIO_Pin = GPIO_Pin_6 ; // that's ADC1 (PA5 on STM32) - GPIO_Init(GPIOA, &GPIO_Conf); - GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN; - GPIO_Conf.GPIO_Pin = GPIO_Pin_5 ; // that's ADC1 (PA3 on STM32) - GPIO_Init(GPIOA, &GPIO_Conf); - RCC_ADCCLKConfig (RCC_PCLK2_Div2); - RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); - ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; - ADC_InitStructure.ADC_ScanConvMode = ENABLE; - ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // we work in continuous sampling mode - ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; - ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; - ADC_InitStructure.ADC_NbrOfChannel = 2; - ADC_Init ( ADC1, &ADC_InitStructure); //set config of ADC1 - ADC_RegularChannelConfig(ADC1,ADC_Channel_5, 1,ADC_SampleTime_28Cycles5); // define regular conversion config - ADC_RegularChannelConfig(ADC1,ADC_Channel_6, 2,ADC_SampleTime_28Cycles5); // define regular conversion config - ADC_DMACmd(ADC1, ENABLE); - ADC_Cmd (ADC1,ENABLE); //enable ADC - ADC_ResetCalibration(ADC1); // Reset previous calibration - while(ADC_GetResetCalibrationStatus(ADC1)); - ADC_StartCalibration(ADC1); // Start new calibration (ADC must be off at that time) - while(ADC_GetCalibrationStatus(ADC1)); - ADC_SoftwareStartConvCmd(ADC1, ENABLE); // start conversion (will be endless as we are in continuous mode) -} - -void spi_init() { - GPIO_Conf.GPIO_Pin = radioSDIpin; - GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP; - GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(GPIOB, &GPIO_Conf); - - RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; - SPI_InitStructure.SPI_Mode = SPI_Mode_Master; - SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; - SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; - SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; - SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16; - SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; - SPI_InitStructure.SPI_CRCPolynomial = 7; - SPI_Init(SPI2, &SPI_InitStructure); - SPI_SSOutputCmd(SPI2, ENABLE); - SPI_Cmd(SPI2, ENABLE); - SPI_InitStructure.SPI_Mode = SPI_Mode_Master; - SPI_Init(SPI2, &SPI_InitStructure); -} - -void spi_deinit() { - SPI_I2S_DeInit(SPI2); - GPIO_Conf.GPIO_Pin = radioSDIpin; - GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(GPIOB, &GPIO_Conf); - -} - -void init_timer(const int rtty_speed) { - TIM_TimeBaseInitTypeDef TIM2_TimeBaseInitStruct; - RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); - RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE); - - TIM2_TimeBaseInitStruct.TIM_Prescaler = 6/*0*/ - 1;// tick every 1/1000000 s - TIM2_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; - TIM2_TimeBaseInitStruct.TIM_Period = (uint16_t) ((1000000 / rtty_speed) - 1); - TIM2_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1; - TIM2_TimeBaseInitStruct.TIM_RepetitionCounter = 0; - - TIM_TimeBaseInit(TIM2,&TIM2_TimeBaseInitStruct); - TIM_ClearITPendingBit(TIM2, TIM_IT_Update); - TIM_ITConfig(TIM2,TIM_IT_Update, ENABLE); - NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure - NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - TIM_Cmd(TIM2,ENABLE); -} + GPIO_Init(GPIOA, &GPIO_Conf); + GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN; + GPIO_Conf.GPIO_Pin = GPIO_Pin_5 ; // that's ADC1 (PA3 on STM32) + GPIO_Init(GPIOA, &GPIO_Conf); + RCC_ADCCLKConfig (RCC_PCLK2_Div2); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); + ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; + ADC_InitStructure.ADC_ScanConvMode = ENABLE; + ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // we work in continuous sampling mode + ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; + ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; + ADC_InitStructure.ADC_NbrOfChannel = 2; + ADC_Init ( ADC1, &ADC_InitStructure); //set config of ADC1 + ADC_RegularChannelConfig(ADC1,ADC_Channel_5, 1,ADC_SampleTime_28Cycles5); // define regular conversion config + ADC_RegularChannelConfig(ADC1,ADC_Channel_6, 2,ADC_SampleTime_28Cycles5); // define regular conversion config + ADC_DMACmd(ADC1, ENABLE); + ADC_Cmd (ADC1,ENABLE); //enable ADC + ADC_ResetCalibration(ADC1); // Reset previous calibration + while(ADC_GetResetCalibrationStatus(ADC1)); + ADC_StartCalibration(ADC1); // Start new calibration (ADC must be off at that time) + while(ADC_GetCalibrationStatus(ADC1)); + ADC_SoftwareStartConvCmd(ADC1, ENABLE); // start conversion (will be endless as we are in continuous mode) +} + +void spi_init() { + GPIO_Conf.GPIO_Pin = radioSDIpin; + GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(GPIOB, &GPIO_Conf); + + RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; + SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16; + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + SPI_InitStructure.SPI_CRCPolynomial = 7; + SPI_Init(SPI2, &SPI_InitStructure); + SPI_SSOutputCmd(SPI2, ENABLE); + SPI_Cmd(SPI2, ENABLE); + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_Init(SPI2, &SPI_InitStructure); +} + +void spi_deinit() { + SPI_I2S_DeInit(SPI2); + GPIO_Conf.GPIO_Pin = radioSDIpin; + GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(GPIOB, &GPIO_Conf); + +} + +void init_timer(const int rtty_speed) { + TIM_TimeBaseInitTypeDef TIM2_TimeBaseInitStruct; + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE); + + TIM2_TimeBaseInitStruct.TIM_Prescaler = 6/*0*/ - 1;// tick every 1/1000000 s + TIM2_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; + TIM2_TimeBaseInitStruct.TIM_Period = (uint16_t) ((1000000 / rtty_speed) - 1); + TIM2_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1; + TIM2_TimeBaseInitStruct.TIM_RepetitionCounter = 0; + + TIM_TimeBaseInit(TIM2,&TIM2_TimeBaseInitStruct); + TIM_ClearITPendingBit(TIM2, TIM_IT_Update); + TIM_ITConfig(TIM2,TIM_IT_Update, ENABLE); + NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure + NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + TIM_Cmd(TIM2,ENABLE); +} diff --git a/init.h b/init.h index f2d6bc0..33f47ab 100644 --- a/init.h +++ b/init.h @@ -1,21 +1,21 @@ -__IO uint16_t ADCVal[2]; -#ifdef __cplusplus -extern "C" { -#endif - -void NVIC_Conf(); - -void RCC_Conf(); - -void init_port(); - -void init_timer(const int rtty_speed); - -void init_usart_gps(const uint32_t speed, const uint8_t enable_irq); - -void spi_init(); - -void spi_deinit(); -#ifdef __cplusplus -} -#endif +__IO uint16_t ADCVal[2]; +#ifdef __cplusplus +extern "C" { +#endif + +void NVIC_Conf(); + +void RCC_Conf(); + +void init_port(); + +void init_timer(const int rtty_speed); + +void init_usart_gps(const uint32_t speed, const uint8_t enable_irq); + +void spi_init(); + +void spi_deinit(); +#ifdef __cplusplus +} +#endif diff --git a/main.c b/main.c index 68341a8..ad1433c 100644 --- a/main.c +++ b/main.c @@ -1,237 +1,277 @@ -// STM32F100 and SI4032 RTTY transmitter -// released under GPL v.2 by anonymous developer -// enjoy and have a nice day -// ver 1.5a -#include -#include -#include -#include -#include -#include -#include -#include "stdlib.h" -#include -#include -#include -#include "f_rtty.h" -#include "fun.h" -#include "init.h" -#include "config.h" -#include "radio.h" -#include "ublox.h" -#include "delay.h" -#include "aprs.h" -///////////////////////////// test mode ///////////// -const unsigned char test = 0; // 0 - normal, 1 - short frame only cunter, height, flag -char callsign[15] = {CALLSIGN}; - - -#define GREEN GPIO_Pin_7 -#define RED GPIO_Pin_8 - -unsigned int send_cun; //frame counter -char status[2] = {'N'}; -int napiecie; - -volatile char flaga = 0;//((((tx_delay / 1000) & 0x0f) << 3) | TX_POWER); -uint16_t CRC_rtty = 0x12ab; //checksum -char buf_rtty[200]; - -volatile unsigned char pun = 0; -volatile unsigned int cun = 10; -volatile unsigned char tx_on = 0; -volatile unsigned int tx_on_delay; -volatile unsigned char tx_enable = 0; -rttyStates send_rtty_status = rttyZero; -volatile char *rtty_buf; -volatile uint16_t button_pressed = 0; -volatile uint8_t disable_armed = 0; - -void send_rtty_packet(); - -/** - * GPS data processing - */ -void USART1_IRQHandler(void) { - if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { - ublox_handle_incoming_byte((uint8_t) USART_ReceiveData(USART1)); - }else if (USART_GetITStatus(USART1, USART_IT_ORE) != RESET) { - USART_ReceiveData(USART1); - } else { - USART_ReceiveData(USART1); - } -} - -void TIM2_IRQHandler(void) { - if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { - TIM_ClearITPendingBit(TIM2, TIM_IT_Update); - - if (aprs_is_active()){ - aprs_timer_handler(); - } else { - if (tx_on /*&& ++cun_rtty == 17*/) { - send_rtty_status = send_rtty((char *) rtty_buf); - if (!disable_armed){ - if (send_rtty_status == rttyEnd) { - GPIO_SetBits(GPIOB, RED); - if (*(++rtty_buf) == 0) { - tx_on = 0; - tx_on_delay = tx_delay / (1000/RTTY_SPEED); - tx_enable = 0; - radio_disable_tx(); - } - } else if (send_rtty_status == rttyOne) { - radio_rw_register(0x73, 0x02, 1); - GPIO_SetBits(GPIOB, RED); - } else if (send_rtty_status == rttyZero) { - radio_rw_register(0x73, 0x00, 1); - GPIO_ResetBits(GPIOB, RED); - } - } - } - if (!tx_on && --tx_on_delay == 0) { - tx_enable = 1; - tx_on_delay--; - } - if (--cun == 0) { - if (pun) { - GPIO_ResetBits(GPIOB, GREEN); - pun = 0; - } else { - if (flaga & 0x80) { - GPIO_SetBits(GPIOB, GREEN); - } - pun = 1; - } - cun = 200; - } - if (ALLOW_DISABLE_BY_BUTTON){ - if (ADCVal[1] > 1900){ - button_pressed++; - if (button_pressed > (5 * RTTY_SPEED)){ - disable_armed = 1; - GPIO_SetBits(GPIOB, RED); - GPIO_SetBits(GPIOB, GREEN); - } - } else { - if (disable_armed){ - GPIO_SetBits(GPIOA, GPIO_Pin_12); - } - button_pressed = 0; - } - } - } - - } - -} - -int main(void) { -#ifdef DEBUG - debug(); -#endif - RCC_Conf(); - NVIC_Conf(); - init_port(); - - init_timer(RTTY_SPEED); - delay_init(); - ublox_init(); - - GPIO_SetBits(GPIOB, RED); - USART_SendData(USART3, 0xc); - radio_rw_register(0x02, 0xff, 0); - - radio_rw_register(0x03, 0xff, 0); - radio_rw_register(0x04, 0xff, 0); - radio_soft_reset(); - // programowanie czestotliwosci nadawania - radio_set_tx_frequency(RTTY_FREQUENCY); - - // Programowanie mocy nadajnika - radio_rw_register(0x6D, 00 | (TX_POWER & 0x0007), 1); - - radio_rw_register(0x71, 0x00, 1); - radio_rw_register(0x87, 0x08, 0); - radio_rw_register(0x02, 0xff, 0); - radio_rw_register(0x75, 0xff, 0); - radio_rw_register(0x76, 0xff, 0); - radio_rw_register(0x77, 0xff, 0); - radio_rw_register(0x12, 0x20, 1); - radio_rw_register(0x13, 0x00, 1); - radio_rw_register(0x12, 0x00, 1); - radio_rw_register(0x0f, 0x80, 1); - rtty_buf = buf_rtty; - tx_on = 0; - tx_enable = 1; - - aprs_init(); - radio_enable_tx(); - - uint8_t rtty_before_aprs_left = RTTY_TO_APRS_RATIO; - - while (1) { - if (tx_on == 0 && tx_enable) { - if (rtty_before_aprs_left){ - send_rtty_packet(); - rtty_before_aprs_left --; - } else { - rtty_before_aprs_left = RTTY_TO_APRS_RATIO; - radio_enable_tx(); - GPSEntry gpsData; - ublox_get_last_data(&gpsData); - USART_Cmd(USART1, DISABLE); - int8_t temperature = radio_read_temperature(); - uint16_t voltage = (uint16_t) srednia(ADCVal[0] * 600 / 4096); - aprs_send_position(gpsData, temperature, voltage); - USART_Cmd(USART1, ENABLE); - radio_disable_tx(); - } - - } else { - NVIC_SystemLPConfig(NVIC_LP_SEVONPEND, DISABLE); - __WFI(); - } - } -} - -void send_rtty_packet() { - start_bits = RTTY_PRE_START_BITS; - int8_t temperatura = radio_read_temperature(); - - napiecie = srednia(ADCVal[0] * 600 / 4096); - GPSEntry gpsData; - ublox_get_last_data(&gpsData); - if (gpsData.fix >= 3) { - flaga |= 0x80; - } else { - flaga &= ~0x80; - } - uint8_t lat_d = (uint8_t) abs(gpsData.lat_raw / 10000000); - uint32_t lat_fl = (uint32_t) abs(abs(gpsData.lat_raw) - lat_d * 10000000) / 100; - uint8_t lon_d = (uint8_t) abs(gpsData.lon_raw / 10000000); - uint32_t lon_fl = (uint32_t) abs(abs(gpsData.lon_raw) - lon_d * 10000000) / 100; - - sprintf(buf_rtty, "$$$$%s,%d,%02u%02u%02u,%s%d.%05ld,%s%d.%05ld,%ld,%d,%d,%d,%d,%d,%02x", callsign, send_cun, - gpsData.hours, gpsData.minutes, gpsData.seconds, - gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl, - gpsData.lon_raw < 0 ? "-" : "", lon_d, lon_fl, - (gpsData.alt_raw / 1000), temperatura, napiecie, gpsData.sats_raw, - gpsData.ok_packets, gpsData.bad_packets, - flaga); - CRC_rtty = 0xffff; //napiecie flaga - CRC_rtty = gps_CRC16_checksum(buf_rtty + 4); - sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff); - rtty_buf = buf_rtty; - radio_enable_tx(); - tx_on = 1; - - send_cun++; -} - -#ifdef DEBUG -void assert_failed(uint8_t* file, uint32_t line) -{ - while (1); -} -#endif +// STM32F100 and SI4032 RTTY transmitter +// released under GPL v.2 by anonymous developer +// enjoy and have a nice day +// ver 1.5a +#include +#include +#include +#include +#include +#include +#include +#include "stdlib.h" +#include +#include +#include +#include "f_rtty.h" +#include "init.h" +#include "config.h" +#include "radio.h" +#include "ublox.h" +#include "delay.h" +#include "aprs.h" +///////////////////////////// test mode ///////////// +const unsigned char test = 0; // 0 - normal, 1 - short frame only cunter, height, flag +char callsign[15] = {CALLSIGN}; + + +#define GREEN GPIO_Pin_7 +#define RED GPIO_Pin_8 + +unsigned int send_cun; //frame counter +char status[2] = {'N'}; +int napiecie; + +volatile char flaga = 0; +uint16_t CRC_rtty = 0x12ab; //checksum +char buf_rtty[200]; + +volatile unsigned char pun = 0; +volatile unsigned int cun = 10; +volatile unsigned char tx_on = 0; +volatile unsigned int tx_on_delay; +volatile unsigned char tx_enable = 0; +rttyStates send_rtty_status = rttyZero; +volatile char *rtty_buf; +volatile uint16_t button_pressed = 0; +volatile uint8_t disable_armed = 0; + +void send_rtty_packet(); +uint16_t gps_CRC16_checksum (char *string); +int srednia (int dana); + + +/** + * GPS data processing + */ +void USART1_IRQHandler(void) { + if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { + ublox_handle_incoming_byte((uint8_t) USART_ReceiveData(USART1)); + }else if (USART_GetITStatus(USART1, USART_IT_ORE) != RESET) { + USART_ReceiveData(USART1); + } else { + USART_ReceiveData(USART1); + } +} + +void TIM2_IRQHandler(void) { + if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { + TIM_ClearITPendingBit(TIM2, TIM_IT_Update); + + if (aprs_is_active()){ + aprs_timer_handler(); + } else { + if (tx_on) { + send_rtty_status = send_rtty((char *) rtty_buf); + if (!disable_armed){ + if (send_rtty_status == rttyEnd) { + GPIO_SetBits(GPIOB, RED); + if (*(++rtty_buf) == 0) { + tx_on = 0; + tx_on_delay = tx_delay / (1000/RTTY_SPEED); + tx_enable = 0; + radio_disable_tx(); + } + } else if (send_rtty_status == rttyOne) { + radio_rw_register(0x73, 0x02, 1); + GPIO_SetBits(GPIOB, RED); + } else if (send_rtty_status == rttyZero) { + radio_rw_register(0x73, 0x00, 1); + GPIO_ResetBits(GPIOB, RED); + } + } + } + if (!tx_on && --tx_on_delay == 0) { + tx_enable = 1; + tx_on_delay--; + } + if (--cun == 0) { + if (pun) { + GPIO_ResetBits(GPIOB, GREEN); + pun = 0; + } else { + if (flaga & 0x80) { + GPIO_SetBits(GPIOB, GREEN); + } + pun = 1; + } + cun = 200; + } + if (ALLOW_DISABLE_BY_BUTTON){ + if (ADCVal[1] > 1900){ + button_pressed++; + if (button_pressed > (5 * RTTY_SPEED)){ + disable_armed = 1; + GPIO_SetBits(GPIOB, RED); + GPIO_SetBits(GPIOB, GREEN); + } + } else { + if (disable_armed){ + GPIO_SetBits(GPIOA, GPIO_Pin_12); + } + button_pressed = 0; + } + } + } + + } + +} + +int main(void) { +#ifdef DEBUG + debug(); +#endif + RCC_Conf(); + NVIC_Conf(); + init_port(); + + init_timer(RTTY_SPEED); + delay_init(); + ublox_init(); + + GPIO_SetBits(GPIOB, RED); + USART_SendData(USART3, 0xc); + radio_rw_register(0x02, 0xff, 0); + + radio_rw_register(0x03, 0xff, 0); + radio_rw_register(0x04, 0xff, 0); + radio_soft_reset(); + // setting TX frequency + radio_set_tx_frequency(RTTY_FREQUENCY); + + // setting TX power + radio_rw_register(0x6D, 00 | (TX_POWER & 0x0007), 1); + + radio_rw_register(0x71, 0x00, 1); + radio_rw_register(0x87, 0x08, 0); + radio_rw_register(0x02, 0xff, 0); + radio_rw_register(0x75, 0xff, 0); + radio_rw_register(0x76, 0xff, 0); + radio_rw_register(0x77, 0xff, 0); + radio_rw_register(0x12, 0x20, 1); + radio_rw_register(0x13, 0x00, 1); + radio_rw_register(0x12, 0x00, 1); + radio_rw_register(0x0f, 0x80, 1); + rtty_buf = buf_rtty; + tx_on = 0; + tx_enable = 1; + + aprs_init(); + radio_enable_tx(); + + uint8_t rtty_before_aprs_left = RTTY_TO_APRS_RATIO; + + while (1) { + if (tx_on == 0 && tx_enable) { + if (rtty_before_aprs_left){ + send_rtty_packet(); + rtty_before_aprs_left --; + } else { + rtty_before_aprs_left = RTTY_TO_APRS_RATIO; + radio_enable_tx(); + GPSEntry gpsData; + ublox_get_last_data(&gpsData); + USART_Cmd(USART1, DISABLE); + int8_t temperature = radio_read_temperature(); + uint16_t voltage = (uint16_t) srednia(ADCVal[0] * 600 / 4096); + aprs_send_position(gpsData, temperature, voltage); + USART_Cmd(USART1, ENABLE); + radio_disable_tx(); + } + + } else { + NVIC_SystemLPConfig(NVIC_LP_SEVONPEND, DISABLE); + __WFI(); + } + } +} + +void send_rtty_packet() { + start_bits = RTTY_PRE_START_BITS; + int8_t temperatura = radio_read_temperature(); + + napiecie = srednia(ADCVal[0] * 600 / 4096); + GPSEntry gpsData; + ublox_get_last_data(&gpsData); + if (gpsData.fix >= 3) { + flaga |= 0x80; + } else { + flaga &= ~0x80; + } + uint8_t lat_d = (uint8_t) abs(gpsData.lat_raw / 10000000); + uint32_t lat_fl = (uint32_t) abs(abs(gpsData.lat_raw) - lat_d * 10000000) / 100; + uint8_t lon_d = (uint8_t) abs(gpsData.lon_raw / 10000000); + uint32_t lon_fl = (uint32_t) abs(abs(gpsData.lon_raw) - lon_d * 10000000) / 100; + + sprintf(buf_rtty, "$$$$%s,%d,%02u%02u%02u,%s%d.%05ld,%s%d.%05ld,%ld,%d,%d,%d,%d,%d,%02x", callsign, send_cun, + gpsData.hours, gpsData.minutes, gpsData.seconds, + gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl, + gpsData.lon_raw < 0 ? "-" : "", lon_d, lon_fl, + (gpsData.alt_raw / 1000), temperatura, napiecie, gpsData.sats_raw, + gpsData.ok_packets, gpsData.bad_packets, + flaga); + CRC_rtty = 0xffff; //napiecie flaga possibly not neccessary?? + CRC_rtty = gps_CRC16_checksum(buf_rtty + 4); + sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff); + rtty_buf = buf_rtty; + radio_enable_tx(); + tx_on = 1; + + send_cun++; +} + +uint16_t gps_CRC16_checksum(char *string) { + uint16_t crc = 0xffff; + char i; + while (*(string) != 0) { + crc = crc ^ (*(string++) << 8); + for (i = 0; i < 8; i++) { + if (crc & 0x8000) + crc = (uint16_t) ((crc << 1) ^ 0x1021); + else + crc <<= 1; + } + } + return crc; +} + +int srednia(int dana) { + static uint8_t nr_pom = 0; + static uint8_t first = 1; + int srednia_u[5] = {0, 0, 0, 0, 0}; + uint8_t i; + int sr = 0; + if (first) { + for (i = 0; i < 5; i++) { + srednia_u[i] = dana; + } + first = 0; + } + srednia_u[nr_pom] = dana; + if (++nr_pom > 4) { + nr_pom = 0; + } + for (i = 0; i < 5; i++) { + sr += srednia_u[i]; + } + sr = sr / 5; + return sr; +} + +#ifdef DEBUG +void assert_failed(uint8_t* file, uint32_t line) +{ + while (1); +} +#endif diff --git a/radio.c b/radio.c index 88ed1c2..cd857d4 100644 --- a/radio.c +++ b/radio.c @@ -24,7 +24,7 @@ void radio_set_tx_frequency(const float freq_in_mhz) { uint8_t hbsel = (uint8_t) ((freq_in_mhz * (30.0f / SI4032_CLOCK)) >= 480.0f ? 1 : 0); uint8_t fb = (uint8_t) ((((uint8_t)((freq_in_mhz * (30.0f / SI4032_CLOCK)) / 10) - 24) - (24 * hbsel)) / (1 + hbsel)); - uint8_t gen_div = 3; //Stała nie zmieniac + uint8_t gen_div = 3; // constant - not possible to change! uint16_t fc = (uint16_t) (((freq_in_mhz / ((SI4032_CLOCK / gen_div) * (hbsel + 1))) - fb - 24) * 64000); radio_rw_register(0x72, 10, 1); @@ -48,7 +48,7 @@ void radio_enable_tx() { int8_t radio_read_temperature() { uint8_t temp; - temp = radio_rw_register(0x11, 0xff, 0); //odczyt ADC + temp = radio_rw_register(0x11, 0xff, 0); // read ADC int8_t temperatura = (int8_t) (-64 + (temp * 5 / 10) - 16); radio_rw_register(0x0f, 0x80, 1); return temperatura; From 0ac3d90c0bc3de6af457d3d354bb718adea2ac1e Mon Sep 17 00:00:00 2001 From: df8oe Date: Fri, 9 Jun 2017 14:49:39 +0200 Subject: [PATCH 6/7] more refactorings, some functions may be useless and are removed --- f_rtty.c | 4 ++-- f_rtty.h | 2 +- init.c | 28 ++++++++++++++-------------- main.c | 18 ++++++++++-------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/f_rtty.c b/f_rtty.c index eb7e81d..056a54a 100644 --- a/f_rtty.c +++ b/f_rtty.c @@ -1,7 +1,7 @@ #include "f_rtty.h" uint8_t start_bits; -rttyStates send_rtty(char *znak) { +rttyStates send_rtty(char *buffer) { static uint8_t nr_bit = 0; nr_bit++; if (start_bits){ @@ -13,7 +13,7 @@ rttyStates send_rtty(char *znak) { return rttyZero; } if (nr_bit > 1 && nr_bit < (RTTY_7BIT ? 9 : 10)) { - if ((*(znak) >> (nr_bit - 2)) & 0x01) { + if ((*(buffer) >> (nr_bit - 2)) & 0x01) { return rttyOne; } else { return rttyZero; diff --git a/f_rtty.h b/f_rtty.h index 11e0fbc..2c09d36 100644 --- a/f_rtty.h +++ b/f_rtty.h @@ -8,5 +8,5 @@ typedef enum { } rttyStates; static const uint8_t RTTY_PRE_START_BITS = 10; -rttyStates send_rtty(char *znak); +rttyStates send_rtty(char *); extern uint8_t start_bits; diff --git a/init.c b/init.c index ca1a028..5186fbc 100644 --- a/init.c +++ b/init.c @@ -20,7 +20,7 @@ DMA_InitTypeDef DMA_InitStructure; #define ADC1_DR_Address ((uint32_t)0x4001244C) #if defined(STM32F10X_CL) -#error "Bedzie problem z kwarcem!" +#error "clock oscillator problem!" #endif void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) { NVIC_DisableIRQ(USART1_IRQn); @@ -30,8 +30,8 @@ void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) { USART_Cmd(USART1, DISABLE); - RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);// | RCC_APB2Periph_AFIO, ENABLE); - USART_InitStructure.USART_BaudRate = speed; //0x9c4; + RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); + USART_InitStructure.USART_BaudRate = speed; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; @@ -39,7 +39,7 @@ void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) { USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_Init(USART1, &USART_InitStructure); - NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure + NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; @@ -166,29 +166,29 @@ void init_port() DMA_Init(DMA1_Channel1, &DMA_InitStructure); DMA_Cmd(DMA1_Channel1, ENABLE); GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN; - GPIO_Conf.GPIO_Pin = GPIO_Pin_6 ; // that's ADC1 (PA5 on STM32) + GPIO_Conf.GPIO_Pin = GPIO_Pin_6 ; // that's ADC1 (PA5 on STM32) GPIO_Init(GPIOA, &GPIO_Conf); GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN; - GPIO_Conf.GPIO_Pin = GPIO_Pin_5 ; // that's ADC1 (PA3 on STM32) + GPIO_Conf.GPIO_Pin = GPIO_Pin_5 ; // that's ADC1 (PA3 on STM32) GPIO_Init(GPIOA, &GPIO_Conf); RCC_ADCCLKConfig (RCC_PCLK2_Div2); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; - ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // we work in continuous sampling mode + ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // we work in continuous sampling mode ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 2; - ADC_Init ( ADC1, &ADC_InitStructure); //set config of ADC1 + ADC_Init ( ADC1, &ADC_InitStructure); //set config of ADC1 ADC_RegularChannelConfig(ADC1,ADC_Channel_5, 1,ADC_SampleTime_28Cycles5); // define regular conversion config ADC_RegularChannelConfig(ADC1,ADC_Channel_6, 2,ADC_SampleTime_28Cycles5); // define regular conversion config ADC_DMACmd(ADC1, ENABLE); - ADC_Cmd (ADC1,ENABLE); //enable ADC - ADC_ResetCalibration(ADC1); // Reset previous calibration + ADC_Cmd (ADC1,ENABLE); //enable ADC + ADC_ResetCalibration(ADC1); // Reset previous calibration while(ADC_GetResetCalibrationStatus(ADC1)); - ADC_StartCalibration(ADC1); // Start new calibration (ADC must be off at that time) + ADC_StartCalibration(ADC1); // start new calibration (ADC must be off at that time) while(ADC_GetCalibrationStatus(ADC1)); - ADC_SoftwareStartConvCmd(ADC1, ENABLE); // start conversion (will be endless as we are in continuous mode) + ADC_SoftwareStartConvCmd(ADC1, ENABLE); // start conversion (will be endless as we are in continuous mode) } void spi_init() { @@ -227,7 +227,7 @@ void init_timer(const int rtty_speed) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE); - TIM2_TimeBaseInitStruct.TIM_Prescaler = 6/*0*/ - 1;// tick every 1/1000000 s + TIM2_TimeBaseInitStruct.TIM_Prescaler = 6 - 1; // tick every 1/1000000 s TIM2_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; TIM2_TimeBaseInitStruct.TIM_Period = (uint16_t) ((1000000 / rtty_speed) - 1); TIM2_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1; @@ -236,7 +236,7 @@ void init_timer(const int rtty_speed) { TIM_TimeBaseInit(TIM2,&TIM2_TimeBaseInitStruct); TIM_ClearITPendingBit(TIM2, TIM_IT_Update); TIM_ITConfig(TIM2,TIM_IT_Update, ENABLE); - NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure + NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; diff --git a/main.c b/main.c index ad1433c..00c02ca 100644 --- a/main.c +++ b/main.c @@ -30,7 +30,7 @@ char callsign[15] = {CALLSIGN}; unsigned int send_cun; //frame counter char status[2] = {'N'}; -int napiecie; +int voltage; volatile char flaga = 0; uint16_t CRC_rtty = 0x12ab; //checksum @@ -48,7 +48,7 @@ volatile uint8_t disable_armed = 0; void send_rtty_packet(); uint16_t gps_CRC16_checksum (char *string); -int srednia (int dana); +// int srednia (int dana); /** @@ -184,7 +184,8 @@ int main(void) { ublox_get_last_data(&gpsData); USART_Cmd(USART1, DISABLE); int8_t temperature = radio_read_temperature(); - uint16_t voltage = (uint16_t) srednia(ADCVal[0] * 600 / 4096); +// uint16_t voltage = (uint16_t) srednia(ADCVal[0] * 600 / 4096); + uint16_t voltage = (uint16_t) ADCVal[0] * 600 / 4096; aprs_send_position(gpsData, temperature, voltage); USART_Cmd(USART1, ENABLE); radio_disable_tx(); @@ -201,7 +202,8 @@ void send_rtty_packet() { start_bits = RTTY_PRE_START_BITS; int8_t temperatura = radio_read_temperature(); - napiecie = srednia(ADCVal[0] * 600 / 4096); +// voltage = srednia(ADCVal[0] * 600 / 4096); + voltage = ADCVal[0] * 600 / 4096; GPSEntry gpsData; ublox_get_last_data(&gpsData); if (gpsData.fix >= 3) { @@ -218,10 +220,10 @@ void send_rtty_packet() { gpsData.hours, gpsData.minutes, gpsData.seconds, gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl, gpsData.lon_raw < 0 ? "-" : "", lon_d, lon_fl, - (gpsData.alt_raw / 1000), temperatura, napiecie, gpsData.sats_raw, + (gpsData.alt_raw / 1000), temperatura, voltage, gpsData.sats_raw, gpsData.ok_packets, gpsData.bad_packets, flaga); - CRC_rtty = 0xffff; //napiecie flaga possibly not neccessary?? + CRC_rtty = 0xffff; //possibly not neccessary?? CRC_rtty = gps_CRC16_checksum(buf_rtty + 4); sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff); rtty_buf = buf_rtty; @@ -245,7 +247,7 @@ uint16_t gps_CRC16_checksum(char *string) { } return crc; } - +/* int srednia(int dana) { static uint8_t nr_pom = 0; static uint8_t first = 1; @@ -268,7 +270,7 @@ int srednia(int dana) { sr = sr / 5; return sr; } - +*/ #ifdef DEBUG void assert_failed(uint8_t* file, uint32_t line) { From e60b70a6b10d33efe45a98694f1049822fbb682e Mon Sep 17 00:00:00 2001 From: df8oe Date: Fri, 9 Jun 2017 14:51:25 +0200 Subject: [PATCH 7/7] removed fun.c and fun.h --- fun.c | 73 ----------------------------------------------------------- fun.h | 8 ------- 2 files changed, 81 deletions(-) delete mode 100644 fun.c delete mode 100644 fun.h diff --git a/fun.c b/fun.c deleted file mode 100644 index 2f7fa05..0000000 --- a/fun.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include - -const char ascii[] = "0123456789ABCDEF"; -int srednia_u[5] = {0, 0, 0, 0, 0}; - - - -int HexCharToInt(char ch) { - if (ch < 48 || (ch > 57 && ch < 65) || ch > 70) return 0; - return (ch < 58) ? ch - 48 : ch - 55; -} - -void print(char *s) { - #ifdef DEBUG - while (*s) { - while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET) { - } - USART_SendData(USART3, *(s++)); - } - #endif -} - -void send_hex(unsigned char data) { - #ifdef DEBUG - while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET) { - } - USART_SendData(USART3, ascii[data >> 4]); - while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET) { - } - USART_SendData(USART3, ascii[data & 0x0f]); - #endif -} - - - -uint16_t gps_CRC16_checksum(char *string) { - uint16_t crc = 0xffff; - char i; - while (*(string) != 0) { - crc = crc ^ (*(string++) << 8); - for (i = 0; i < 8; i++) { - if (crc & 0x8000) - crc = (uint16_t) ((crc << 1) ^ 0x1021); - else - crc <<= 1; - } - } - return crc; -} - -int srednia(int dana) { - static uint8_t nr_pom = 0; - static uint8_t first = 1; - uint8_t i; - int sr = 0; - if (first) { - for (i = 0; i < 5; i++) { - srednia_u[i] = dana; - } - first = 0; - } - srednia_u[nr_pom] = dana; - if (++nr_pom > 4) { - nr_pom = 0; - } - for (i = 0; i < 5; i++) { - sr += srednia_u[i]; - } - sr = sr / 5; - return sr; -} diff --git a/fun.h b/fun.h deleted file mode 100644 index f80368f..0000000 --- a/fun.h +++ /dev/null @@ -1,8 +0,0 @@ -int HexCharToInt(char ch); -void print( char* s); -void send_hex(unsigned char data); - -unsigned char czytaj_GPS(unsigned char pos,unsigned char len, char *source, char * destination); -uint16_t gps_CRC16_checksum (char *string); -int srednia (int dana); -