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 & 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
|
||||
|
|
74
f_rtty.c
74
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;
|
||||
}
|
||||
|
|
24
f_rtty.h
24
f_rtty.h
|
@ -1,12 +1,12 @@
|
|||
#include <stdint.h>
|
||||
#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;
|
||||
#include <stdint.h>
|
||||
#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;
|
||||
|
|
490
init.c
490
init.c
|
@ -1,246 +1,246 @@
|
|||
#include <stm32f10x_flash.h>
|
||||
#include <stm32f10x_rcc.h>
|
||||
#include <stm32f10x_gpio.h>
|
||||
#include <stm32f10x_tim.h>
|
||||
#include <stm32f10x_usart.h>
|
||||
#include <stm32f10x_adc.h>
|
||||
#include <stm32f10x.h>
|
||||
#include <stm32f10x_dma.h>
|
||||
#include <stm32f10x_spi.h>
|
||||
#include <misc.h>
|
||||
#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 <stm32f10x_flash.h>
|
||||
#include <stm32f10x_rcc.h>
|
||||
#include <stm32f10x_gpio.h>
|
||||
#include <stm32f10x_tim.h>
|
||||
#include <stm32f10x_usart.h>
|
||||
#include <stm32f10x_adc.h>
|
||||
#include <stm32f10x.h>
|
||||
#include <stm32f10x_dma.h>
|
||||
#include <stm32f10x_spi.h>
|
||||
#include <misc.h>
|
||||
#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);
|
||||
}
|
||||
|
|
42
init.h
42
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
|
||||
|
|
514
main.c
514
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 <stm32f10x_gpio.h>
|
||||
#include <stm32f10x_tim.h>
|
||||
#include <stm32f10x_spi.h>
|
||||
#include <stm32f10x_tim.h>
|
||||
#include <stm32f10x_usart.h>
|
||||
#include <stm32f10x_adc.h>
|
||||
#include <stm32f10x_rcc.h>
|
||||
#include "stdlib.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <misc.h>
|
||||
#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 <stm32f10x_gpio.h>
|
||||
#include <stm32f10x_tim.h>
|
||||
#include <stm32f10x_spi.h>
|
||||
#include <stm32f10x_tim.h>
|
||||
#include <stm32f10x_usart.h>
|
||||
#include <stm32f10x_adc.h>
|
||||
#include <stm32f10x_rcc.h>
|
||||
#include "stdlib.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <misc.h>
|
||||
#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
|
||||
|
|
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 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;
|
||||
|
|
Ładowanie…
Reference in New Issue