kopia lustrzana https://github.com/Qyon/STM32_RTTY
more refactorings, some functions may be useless and are removed
rodzic
6426f48ff3
commit
0ac3d90c0b
4
f_rtty.c
4
f_rtty.c
|
@ -1,7 +1,7 @@
|
||||||
#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 *buffer) {
|
||||||
static uint8_t nr_bit = 0;
|
static uint8_t nr_bit = 0;
|
||||||
nr_bit++;
|
nr_bit++;
|
||||||
if (start_bits){
|
if (start_bits){
|
||||||
|
@ -13,7 +13,7 @@ rttyStates send_rtty(char *znak) {
|
||||||
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 ((*(buffer) >> (nr_bit - 2)) & 0x01) {
|
||||||
return rttyOne;
|
return rttyOne;
|
||||||
} else {
|
} else {
|
||||||
return rttyZero;
|
return rttyZero;
|
||||||
|
|
2
f_rtty.h
2
f_rtty.h
|
@ -8,5 +8,5 @@ typedef enum {
|
||||||
} 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 *);
|
||||||
extern uint8_t start_bits;
|
extern uint8_t start_bits;
|
||||||
|
|
28
init.c
28
init.c
|
@ -20,7 +20,7 @@ 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 "clock oscillator problem!"
|
||||||
#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);
|
||||||
|
@ -30,8 +30,8 @@ void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) {
|
||||||
|
|
||||||
USART_Cmd(USART1, DISABLE);
|
USART_Cmd(USART1, DISABLE);
|
||||||
|
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);// | RCC_APB2Periph_AFIO, ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||||
USART_InitStructure.USART_BaudRate = speed; //0x9c4;
|
USART_InitStructure.USART_BaudRate = speed;
|
||||||
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;
|
||||||
|
@ -39,7 +39,7 @@ void init_usart_gps(const uint32_t speed, const uint8_t enable_irq) {
|
||||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
USART_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;
|
||||||
|
@ -166,29 +166,29 @@ void init_port()
|
||||||
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() {
|
||||||
|
@ -227,7 +227,7 @@ void init_timer(const int rtty_speed) {
|
||||||
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 - 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;
|
||||||
|
@ -236,7 +236,7 @@ void init_timer(const int rtty_speed) {
|
||||||
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;
|
||||||
|
|
18
main.c
18
main.c
|
@ -30,7 +30,7 @@ char callsign[15] = {CALLSIGN};
|
||||||
|
|
||||||
unsigned int send_cun; //frame counter
|
unsigned int send_cun; //frame counter
|
||||||
char status[2] = {'N'};
|
char status[2] = {'N'};
|
||||||
int napiecie;
|
int voltage;
|
||||||
|
|
||||||
volatile char flaga = 0;
|
volatile char flaga = 0;
|
||||||
uint16_t CRC_rtty = 0x12ab; //checksum
|
uint16_t CRC_rtty = 0x12ab; //checksum
|
||||||
|
@ -48,7 +48,7 @@ volatile uint8_t disable_armed = 0;
|
||||||
|
|
||||||
void send_rtty_packet();
|
void send_rtty_packet();
|
||||||
uint16_t gps_CRC16_checksum (char *string);
|
uint16_t gps_CRC16_checksum (char *string);
|
||||||
int srednia (int dana);
|
// int srednia (int dana);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,7 +184,8 @@ int main(void) {
|
||||||
ublox_get_last_data(&gpsData);
|
ublox_get_last_data(&gpsData);
|
||||||
USART_Cmd(USART1, DISABLE);
|
USART_Cmd(USART1, DISABLE);
|
||||||
int8_t temperature = radio_read_temperature();
|
int8_t temperature = radio_read_temperature();
|
||||||
uint16_t voltage = (uint16_t) srednia(ADCVal[0] * 600 / 4096);
|
// uint16_t voltage = (uint16_t) srednia(ADCVal[0] * 600 / 4096);
|
||||||
|
uint16_t voltage = (uint16_t) ADCVal[0] * 600 / 4096;
|
||||||
aprs_send_position(gpsData, temperature, voltage);
|
aprs_send_position(gpsData, temperature, voltage);
|
||||||
USART_Cmd(USART1, ENABLE);
|
USART_Cmd(USART1, ENABLE);
|
||||||
radio_disable_tx();
|
radio_disable_tx();
|
||||||
|
@ -201,7 +202,8 @@ void send_rtty_packet() {
|
||||||
start_bits = RTTY_PRE_START_BITS;
|
start_bits = RTTY_PRE_START_BITS;
|
||||||
int8_t temperatura = radio_read_temperature();
|
int8_t temperatura = radio_read_temperature();
|
||||||
|
|
||||||
napiecie = srednia(ADCVal[0] * 600 / 4096);
|
// voltage = srednia(ADCVal[0] * 600 / 4096);
|
||||||
|
voltage = ADCVal[0] * 600 / 4096;
|
||||||
GPSEntry gpsData;
|
GPSEntry gpsData;
|
||||||
ublox_get_last_data(&gpsData);
|
ublox_get_last_data(&gpsData);
|
||||||
if (gpsData.fix >= 3) {
|
if (gpsData.fix >= 3) {
|
||||||
|
@ -218,10 +220,10 @@ void send_rtty_packet() {
|
||||||
gpsData.hours, gpsData.minutes, gpsData.seconds,
|
gpsData.hours, gpsData.minutes, gpsData.seconds,
|
||||||
gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl,
|
gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl,
|
||||||
gpsData.lon_raw < 0 ? "-" : "", lon_d, lon_fl,
|
gpsData.lon_raw < 0 ? "-" : "", lon_d, lon_fl,
|
||||||
(gpsData.alt_raw / 1000), temperatura, napiecie, gpsData.sats_raw,
|
(gpsData.alt_raw / 1000), temperatura, voltage, gpsData.sats_raw,
|
||||||
gpsData.ok_packets, gpsData.bad_packets,
|
gpsData.ok_packets, gpsData.bad_packets,
|
||||||
flaga);
|
flaga);
|
||||||
CRC_rtty = 0xffff; //napiecie flaga possibly not neccessary??
|
CRC_rtty = 0xffff; //possibly not neccessary??
|
||||||
CRC_rtty = gps_CRC16_checksum(buf_rtty + 4);
|
CRC_rtty = gps_CRC16_checksum(buf_rtty + 4);
|
||||||
sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff);
|
sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff);
|
||||||
rtty_buf = buf_rtty;
|
rtty_buf = buf_rtty;
|
||||||
|
@ -245,7 +247,7 @@ uint16_t gps_CRC16_checksum(char *string) {
|
||||||
}
|
}
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int srednia(int dana) {
|
int srednia(int dana) {
|
||||||
static uint8_t nr_pom = 0;
|
static uint8_t nr_pom = 0;
|
||||||
static uint8_t first = 1;
|
static uint8_t first = 1;
|
||||||
|
@ -268,7 +270,7 @@ int srednia(int dana) {
|
||||||
sr = sr / 5;
|
sr = sr / 5;
|
||||||
return sr;
|
return sr;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
void assert_failed(uint8_t* file, uint32_t line)
|
void assert_failed(uint8_t* file, uint32_t line)
|
||||||
{
|
{
|
||||||
|
|
Ładowanie…
Reference in New Issue