2016-12-10 20:29:51 +00:00
|
|
|
// 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>
|
2016-12-22 22:38:48 +00:00
|
|
|
#include <string.h>
|
2016-12-28 14:56:19 +00:00
|
|
|
#include <misc.h>
|
2016-12-10 20:29:51 +00:00
|
|
|
#include "f_rtty.h"
|
|
|
|
#include "fun.h"
|
2016-12-22 22:38:48 +00:00
|
|
|
#include "init.h"
|
2016-12-24 20:12:31 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "radio.h"
|
2016-12-27 23:03:08 +00:00
|
|
|
#include "ublox.h"
|
|
|
|
#include "delay.h"
|
2017-01-10 01:24:10 +00:00
|
|
|
#include "aprs.h"
|
2016-12-10 20:29:51 +00:00
|
|
|
///////////////////////////// test mode /////////////
|
2016-12-27 23:03:08 +00:00
|
|
|
const unsigned char test = 0; // 0 - normal, 1 - short frame only cunter, height, flag
|
2016-12-24 20:12:31 +00:00
|
|
|
char callsign[15] = {CALLSIGN};
|
2016-12-22 22:00:56 +00:00
|
|
|
|
2016-12-28 00:54:09 +00:00
|
|
|
|
2016-12-22 22:00:56 +00:00
|
|
|
#define GREEN GPIO_Pin_7
|
|
|
|
#define RED GPIO_Pin_8
|
2016-12-28 00:54:09 +00:00
|
|
|
|
2016-12-22 22:00:56 +00:00
|
|
|
unsigned int send_cun; //frame counter
|
|
|
|
char status[2] = {'N'};
|
2016-12-10 20:29:51 +00:00
|
|
|
int napiecie;
|
2016-12-27 23:03:08 +00:00
|
|
|
|
2016-12-28 10:53:34 +00:00
|
|
|
volatile char flaga = ((((tx_delay / 1000) & 0x0f) << 3) | Smoc);
|
2016-12-22 22:38:48 +00:00
|
|
|
uint16_t CRC_rtty = 0x12ab; //checksum
|
2016-12-10 20:29:51 +00:00
|
|
|
char buf_rtty[200];
|
2016-12-22 22:00:56 +00:00
|
|
|
char menu[] = "$$$$$$STM32 RTTY tracker by Blasiu, enjoy and see you on the HUB... \n\r";
|
2016-12-10 20:29:51 +00:00
|
|
|
char init_trx[] = "\n\rPowering up TX\n\r";
|
2016-12-28 10:53:34 +00:00
|
|
|
volatile unsigned char pun = 0;
|
|
|
|
volatile unsigned int cun = 10;
|
2016-12-10 20:29:51 +00:00
|
|
|
unsigned char dev = 0;
|
2016-12-28 00:54:09 +00:00
|
|
|
volatile unsigned char tx_on = 0;
|
2016-12-28 10:53:34 +00:00
|
|
|
volatile unsigned int tx_on_delay;
|
2016-12-28 00:54:09 +00:00
|
|
|
volatile unsigned char tx_enable = 0;
|
2016-12-24 19:02:35 +00:00
|
|
|
rttyStates send_rtty_status = rttyZero;
|
2016-12-28 10:53:34 +00:00
|
|
|
volatile char *rtty_buf;
|
2016-12-10 20:29:51 +00:00
|
|
|
unsigned char cun_off = 0;
|
2016-12-22 22:00:56 +00:00
|
|
|
|
|
|
|
|
2016-12-27 23:03:08 +00:00
|
|
|
/**
|
|
|
|
* GPS data processing
|
|
|
|
*/
|
|
|
|
void USART1_IRQHandler(void) {
|
2016-12-28 10:53:34 +00:00
|
|
|
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
|
2016-12-27 23:03:08 +00:00
|
|
|
ublox_handle_incoming_byte((uint8_t) USART_ReceiveData(USART1));
|
2016-12-28 10:53:34 +00:00
|
|
|
}else if (USART_GetITStatus(USART1, USART_IT_ORE) != RESET) {
|
|
|
|
USART_ReceiveData(USART1);
|
|
|
|
} else {
|
2017-01-10 01:24:10 +00:00
|
|
|
USART_ReceiveData(USART1);
|
2016-12-22 22:00:56 +00:00
|
|
|
}
|
2016-12-10 20:29:51 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 22:00:56 +00:00
|
|
|
void TIM2_IRQHandler(void) {
|
|
|
|
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {
|
|
|
|
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
2017-01-10 20:21:44 +00:00
|
|
|
|
|
|
|
if (aprs_is_active()){
|
|
|
|
aprs_timer_handler();
|
|
|
|
} else {
|
|
|
|
if (tx_on /*&& ++cun_rtty == 17*/) {
|
|
|
|
send_rtty_status = send_rtty((char *) rtty_buf);
|
|
|
|
if (send_rtty_status == rttyEnd) {
|
|
|
|
GPIO_SetBits(GPIOB, RED);
|
|
|
|
if (*(++rtty_buf) == 0) {
|
|
|
|
tx_on = 0;
|
|
|
|
tx_on_delay = tx_delay / (1000/RTTY_SPEED);//2500;
|
|
|
|
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);
|
2017-01-10 01:24:10 +00:00
|
|
|
}
|
2016-12-22 22:00:56 +00:00
|
|
|
}
|
2017-01-10 20:21:44 +00:00
|
|
|
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;
|
2017-01-10 01:24:10 +00:00
|
|
|
}
|
2017-01-10 20:21:44 +00:00
|
|
|
cun = 200;
|
2016-12-22 22:00:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-10 20:21:44 +00:00
|
|
|
|
2016-12-22 22:00:56 +00:00
|
|
|
}
|
2017-01-10 01:24:10 +00:00
|
|
|
|
2016-12-10 20:29:51 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 22:00:56 +00:00
|
|
|
int main(void) {
|
2016-12-10 20:29:51 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
debug();
|
|
|
|
#endif
|
2016-12-22 22:00:56 +00:00
|
|
|
RCC_Conf();
|
|
|
|
NVIC_Conf();
|
|
|
|
init_port();
|
2016-12-27 23:03:08 +00:00
|
|
|
|
2016-12-24 21:23:49 +00:00
|
|
|
init_timer(RTTY_SPEED);
|
2016-12-27 23:03:08 +00:00
|
|
|
delay_init();
|
|
|
|
ublox_init();
|
2016-12-22 22:00:56 +00:00
|
|
|
|
2016-12-27 23:03:08 +00:00
|
|
|
int8_t temperatura;
|
2016-12-22 22:00:56 +00:00
|
|
|
|
|
|
|
GPIO_SetBits(GPIOB, RED);
|
|
|
|
USART_SendData(USART3, 0xc);
|
2016-12-27 23:03:08 +00:00
|
|
|
radio_rw_register(0x02, 0xff, 0);
|
2016-12-22 22:00:56 +00:00
|
|
|
|
2016-12-27 23:03:08 +00:00
|
|
|
radio_rw_register(0x03, 0xff, 0);
|
|
|
|
radio_rw_register(0x04, 0xff, 0);
|
2016-12-24 21:23:49 +00:00
|
|
|
radio_soft_reset();
|
2016-12-22 22:00:56 +00:00
|
|
|
// programowanie czestotliwosci nadawania
|
2017-01-07 17:55:09 +00:00
|
|
|
radio_set_tx_frequency(RTTY_FREQUENCY);
|
2016-12-22 22:00:56 +00:00
|
|
|
|
|
|
|
// Programowanie mocy nadajnika
|
2016-12-27 23:03:08 +00:00
|
|
|
radio_rw_register(0x6D, 00 | (Smoc & 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);
|
2016-12-22 22:00:56 +00:00
|
|
|
rtty_buf = buf_rtty;
|
|
|
|
tx_on = 0;
|
|
|
|
tx_enable = 1;
|
|
|
|
//tx_enable =0;
|
2016-12-28 00:54:09 +00:00
|
|
|
//Button = ADCVal[1];
|
2017-01-10 01:24:10 +00:00
|
|
|
aprs_init();
|
2016-12-28 10:53:34 +00:00
|
|
|
radio_enable_tx();
|
2017-01-10 20:21:44 +00:00
|
|
|
|
|
|
|
uint16_t x = 710;
|
2017-01-10 01:24:10 +00:00
|
|
|
while (1){
|
|
|
|
radio_enable_tx();
|
|
|
|
USART_Cmd(USART1, DISABLE);
|
|
|
|
x+=1;
|
|
|
|
//aprs_change_tone_time(x);
|
|
|
|
aprs_test(x);
|
|
|
|
USART_Cmd(USART1, ENABLE);
|
|
|
|
|
|
|
|
radio_disable_tx();
|
|
|
|
_delay_ms(1000);
|
|
|
|
}
|
2016-12-22 22:00:56 +00:00
|
|
|
|
2016-12-28 16:12:39 +00:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
2016-12-27 23:03:08 +00:00
|
|
|
while (1) {
|
2016-12-22 22:00:56 +00:00
|
|
|
if (tx_on == 0 && tx_enable) {
|
2016-12-24 19:54:27 +00:00
|
|
|
start_bits = RTTY_PRE_START_BITS;
|
2016-12-27 23:03:08 +00:00
|
|
|
temperatura = radio_read_temperature();
|
2016-12-24 20:12:31 +00:00
|
|
|
|
2016-12-22 22:00:56 +00:00
|
|
|
napiecie = srednia(ADCVal[0] * 600 / 4096);
|
2016-12-27 23:03:08 +00:00
|
|
|
GPSEntry gpsData;
|
|
|
|
ublox_get_last_data(&gpsData);
|
|
|
|
if (gpsData.fix >= 3) {
|
|
|
|
flaga |= 0x80;
|
|
|
|
} else {
|
|
|
|
flaga &= ~0x80;
|
2016-12-22 22:00:56 +00:00
|
|
|
}
|
2016-12-28 00:54:09 +00:00
|
|
|
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;
|
2016-12-28 10:53:34 +00:00
|
|
|
|
2016-12-28 16:12:39 +00:00
|
|
|
sprintf(buf_rtty, "$$$$%s,%d,%02u%02u%02u,%s%d.%05ld,%s%d.%05ld,%ld,%d,%d,%d,%d,%d,%02x", callsign, send_cun,
|
2016-12-28 00:54:09 +00:00
|
|
|
gpsData.hours, gpsData.minutes, gpsData.seconds,
|
|
|
|
gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl,
|
|
|
|
gpsData.lon_raw < 0 ? "-" : "", lon_d, lon_fl,
|
2016-12-28 10:53:34 +00:00
|
|
|
(gpsData.alt_raw / 1000), temperatura, napiecie, gpsData.sats_raw,
|
|
|
|
gpsData.ok_packets, gpsData.bad_packets,
|
|
|
|
flaga);
|
2016-12-22 22:00:56 +00:00
|
|
|
CRC_rtty = 0xffff; //napiecie flaga
|
2016-12-28 16:12:39 +00:00
|
|
|
CRC_rtty = gps_CRC16_checksum(buf_rtty + 4);
|
2016-12-22 22:00:56 +00:00
|
|
|
sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff);
|
|
|
|
rtty_buf = buf_rtty;
|
2016-12-24 21:23:49 +00:00
|
|
|
radio_enable_tx();
|
2016-12-22 22:00:56 +00:00
|
|
|
tx_on = 1;
|
2016-12-24 21:23:49 +00:00
|
|
|
|
2016-12-22 22:00:56 +00:00
|
|
|
send_cun++;
|
2016-12-28 14:56:19 +00:00
|
|
|
} else {
|
|
|
|
NVIC_SystemLPConfig(NVIC_LP_SEVONPEND, DISABLE);
|
|
|
|
__WFI();
|
2016-12-22 22:00:56 +00:00
|
|
|
}
|
2016-12-27 23:03:08 +00:00
|
|
|
}
|
2016-12-22 22:38:48 +00:00
|
|
|
#pragma clang diagnostic pop
|
2016-12-28 16:12:39 +00:00
|
|
|
}
|
2016-12-22 22:38:48 +00:00
|
|
|
|
2016-12-10 20:29:51 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void assert_failed(uint8_t* file, uint32_t line)
|
|
|
|
{
|
2016-12-22 22:00:56 +00:00
|
|
|
while (1);
|
2016-12-10 20:29:51 +00:00
|
|
|
}
|
|
|
|
#endif
|