Uporzadkowanie kodu radiowego

Poprawione synchronizacja RTTY
aprs_test
Łukasz Nidecki 2016-12-24 20:54:27 +01:00
rodzic 5f8ae7b626
commit f307c472f5
7 zmienionych plików z 78 dodań i 40 usunięć

Wyświetl plik

@ -1,9 +1,15 @@
#include <stdint.h>
#include "f_rtty.h"
volatile unsigned char nr_bit = 0;
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;
}

Wyświetl plik

@ -4,4 +4,7 @@ typedef enum {
rttyOne = 1,
rttyEnd = 2
} rttyStates;
rttyStates send_rtty( char *znak);
static const uint8_t RTTY_PRE_START_BITS = 10;
rttyStates send_rtty(char *znak);
extern uint8_t start_bits;

11
fun.c
Wyświetl plik

@ -53,17 +53,6 @@ void send_hex(unsigned char data) {
USART_SendData(USART3, ascii[data & 0x0f]);
}
uint8_t spi_sendrecv(uint16_t byte) {
GPIO_ResetBits(GPIOC, GPIO_Pin_13);
// wait for tx buffer
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI2, byte);
// wait for data in rx buffer
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
GPIO_SetBits(GPIOC, GPIO_Pin_13);
return SPI_I2S_ReceiveData(SPI2);
}
unsigned char czytaj_GPS(unsigned char pos, unsigned char len, char *source, char *destination) {
char *wyn;

1
fun.h
Wyświetl plik

@ -3,7 +3,6 @@ void print( char* s);
void sendtogps(char* s, unsigned char cun);
void send_hex(unsigned char data);
uint8_t spi_sendrecv(uint16_t byte);
unsigned char czytaj_GPS(unsigned char pos,unsigned char len, char *source, char * destination);
uint16_t gps_CRC16_checksum (char *string);
int srednia (int dana);

51
main.c
Wyświetl plik

@ -15,6 +15,7 @@
#include "f_rtty.h"
#include "fun.h"
#include "init.h"
#include "radio.h"
//**************config**************
char callsign[15] = {"NO1LIC-1"}; // put your callsign here
@ -48,7 +49,6 @@ char callsign[15] = {"NO1LIC-1"}; // put your callsign here
///////////////////////////// test mode /////////////
unsigned char test = 0; // 0 - normal, 1 - short frame only cunter, height, flag
#define WR 0x8000
#define gps_RMC_dlugosc 5
#define gps_RMC_dlugosc_len 10
#define gps_RMC_dlugosc_kier 6
@ -197,13 +197,13 @@ void TIM2_IRQHandler(void) {
tx_on = 0;
tx_on_delay = tx_delay;//2500;
tx_enable = 0;
temp = spi_sendrecv(0x0740 | WR);
temp = radio_rw_register(0x07, 0x40, 1);
}
} else if (send_rtty_status == rttyOne) {
temp = spi_sendrecv(0x7302 | WR);
temp = radio_rw_register(0x73, 0x02, 1);
GPIO_SetBits(GPIOB, RED);
} else if (send_rtty_status == rttyZero) {
temp = spi_sendrecv(0x7300 | WR);
temp = radio_rw_register(0x73, 0x00, 1);
GPIO_ResetBits(GPIOB, RED);
}
}
@ -243,28 +243,28 @@ int main(void) {
GPIO_SetBits(GPIOB, RED);
USART_SendData(USART3, 0xc);
print(menu);
temp = spi_sendrecv(0x02ff);
temp = radio_rw_register(0x02, 0xff, 0);
//send_hex(temp);
temp = spi_sendrecv(0x03ff);
temp = spi_sendrecv(0x04ff);
temp = spi_sendrecv(0x0780 | WR);
temp = radio_rw_register(0x03, 0xff, 0);
temp = radio_rw_register(0x04, 0xff, 0);
temp = radio_rw_register(0x07, 0x80, 1);
print(init_trx);
// programowanie czestotliwosci nadawania
radio_set_tx_frequency();
// Programowanie mocy nadajnika
temp = spi_sendrecv(0x6D00 | (Smoc & 0x0007) | WR);
temp = spi_sendrecv(0x7100 | WR);
temp = spi_sendrecv(0x8708);
temp = spi_sendrecv(0x02ff);
temp = spi_sendrecv(0x75ff);
temp = spi_sendrecv(0x76ff);
temp = spi_sendrecv(0x77ff);
temp = spi_sendrecv(0x1220 | WR);
temp = spi_sendrecv(0x1300 | WR);
temp = spi_sendrecv(0x1200 | WR);
temp = spi_sendrecv(0x0f80 | WR);
temp = radio_rw_register(0x6D, 00 | (Smoc & 0x0007), 1);
temp = radio_rw_register(0x71, 0x00, 1);
temp = radio_rw_register(0x87, 0x08, 0);
temp = radio_rw_register(0x02, 0xff, 0);
temp = radio_rw_register(0x75, 0xff, 0);
temp = radio_rw_register(0x76, 0xff, 0);
temp = radio_rw_register(0x77, 0xff, 0);
temp = radio_rw_register(0x12, 0x20, 1);
temp = radio_rw_register(0x13, 0x00, 1);
temp = radio_rw_register(0x12, 0x00, 1);
temp = radio_rw_register(0x0f, 0x80, 1);
rtty_buf = buf_rtty;
tx_on = 0;
tx_enable = 1;
@ -279,8 +279,9 @@ int main(void) {
}
if (tx_on == 0 && tx_enable) {
temperatura = spi_sendrecv(0x11ff); //odczyt ADC
temp = spi_sendrecv(0x0f80 | WR);
start_bits = RTTY_PRE_START_BITS;
temperatura = radio_rw_register(0x11, 0xff, 0); //odczyt ADC
temp = radio_rw_register(0x0f, 0x80, 1);
temperatura = -64 + (temperatura * 5 / 10) - 16;
napiecie = srednia(ADCVal[0] * 600 / 4096);
@ -309,7 +310,7 @@ int main(void) {
sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff);
rtty_buf = buf_rtty;
tx_on = 1;
temp = spi_sendrecv(0x0748 | WR);
temp = radio_rw_register(0x07, 0x48, 1);
send_cun++;
}
@ -388,9 +389,9 @@ int main(void) {
}
void radio_set_tx_frequency() {
temp = spi_sendrecv(0x7561 | WR); // FIXME: tutaj powinno zdaje się być ustawiane fbsel?!
temp = spi_sendrecv(0x7600 | (((uint16_t)fc >> 8) & 0x00ff) | WR);
temp = spi_sendrecv(0x7700 | ((uint16_t)fc & 0x00ff) | WR);
temp = radio_rw_register(0x75, 0x61, 1); // FIXME: tutaj powinno zdaje się być ustawiane fbsel?!
temp = radio_rw_register(0x76, (uint8_t) (((uint16_t)fc >> 8) & 0xff), 1);
temp = radio_rw_register(0x77, (uint8_t) ((uint16_t)fc & 0xff), 1);
}
#pragma clang diagnostic pop

22
radio.c 100644
Wyświetl plik

@ -0,0 +1,22 @@
//
// Created by Admin on 2016-12-24.
//
#include "radio.h"
uint8_t _spi_sendrecv(const uint16_t data_word) {
GPIO_ResetBits(GPIOC, radioNSELpin);
// wait for tx buffer
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI2, data_word);
// wait for data in rx buffer
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
GPIO_SetBits(GPIOC, radioNSELpin);
return (uint8_t) SPI_I2S_ReceiveData(SPI2);
}
uint8_t radio_rw_register(const uint8_t register_addr, uint8_t value, uint8_t write){
return _spi_sendrecv(((write ? register_addr | WR : register_addr) << 8) | value);
}

18
radio.h 100644
Wyświetl plik

@ -0,0 +1,18 @@
//
// Created by Admin on 2016-12-24.
//
#ifndef STM32_RTTY_RADIO_H
#define STM32_RTTY_RADIO_H
#include <stdint.h>
#include <stm32f10x_spi.h>
#include <stm32f10x_gpio.h>
static const uint16_t radioNSELpin = GPIO_Pin_13;
static const uint8_t WR = 0x80;
uint8_t _spi_sendrecv(const uint16_t data_word);
uint8_t radio_rw_register(const uint8_t register_addr, uint8_t value, uint8_t write);
#endif //STM32_RTTY_RADIO_H