kopia lustrzana https://github.com/Qyon/STM32_RTTY
some more refactorings, adding license text as original author's license wish
rodzic
c746fee8ff
commit
6426f48ff3
|
@ -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
|
|
@ -1,12 +1,19 @@
|
||||||
# STM32_RTTY
|
# STM32_RTTY
|
||||||
STM32 & SI4032 rtty test
|
STM32 & SI4032 rtty test
|
||||||
|
|
||||||
|
Released under GPL v2
|
||||||
|
|
||||||
Use:
|
Use:
|
||||||
https://www.wyzbee.com/download/Utilities/Software/CoIDE-1.7.8.exe
|
https://www.wyzbee.com/download/Utilities/Software/CoIDE-1.7.8.exe
|
||||||
|
|
||||||
And:
|
And:
|
||||||
https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-win32.exe
|
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 ;)
|
Have a nice day ;)
|
||||||
|
|
||||||
#Changelog
|
#Changelog
|
||||||
|
|
74
f_rtty.c
74
f_rtty.c
|
@ -1,37 +1,37 @@
|
||||||
#include "f_rtty.h"
|
#include "f_rtty.h"
|
||||||
|
|
||||||
uint8_t start_bits;
|
uint8_t start_bits;
|
||||||
rttyStates send_rtty(char *znak) {
|
rttyStates send_rtty(char *znak) {
|
||||||
static uint8_t nr_bit = 0;
|
static uint8_t nr_bit = 0;
|
||||||
nr_bit++;
|
nr_bit++;
|
||||||
if (start_bits){
|
if (start_bits){
|
||||||
start_bits--;
|
start_bits--;
|
||||||
return rttyOne;
|
return rttyOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nr_bit == 1) {
|
if (nr_bit == 1) {
|
||||||
return rttyZero;
|
return rttyZero;
|
||||||
}
|
}
|
||||||
if (nr_bit > 1 && nr_bit < (RTTY_7BIT ? 9 : 10)) {
|
if (nr_bit > 1 && nr_bit < (RTTY_7BIT ? 9 : 10)) {
|
||||||
if ((*(znak) >> (nr_bit - 2)) & 0x01) {
|
if ((*(znak) >> (nr_bit - 2)) & 0x01) {
|
||||||
return rttyOne;
|
return rttyOne;
|
||||||
} else {
|
} else {
|
||||||
return rttyZero;
|
return rttyZero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RTTY_7BIT
|
#ifdef RTTY_7BIT
|
||||||
nr_bit++;
|
nr_bit++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (nr_bit == 10) {
|
if (nr_bit == 10) {
|
||||||
return rttyOne;
|
return rttyOne;
|
||||||
}
|
}
|
||||||
#ifdef RTTY_USE_2_STOP_BITS
|
#ifdef RTTY_USE_2_STOP_BITS
|
||||||
if (nr_bit == 11) {
|
if (nr_bit == 11) {
|
||||||
return rttyOne;
|
return rttyOne;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
nr_bit = 0;
|
nr_bit = 0;
|
||||||
return rttyEnd;
|
return rttyEnd;
|
||||||
}
|
}
|
||||||
|
|
24
f_rtty.h
24
f_rtty.h
|
@ -1,12 +1,12 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
rttyZero = 0,
|
rttyZero = 0,
|
||||||
rttyOne = 1,
|
rttyOne = 1,
|
||||||
rttyEnd = 2
|
rttyEnd = 2
|
||||||
} rttyStates;
|
} rttyStates;
|
||||||
static const uint8_t RTTY_PRE_START_BITS = 10;
|
static const uint8_t RTTY_PRE_START_BITS = 10;
|
||||||
|
|
||||||
rttyStates send_rtty(char *znak);
|
rttyStates send_rtty(char *znak);
|
||||||
extern uint8_t start_bits;
|
extern uint8_t start_bits;
|
||||||
|
|
490
init.c
490
init.c
|
@ -1,246 +1,246 @@
|
||||||
#include <stm32f10x_flash.h>
|
#include <stm32f10x_flash.h>
|
||||||
#include <stm32f10x_rcc.h>
|
#include <stm32f10x_rcc.h>
|
||||||
#include <stm32f10x_gpio.h>
|
#include <stm32f10x_gpio.h>
|
||||||
#include <stm32f10x_tim.h>
|
#include <stm32f10x_tim.h>
|
||||||
#include <stm32f10x_usart.h>
|
#include <stm32f10x_usart.h>
|
||||||
#include <stm32f10x_adc.h>
|
#include <stm32f10x_adc.h>
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
#include <stm32f10x_dma.h>
|
#include <stm32f10x_dma.h>
|
||||||
#include <stm32f10x_spi.h>
|
#include <stm32f10x_spi.h>
|
||||||
#include <misc.h>
|
#include <misc.h>
|
||||||
#include "init.h"
|
#include "init.h"
|
||||||
#include "radio.h"
|
#include "radio.h"
|
||||||
|
|
||||||
SPI_InitTypeDef SPI_InitStructure;
|
SPI_InitTypeDef SPI_InitStructure;
|
||||||
USART_InitTypeDef USART_InitStructure;
|
USART_InitTypeDef USART_InitStructure;
|
||||||
GPIO_InitTypeDef GPIO_Conf;
|
GPIO_InitTypeDef GPIO_Conf;
|
||||||
ADC_InitTypeDef ADC_InitStructure;
|
ADC_InitTypeDef ADC_InitStructure;
|
||||||
DMA_InitTypeDef DMA_InitStructure;
|
DMA_InitTypeDef DMA_InitStructure;
|
||||||
|
|
||||||
|
|
||||||
#define ADC1_DR_Address ((uint32_t)0x4001244C)
|
#define ADC1_DR_Address ((uint32_t)0x4001244C)
|
||||||
#if defined(STM32F10X_CL)
|
#if defined(STM32F10X_CL)
|
||||||
#error "Bedzie problem z kwarcem!"
|
#error "Bedzie problem z kwarcem!"
|
||||||
#endif
|
#endif
|
||||||
void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) {
|
void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) {
|
||||||
NVIC_DisableIRQ(USART1_IRQn);
|
NVIC_DisableIRQ(USART1_IRQn);
|
||||||
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
|
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
|
||||||
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
|
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
|
||||||
USART_ClearITPendingBit(USART1, USART_IT_ORE);
|
USART_ClearITPendingBit(USART1, USART_IT_ORE);
|
||||||
|
|
||||||
USART_Cmd(USART1, DISABLE);
|
USART_Cmd(USART1, DISABLE);
|
||||||
|
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);// | RCC_APB2Periph_AFIO, ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);// | RCC_APB2Periph_AFIO, ENABLE);
|
||||||
USART_InitStructure.USART_BaudRate = speed; //0x9c4;
|
USART_InitStructure.USART_BaudRate = speed; //0x9c4;
|
||||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||||
USART_Init(USART1, &USART_InitStructure);
|
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_IRQChannel = USART1_IRQn;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
|
|
||||||
USART_Cmd(USART1, ENABLE);
|
USART_Cmd(USART1, ENABLE);
|
||||||
if (enable_irq){
|
if (enable_irq){
|
||||||
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
||||||
NVIC_EnableIRQ(USART1_IRQn);
|
NVIC_EnableIRQ(USART1_IRQn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_usart_debug() {
|
void init_usart_debug() {
|
||||||
NVIC_DisableIRQ(USART3_IRQn);
|
NVIC_DisableIRQ(USART3_IRQn);
|
||||||
USART_Cmd(USART3, DISABLE);
|
USART_Cmd(USART3, DISABLE);
|
||||||
|
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);// | RCC_APB2Periph_AFIO, ENABLE);
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||||
USART_InitStructure.USART_BaudRate = 19200; //0x9c4;
|
USART_InitStructure.USART_BaudRate = 19200; //0x9c4;
|
||||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||||
USART_Init(USART3, &USART_InitStructure);
|
USART_Init(USART3, &USART_InitStructure);
|
||||||
USART_Cmd(USART3, ENABLE);
|
USART_Cmd(USART3, ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NVIC_Conf()
|
void NVIC_Conf()
|
||||||
{
|
{
|
||||||
#ifdef VECT_TAB_RAM
|
#ifdef VECT_TAB_RAM
|
||||||
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
|
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
|
||||||
#else // VECT_TAB_FLASH
|
#else // VECT_TAB_FLASH
|
||||||
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
|
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RCC_Conf()
|
void RCC_Conf()
|
||||||
{
|
{
|
||||||
ErrorStatus HSEStartUpStatus;
|
ErrorStatus HSEStartUpStatus;
|
||||||
RCC_DeInit();
|
RCC_DeInit();
|
||||||
RCC_HSEConfig(RCC_HSE_ON);
|
RCC_HSEConfig(RCC_HSE_ON);
|
||||||
HSEStartUpStatus = RCC_WaitForHSEStartUp();
|
HSEStartUpStatus = RCC_WaitForHSEStartUp();
|
||||||
if(HSEStartUpStatus == SUCCESS)
|
if(HSEStartUpStatus == SUCCESS)
|
||||||
{
|
{
|
||||||
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
|
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
|
||||||
FLASH_SetLatency(FLASH_Latency_2);
|
FLASH_SetLatency(FLASH_Latency_2);
|
||||||
RCC_HCLKConfig(RCC_SYSCLK_Div4); // 24 / 4 -> 6
|
RCC_HCLKConfig(RCC_SYSCLK_Div4);
|
||||||
RCC_PCLK2Config(RCC_HCLK_Div4); // 6 / 4 = 1,5 -> APB2 -> TIMERS x 2
|
RCC_PCLK2Config(RCC_HCLK_Div4);
|
||||||
RCC_PCLK1Config(RCC_HCLK_Div2); // 6 / 2 = 3 -> APB1 -> TIMERS x 2
|
RCC_PCLK1Config(RCC_HCLK_Div2);
|
||||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); // 24
|
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
|
||||||
while(RCC_GetSYSCLKSource() != 0x04);
|
while(RCC_GetSYSCLKSource() != 0x04);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_port()
|
void init_port()
|
||||||
{
|
{
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||||
GPIO_Conf.GPIO_Pin = GPIO_Pin_12;
|
GPIO_Conf.GPIO_Pin = GPIO_Pin_12;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(GPIOA, &GPIO_Conf);
|
GPIO_Init(GPIOA, &GPIO_Conf);
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||||
GPIO_Conf.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 ;//| GPIO_Pin_10;
|
GPIO_Conf.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(GPIOB, &GPIO_Conf);
|
GPIO_Init(GPIOB, &GPIO_Conf);
|
||||||
|
|
||||||
// SPI2_SCK & SPI2_MOSI
|
// SPI2_SCK & SPI2_MOSI
|
||||||
GPIO_Conf.GPIO_Pin = GPIO_Pin_13 | radioSDIpin;
|
GPIO_Conf.GPIO_Pin = GPIO_Pin_13 | radioSDIpin;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||||
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(GPIOB, &GPIO_Conf);
|
GPIO_Init(GPIOB, &GPIO_Conf);
|
||||||
|
|
||||||
// SPI2_MISO
|
// SPI2_MISO
|
||||||
GPIO_Conf.GPIO_Pin = GPIO_Pin_14;
|
GPIO_Conf.GPIO_Pin = GPIO_Pin_14;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||||
GPIO_Init(GPIOB, &GPIO_Conf);
|
GPIO_Init(GPIOB, &GPIO_Conf);
|
||||||
|
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||||
|
|
||||||
// radioNSELpin
|
// radioNSELpin
|
||||||
GPIO_Conf.GPIO_Pin = radioNSELpin;
|
GPIO_Conf.GPIO_Pin = radioNSELpin;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(GPIOC,&GPIO_Conf);
|
GPIO_Init(GPIOC,&GPIO_Conf);
|
||||||
|
|
||||||
spi_init();
|
spi_init();
|
||||||
|
|
||||||
GPIO_Conf.GPIO_Pin = GPIO_Pin_9;
|
GPIO_Conf.GPIO_Pin = GPIO_Pin_9;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||||
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(GPIOA, &GPIO_Conf);
|
GPIO_Init(GPIOA, &GPIO_Conf);
|
||||||
GPIO_Conf.GPIO_Pin = GPIO_Pin_10;
|
GPIO_Conf.GPIO_Pin = GPIO_Pin_10;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||||
GPIO_Init(GPIOA, &GPIO_Conf);
|
GPIO_Init(GPIOA, &GPIO_Conf);
|
||||||
|
|
||||||
init_usart_gps(9600, 0);
|
init_usart_gps(9600, 0);
|
||||||
|
|
||||||
GPIO_Conf.GPIO_Pin = GPIO_Pin_10;
|
GPIO_Conf.GPIO_Pin = GPIO_Pin_10;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||||
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(GPIOB, &GPIO_Conf);
|
GPIO_Init(GPIOB, &GPIO_Conf);
|
||||||
GPIO_Conf.GPIO_Pin = GPIO_Pin_11;
|
GPIO_Conf.GPIO_Pin = GPIO_Pin_11;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||||
GPIO_Init(GPIOB, &GPIO_Conf);
|
GPIO_Init(GPIOB, &GPIO_Conf);
|
||||||
|
|
||||||
init_usart_debug();
|
init_usart_debug();
|
||||||
|
|
||||||
RCC_AHBPeriphClockCmd ( RCC_AHBPeriph_DMA1 , ENABLE ) ;
|
RCC_AHBPeriphClockCmd ( RCC_AHBPeriph_DMA1 , ENABLE ) ;
|
||||||
DMA_DeInit(DMA1_Channel1);
|
DMA_DeInit(DMA1_Channel1);
|
||||||
DMA_InitStructure.DMA_BufferSize = 2;
|
DMA_InitStructure.DMA_BufferSize = 2;
|
||||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
|
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
|
||||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||||
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &ADCVal;
|
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &ADCVal;
|
||||||
ADC_DMACmd(ADC1, ENABLE);
|
ADC_DMACmd(ADC1, ENABLE);
|
||||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
|
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
|
||||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
|
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
|
||||||
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
|
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
|
||||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
|
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
|
||||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||||
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
|
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
|
||||||
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
|
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
|
||||||
DMA_Cmd(DMA1_Channel1, ENABLE);
|
DMA_Cmd(DMA1_Channel1, ENABLE);
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN;
|
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_Init(GPIOA, &GPIO_Conf);
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN;
|
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);
|
GPIO_Init(GPIOA, &GPIO_Conf);
|
||||||
RCC_ADCCLKConfig (RCC_PCLK2_Div2);
|
RCC_ADCCLKConfig (RCC_PCLK2_Div2);
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
||||||
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||||
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
|
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_ExternalTrigConv = ADC_ExternalTrigConv_None;
|
||||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||||
ADC_InitStructure.ADC_NbrOfChannel = 2;
|
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_5, 1,ADC_SampleTime_28Cycles5); // define regular conversion config
|
||||||
ADC_RegularChannelConfig(ADC1,ADC_Channel_6, 2,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_DMACmd(ADC1, ENABLE);
|
||||||
ADC_Cmd (ADC1,ENABLE); //enable ADC
|
ADC_Cmd (ADC1,ENABLE); //enable ADC
|
||||||
ADC_ResetCalibration(ADC1); // Reset previous calibration
|
ADC_ResetCalibration(ADC1); // Reset previous calibration
|
||||||
while(ADC_GetResetCalibrationStatus(ADC1));
|
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));
|
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() {
|
void spi_init() {
|
||||||
GPIO_Conf.GPIO_Pin = radioSDIpin;
|
GPIO_Conf.GPIO_Pin = radioSDIpin;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||||
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(GPIOB, &GPIO_Conf);
|
GPIO_Init(GPIOB, &GPIO_Conf);
|
||||||
|
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
|
||||||
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||||
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
||||||
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
|
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
|
||||||
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
|
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
|
||||||
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
||||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
|
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
|
||||||
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
||||||
SPI_InitStructure.SPI_CRCPolynomial = 7;
|
SPI_InitStructure.SPI_CRCPolynomial = 7;
|
||||||
SPI_Init(SPI2, &SPI_InitStructure);
|
SPI_Init(SPI2, &SPI_InitStructure);
|
||||||
SPI_SSOutputCmd(SPI2, ENABLE);
|
SPI_SSOutputCmd(SPI2, ENABLE);
|
||||||
SPI_Cmd(SPI2, ENABLE);
|
SPI_Cmd(SPI2, ENABLE);
|
||||||
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
||||||
SPI_Init(SPI2, &SPI_InitStructure);
|
SPI_Init(SPI2, &SPI_InitStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_deinit() {
|
void spi_deinit() {
|
||||||
SPI_I2S_DeInit(SPI2);
|
SPI_I2S_DeInit(SPI2);
|
||||||
GPIO_Conf.GPIO_Pin = radioSDIpin;
|
GPIO_Conf.GPIO_Pin = radioSDIpin;
|
||||||
GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
|
GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
GPIO_Conf.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(GPIOB, &GPIO_Conf);
|
GPIO_Init(GPIOB, &GPIO_Conf);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_timer(const int rtty_speed) {
|
void init_timer(const int rtty_speed) {
|
||||||
TIM_TimeBaseInitTypeDef TIM2_TimeBaseInitStruct;
|
TIM_TimeBaseInitTypeDef TIM2_TimeBaseInitStruct;
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
||||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);
|
||||||
|
|
||||||
TIM2_TimeBaseInitStruct.TIM_Prescaler = 6/*0*/ - 1;// tick every 1/1000000 s
|
TIM2_TimeBaseInitStruct.TIM_Prescaler = 6/*0*/ - 1;// tick every 1/1000000 s
|
||||||
TIM2_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
|
TIM2_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
|
||||||
TIM2_TimeBaseInitStruct.TIM_Period = (uint16_t) ((1000000 / rtty_speed) - 1);
|
TIM2_TimeBaseInitStruct.TIM_Period = (uint16_t) ((1000000 / rtty_speed) - 1);
|
||||||
TIM2_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
|
TIM2_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||||
TIM2_TimeBaseInitStruct.TIM_RepetitionCounter = 0;
|
TIM2_TimeBaseInitStruct.TIM_RepetitionCounter = 0;
|
||||||
|
|
||||||
TIM_TimeBaseInit(TIM2,&TIM2_TimeBaseInitStruct);
|
TIM_TimeBaseInit(TIM2,&TIM2_TimeBaseInitStruct);
|
||||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
||||||
TIM_ITConfig(TIM2,TIM_IT_Update, ENABLE);
|
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_IRQChannel = TIM2_IRQn;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
TIM_Cmd(TIM2,ENABLE);
|
TIM_Cmd(TIM2,ENABLE);
|
||||||
}
|
}
|
||||||
|
|
42
init.h
42
init.h
|
@ -1,21 +1,21 @@
|
||||||
__IO uint16_t ADCVal[2];
|
__IO uint16_t ADCVal[2];
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void NVIC_Conf();
|
void NVIC_Conf();
|
||||||
|
|
||||||
void RCC_Conf();
|
void RCC_Conf();
|
||||||
|
|
||||||
void init_port();
|
void init_port();
|
||||||
|
|
||||||
void init_timer(const int rtty_speed);
|
void init_timer(const int rtty_speed);
|
||||||
|
|
||||||
void init_usart_gps(const uint32_t speed, const uint8_t enable_irq);
|
void init_usart_gps(const uint32_t speed, const uint8_t enable_irq);
|
||||||
|
|
||||||
void spi_init();
|
void spi_init();
|
||||||
|
|
||||||
void spi_deinit();
|
void spi_deinit();
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
514
main.c
514
main.c
|
@ -1,237 +1,277 @@
|
||||||
// STM32F100 and SI4032 RTTY transmitter
|
// STM32F100 and SI4032 RTTY transmitter
|
||||||
// released under GPL v.2 by anonymous developer
|
// released under GPL v.2 by anonymous developer
|
||||||
// enjoy and have a nice day
|
// enjoy and have a nice day
|
||||||
// ver 1.5a
|
// ver 1.5a
|
||||||
#include <stm32f10x_gpio.h>
|
#include <stm32f10x_gpio.h>
|
||||||
#include <stm32f10x_tim.h>
|
#include <stm32f10x_tim.h>
|
||||||
#include <stm32f10x_spi.h>
|
#include <stm32f10x_spi.h>
|
||||||
#include <stm32f10x_tim.h>
|
#include <stm32f10x_tim.h>
|
||||||
#include <stm32f10x_usart.h>
|
#include <stm32f10x_usart.h>
|
||||||
#include <stm32f10x_adc.h>
|
#include <stm32f10x_adc.h>
|
||||||
#include <stm32f10x_rcc.h>
|
#include <stm32f10x_rcc.h>
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <misc.h>
|
#include <misc.h>
|
||||||
#include "f_rtty.h"
|
#include "f_rtty.h"
|
||||||
#include "fun.h"
|
#include "init.h"
|
||||||
#include "init.h"
|
#include "config.h"
|
||||||
#include "config.h"
|
#include "radio.h"
|
||||||
#include "radio.h"
|
#include "ublox.h"
|
||||||
#include "ublox.h"
|
#include "delay.h"
|
||||||
#include "delay.h"
|
#include "aprs.h"
|
||||||
#include "aprs.h"
|
///////////////////////////// test mode /////////////
|
||||||
///////////////////////////// test mode /////////////
|
const unsigned char test = 0; // 0 - normal, 1 - short frame only cunter, height, flag
|
||||||
const unsigned char test = 0; // 0 - normal, 1 - short frame only cunter, height, flag
|
char callsign[15] = {CALLSIGN};
|
||||||
char callsign[15] = {CALLSIGN};
|
|
||||||
|
|
||||||
|
#define GREEN GPIO_Pin_7
|
||||||
#define GREEN GPIO_Pin_7
|
#define RED GPIO_Pin_8
|
||||||
#define RED GPIO_Pin_8
|
|
||||||
|
unsigned int send_cun; //frame counter
|
||||||
unsigned int send_cun; //frame counter
|
char status[2] = {'N'};
|
||||||
char status[2] = {'N'};
|
int napiecie;
|
||||||
int napiecie;
|
|
||||||
|
volatile char flaga = 0;
|
||||||
volatile char flaga = 0;//((((tx_delay / 1000) & 0x0f) << 3) | TX_POWER);
|
uint16_t CRC_rtty = 0x12ab; //checksum
|
||||||
uint16_t CRC_rtty = 0x12ab; //checksum
|
char buf_rtty[200];
|
||||||
char buf_rtty[200];
|
|
||||||
|
volatile unsigned char pun = 0;
|
||||||
volatile unsigned char pun = 0;
|
volatile unsigned int cun = 10;
|
||||||
volatile unsigned int cun = 10;
|
volatile unsigned char tx_on = 0;
|
||||||
volatile unsigned char tx_on = 0;
|
volatile unsigned int tx_on_delay;
|
||||||
volatile unsigned int tx_on_delay;
|
volatile unsigned char tx_enable = 0;
|
||||||
volatile unsigned char tx_enable = 0;
|
rttyStates send_rtty_status = rttyZero;
|
||||||
rttyStates send_rtty_status = rttyZero;
|
volatile char *rtty_buf;
|
||||||
volatile char *rtty_buf;
|
volatile uint16_t button_pressed = 0;
|
||||||
volatile uint16_t button_pressed = 0;
|
volatile uint8_t disable_armed = 0;
|
||||||
volatile uint8_t disable_armed = 0;
|
|
||||||
|
void send_rtty_packet();
|
||||||
void send_rtty_packet();
|
uint16_t gps_CRC16_checksum (char *string);
|
||||||
|
int srednia (int dana);
|
||||||
/**
|
|
||||||
* GPS data processing
|
|
||||||
*/
|
/**
|
||||||
void USART1_IRQHandler(void) {
|
* GPS data processing
|
||||||
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
|
*/
|
||||||
ublox_handle_incoming_byte((uint8_t) USART_ReceiveData(USART1));
|
void USART1_IRQHandler(void) {
|
||||||
}else if (USART_GetITStatus(USART1, USART_IT_ORE) != RESET) {
|
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
|
||||||
USART_ReceiveData(USART1);
|
ublox_handle_incoming_byte((uint8_t) USART_ReceiveData(USART1));
|
||||||
} else {
|
}else if (USART_GetITStatus(USART1, USART_IT_ORE) != RESET) {
|
||||||
USART_ReceiveData(USART1);
|
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);
|
void TIM2_IRQHandler(void) {
|
||||||
|
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {
|
||||||
if (aprs_is_active()){
|
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
||||||
aprs_timer_handler();
|
|
||||||
} else {
|
if (aprs_is_active()){
|
||||||
if (tx_on /*&& ++cun_rtty == 17*/) {
|
aprs_timer_handler();
|
||||||
send_rtty_status = send_rtty((char *) rtty_buf);
|
} else {
|
||||||
if (!disable_armed){
|
if (tx_on) {
|
||||||
if (send_rtty_status == rttyEnd) {
|
send_rtty_status = send_rtty((char *) rtty_buf);
|
||||||
GPIO_SetBits(GPIOB, RED);
|
if (!disable_armed){
|
||||||
if (*(++rtty_buf) == 0) {
|
if (send_rtty_status == rttyEnd) {
|
||||||
tx_on = 0;
|
GPIO_SetBits(GPIOB, RED);
|
||||||
tx_on_delay = tx_delay / (1000/RTTY_SPEED);
|
if (*(++rtty_buf) == 0) {
|
||||||
tx_enable = 0;
|
tx_on = 0;
|
||||||
radio_disable_tx();
|
tx_on_delay = tx_delay / (1000/RTTY_SPEED);
|
||||||
}
|
tx_enable = 0;
|
||||||
} else if (send_rtty_status == rttyOne) {
|
radio_disable_tx();
|
||||||
radio_rw_register(0x73, 0x02, 1);
|
}
|
||||||
GPIO_SetBits(GPIOB, RED);
|
} else if (send_rtty_status == rttyOne) {
|
||||||
} else if (send_rtty_status == rttyZero) {
|
radio_rw_register(0x73, 0x02, 1);
|
||||||
radio_rw_register(0x73, 0x00, 1);
|
GPIO_SetBits(GPIOB, RED);
|
||||||
GPIO_ResetBits(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 (!tx_on && --tx_on_delay == 0) {
|
||||||
}
|
tx_enable = 1;
|
||||||
if (--cun == 0) {
|
tx_on_delay--;
|
||||||
if (pun) {
|
}
|
||||||
GPIO_ResetBits(GPIOB, GREEN);
|
if (--cun == 0) {
|
||||||
pun = 0;
|
if (pun) {
|
||||||
} else {
|
GPIO_ResetBits(GPIOB, GREEN);
|
||||||
if (flaga & 0x80) {
|
pun = 0;
|
||||||
GPIO_SetBits(GPIOB, GREEN);
|
} else {
|
||||||
}
|
if (flaga & 0x80) {
|
||||||
pun = 1;
|
GPIO_SetBits(GPIOB, GREEN);
|
||||||
}
|
}
|
||||||
cun = 200;
|
pun = 1;
|
||||||
}
|
}
|
||||||
if (ALLOW_DISABLE_BY_BUTTON){
|
cun = 200;
|
||||||
if (ADCVal[1] > 1900){
|
}
|
||||||
button_pressed++;
|
if (ALLOW_DISABLE_BY_BUTTON){
|
||||||
if (button_pressed > (5 * RTTY_SPEED)){
|
if (ADCVal[1] > 1900){
|
||||||
disable_armed = 1;
|
button_pressed++;
|
||||||
GPIO_SetBits(GPIOB, RED);
|
if (button_pressed > (5 * RTTY_SPEED)){
|
||||||
GPIO_SetBits(GPIOB, GREEN);
|
disable_armed = 1;
|
||||||
}
|
GPIO_SetBits(GPIOB, RED);
|
||||||
} else {
|
GPIO_SetBits(GPIOB, GREEN);
|
||||||
if (disable_armed){
|
}
|
||||||
GPIO_SetBits(GPIOA, GPIO_Pin_12);
|
} else {
|
||||||
}
|
if (disable_armed){
|
||||||
button_pressed = 0;
|
GPIO_SetBits(GPIOA, GPIO_Pin_12);
|
||||||
}
|
}
|
||||||
}
|
button_pressed = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
}
|
||||||
#ifdef DEBUG
|
|
||||||
debug();
|
int main(void) {
|
||||||
#endif
|
#ifdef DEBUG
|
||||||
RCC_Conf();
|
debug();
|
||||||
NVIC_Conf();
|
#endif
|
||||||
init_port();
|
RCC_Conf();
|
||||||
|
NVIC_Conf();
|
||||||
init_timer(RTTY_SPEED);
|
init_port();
|
||||||
delay_init();
|
|
||||||
ublox_init();
|
init_timer(RTTY_SPEED);
|
||||||
|
delay_init();
|
||||||
GPIO_SetBits(GPIOB, RED);
|
ublox_init();
|
||||||
USART_SendData(USART3, 0xc);
|
|
||||||
radio_rw_register(0x02, 0xff, 0);
|
GPIO_SetBits(GPIOB, RED);
|
||||||
|
USART_SendData(USART3, 0xc);
|
||||||
radio_rw_register(0x03, 0xff, 0);
|
radio_rw_register(0x02, 0xff, 0);
|
||||||
radio_rw_register(0x04, 0xff, 0);
|
|
||||||
radio_soft_reset();
|
radio_rw_register(0x03, 0xff, 0);
|
||||||
// programowanie czestotliwosci nadawania
|
radio_rw_register(0x04, 0xff, 0);
|
||||||
radio_set_tx_frequency(RTTY_FREQUENCY);
|
radio_soft_reset();
|
||||||
|
// setting TX frequency
|
||||||
// Programowanie mocy nadajnika
|
radio_set_tx_frequency(RTTY_FREQUENCY);
|
||||||
radio_rw_register(0x6D, 00 | (TX_POWER & 0x0007), 1);
|
|
||||||
|
// setting TX power
|
||||||
radio_rw_register(0x71, 0x00, 1);
|
radio_rw_register(0x6D, 00 | (TX_POWER & 0x0007), 1);
|
||||||
radio_rw_register(0x87, 0x08, 0);
|
|
||||||
radio_rw_register(0x02, 0xff, 0);
|
radio_rw_register(0x71, 0x00, 1);
|
||||||
radio_rw_register(0x75, 0xff, 0);
|
radio_rw_register(0x87, 0x08, 0);
|
||||||
radio_rw_register(0x76, 0xff, 0);
|
radio_rw_register(0x02, 0xff, 0);
|
||||||
radio_rw_register(0x77, 0xff, 0);
|
radio_rw_register(0x75, 0xff, 0);
|
||||||
radio_rw_register(0x12, 0x20, 1);
|
radio_rw_register(0x76, 0xff, 0);
|
||||||
radio_rw_register(0x13, 0x00, 1);
|
radio_rw_register(0x77, 0xff, 0);
|
||||||
radio_rw_register(0x12, 0x00, 1);
|
radio_rw_register(0x12, 0x20, 1);
|
||||||
radio_rw_register(0x0f, 0x80, 1);
|
radio_rw_register(0x13, 0x00, 1);
|
||||||
rtty_buf = buf_rtty;
|
radio_rw_register(0x12, 0x00, 1);
|
||||||
tx_on = 0;
|
radio_rw_register(0x0f, 0x80, 1);
|
||||||
tx_enable = 1;
|
rtty_buf = buf_rtty;
|
||||||
|
tx_on = 0;
|
||||||
aprs_init();
|
tx_enable = 1;
|
||||||
radio_enable_tx();
|
|
||||||
|
aprs_init();
|
||||||
uint8_t rtty_before_aprs_left = RTTY_TO_APRS_RATIO;
|
radio_enable_tx();
|
||||||
|
|
||||||
while (1) {
|
uint8_t rtty_before_aprs_left = RTTY_TO_APRS_RATIO;
|
||||||
if (tx_on == 0 && tx_enable) {
|
|
||||||
if (rtty_before_aprs_left){
|
while (1) {
|
||||||
send_rtty_packet();
|
if (tx_on == 0 && tx_enable) {
|
||||||
rtty_before_aprs_left --;
|
if (rtty_before_aprs_left){
|
||||||
} else {
|
send_rtty_packet();
|
||||||
rtty_before_aprs_left = RTTY_TO_APRS_RATIO;
|
rtty_before_aprs_left --;
|
||||||
radio_enable_tx();
|
} else {
|
||||||
GPSEntry gpsData;
|
rtty_before_aprs_left = RTTY_TO_APRS_RATIO;
|
||||||
ublox_get_last_data(&gpsData);
|
radio_enable_tx();
|
||||||
USART_Cmd(USART1, DISABLE);
|
GPSEntry gpsData;
|
||||||
int8_t temperature = radio_read_temperature();
|
ublox_get_last_data(&gpsData);
|
||||||
uint16_t voltage = (uint16_t) srednia(ADCVal[0] * 600 / 4096);
|
USART_Cmd(USART1, DISABLE);
|
||||||
aprs_send_position(gpsData, temperature, voltage);
|
int8_t temperature = radio_read_temperature();
|
||||||
USART_Cmd(USART1, ENABLE);
|
uint16_t voltage = (uint16_t) srednia(ADCVal[0] * 600 / 4096);
|
||||||
radio_disable_tx();
|
aprs_send_position(gpsData, temperature, voltage);
|
||||||
}
|
USART_Cmd(USART1, ENABLE);
|
||||||
|
radio_disable_tx();
|
||||||
} else {
|
}
|
||||||
NVIC_SystemLPConfig(NVIC_LP_SEVONPEND, DISABLE);
|
|
||||||
__WFI();
|
} else {
|
||||||
}
|
NVIC_SystemLPConfig(NVIC_LP_SEVONPEND, DISABLE);
|
||||||
}
|
__WFI();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void send_rtty_packet() {
|
}
|
||||||
start_bits = RTTY_PRE_START_BITS;
|
|
||||||
int8_t temperatura = radio_read_temperature();
|
void send_rtty_packet() {
|
||||||
|
start_bits = RTTY_PRE_START_BITS;
|
||||||
napiecie = srednia(ADCVal[0] * 600 / 4096);
|
int8_t temperatura = radio_read_temperature();
|
||||||
GPSEntry gpsData;
|
|
||||||
ublox_get_last_data(&gpsData);
|
napiecie = srednia(ADCVal[0] * 600 / 4096);
|
||||||
if (gpsData.fix >= 3) {
|
GPSEntry gpsData;
|
||||||
flaga |= 0x80;
|
ublox_get_last_data(&gpsData);
|
||||||
} else {
|
if (gpsData.fix >= 3) {
|
||||||
flaga &= ~0x80;
|
flaga |= 0x80;
|
||||||
}
|
} else {
|
||||||
uint8_t lat_d = (uint8_t) abs(gpsData.lat_raw / 10000000);
|
flaga &= ~0x80;
|
||||||
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);
|
uint8_t lat_d = (uint8_t) abs(gpsData.lat_raw / 10000000);
|
||||||
uint32_t lon_fl = (uint32_t) abs(abs(gpsData.lon_raw) - lon_d * 10000000) / 100;
|
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);
|
||||||
sprintf(buf_rtty, "$$$$%s,%d,%02u%02u%02u,%s%d.%05ld,%s%d.%05ld,%ld,%d,%d,%d,%d,%d,%02x", callsign, send_cun,
|
uint32_t lon_fl = (uint32_t) abs(abs(gpsData.lon_raw) - lon_d * 10000000) / 100;
|
||||||
gpsData.hours, gpsData.minutes, gpsData.seconds,
|
|
||||||
gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl,
|
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.lon_raw < 0 ? "-" : "", lon_d, lon_fl,
|
gpsData.hours, gpsData.minutes, gpsData.seconds,
|
||||||
(gpsData.alt_raw / 1000), temperatura, napiecie, gpsData.sats_raw,
|
gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl,
|
||||||
gpsData.ok_packets, gpsData.bad_packets,
|
gpsData.lon_raw < 0 ? "-" : "", lon_d, lon_fl,
|
||||||
flaga);
|
(gpsData.alt_raw / 1000), temperatura, napiecie, gpsData.sats_raw,
|
||||||
CRC_rtty = 0xffff; //napiecie flaga
|
gpsData.ok_packets, gpsData.bad_packets,
|
||||||
CRC_rtty = gps_CRC16_checksum(buf_rtty + 4);
|
flaga);
|
||||||
sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff);
|
CRC_rtty = 0xffff; //napiecie flaga possibly not neccessary??
|
||||||
rtty_buf = buf_rtty;
|
CRC_rtty = gps_CRC16_checksum(buf_rtty + 4);
|
||||||
radio_enable_tx();
|
sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff);
|
||||||
tx_on = 1;
|
rtty_buf = buf_rtty;
|
||||||
|
radio_enable_tx();
|
||||||
send_cun++;
|
tx_on = 1;
|
||||||
}
|
|
||||||
|
send_cun++;
|
||||||
#ifdef DEBUG
|
}
|
||||||
void assert_failed(uint8_t* file, uint32_t line)
|
|
||||||
{
|
uint16_t gps_CRC16_checksum(char *string) {
|
||||||
while (1);
|
uint16_t crc = 0xffff;
|
||||||
}
|
char i;
|
||||||
#endif
|
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
|
||||||
|
|
4
radio.c
4
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 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 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);
|
uint16_t fc = (uint16_t) (((freq_in_mhz / ((SI4032_CLOCK / gen_div) * (hbsel + 1))) - fb - 24) * 64000);
|
||||||
|
|
||||||
radio_rw_register(0x72, 10, 1);
|
radio_rw_register(0x72, 10, 1);
|
||||||
|
@ -48,7 +48,7 @@ void radio_enable_tx() {
|
||||||
|
|
||||||
int8_t radio_read_temperature() {
|
int8_t radio_read_temperature() {
|
||||||
uint8_t temp;
|
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);
|
int8_t temperatura = (int8_t) (-64 + (temp * 5 / 10) - 16);
|
||||||
radio_rw_register(0x0f, 0x80, 1);
|
radio_rw_register(0x0f, 0x80, 1);
|
||||||
return temperatura;
|
return temperatura;
|
||||||
|
|
Ładowanie…
Reference in New Issue