Changeset - e3feb70c71e6
[Not reviewed]
default
0 2 0
Ethan Zonca - 10 years ago 2016-03-31 22:25:29
ez@ethanzonca.com
Commented out GPS code that wasn't compiling, added power saving options to si5351 code. Tx is now 66mA, no GPS.
2 files changed with 14 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/gps.c
Show inline comments
 
@@ -15,55 +15,55 @@ uint8_t nmeaBufferParsePosition = 0;
 

	
 
// Location of receive byte interrupt in the buffer
 
volatile uint16_t nmeaBufferDataPosition = 0;
 

	
 
// holds the byte ALREADY PARSED. includes starting character
 
int bytesReceived = 0;
 

	
 
//data (and checksum) of most recent transmission
 
char data[16];
 

	
 
//used to skip over bytes during parse
 
int skipBytes = 0;
 

	
 
//used to index data arrays during data collection
 
int numBytes = 0;
 

	
 
//variables to store data from transmission
 
//least significant digit is stored at location 0 of arrays
 
char tramsmissionType[7];
 

	
 

	
 
void gps_poweron(void)
 
{
 
    // NOTE: pchannel
 
    gpio_clear(GPS_ONOFF);
 
    //gpio_clear(GPS_ONOFF);
 
}
 

	
 
void gps_poweroff(void)
 
{
 
    // NOTE: pchannel
 
    gpio_set(GPS_ONOFF);
 
    //gpio_set(GPS_ONOFF);
 
}
 

	
 
char timestamp[12];	//hhmmss.ss
 
char* get_timestamp() 
 
{
 
	return timestamp;
 
}
 
	
 
char latitude[14];	//lllll.lla
 
char latitudeTmpTRIM[8];
 
char latitudeTmpLSB[4];
 
char* get_latitudeTrimmed() 
 
{
 
	strncpy(latitudeTmpTRIM, &latitude[0], 7);
 
	latitudeTmpTRIM[7] = 0x00;
 
	return latitudeTmpTRIM;
 
}
 
char* get_latitudeLSBs()
 
{
 
	strncpy(latitudeTmpLSB, &latitude[7], 3);
 
	latitudeTmpLSB[3] = 0x00;
 
	return latitudeTmpLSB;
 
}
 

	
 
@@ -151,91 +151,91 @@ enum decodeState {
 
	GGA_LATITUDE,
 
	GGA_LONGITUDE,
 
	GGA_QUALITY,
 
	GGA_SATELLITES,
 
	GGA_HDOP,
 
	GGA_ALTITUDE,
 
	GGA_WGS84,
 
	GGA_LAST_UPDATE,
 
	GGA_STATION_ID,
 
	//RMC data fields
 
	RMC_TIME,
 
	RMC_VALIDITY,
 
	RMC_LATITUDE,
 
	RMC_LONGITUDE,
 
	RMC_KNOTS,
 
	RMC_COURSE,
 
	RMC_DATE,
 
	RMC_MAG_VARIATION,
 
	
 
}decodeState;
 

	
 

	
 
void usart1_isr(void)
 
{
 
	uint8_t recv = usart_recv(GPS_USART);
 
	uint8_t recv = 0;// usart_recv(GPS_USART);
 
	//ECHO debug: usart_send_blocking(GPS_USART, recv);
 
	nmeaBuffer[nmeaBufferDataPosition % NMEABUFFER_SIZE] = recv;
 
	nmeaBufferDataPosition = (nmeaBufferDataPosition + 1) % NMEABUFFER_SIZE;
 
}
 

	
 
void gps_init() 
 
{
 
    uart_init();
 
    timestamp[0] = 0x00;
 
    latitude[0] = 0x00;
 
    longitude[0] = 0x00;
 
    numSatellites[0] = 0x00;
 
    hdop[0] = 0x00;
 
    knots[0] = 0x00;
 
    course[0] = 0x00;
 
    dayofmonth[0] = 0x00;
 

	
 
    gps_poweron();
 
    HAL_Delay(100); // Make sure GPS is awake and alive
 

	
 
    // Disable GLONASS mode
 
    uint8_t disable_glonass[20] = {0xB5, 0x62, 0x06, 0x3E, 0x0C, 0x00, 0x00, 0x00, 0x20, 0x01, 0x06, 0x08, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x01, 0x8F, 0xB2};
 

	
 
    gps_sendubx(disable_glonass, 20);
 

	
 
    // Enable power saving
 
    uint8_t enable_powersave[10] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92};
 
    gps_sendubx(enable_powersave, 10);
 

	
 

	
 
    // Set dynamic model 6 (<1g airborne platform)
 
    uint8_t airborne_model[] = { 0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC };
 
    gps_sendubx(airborne_model, sizeof(airborne_model)/sizeof(uint8_t));
 

	
 
}
 

	
 
void gps_sendubx(uint8_t* dat, uint8_t size)
 
{
 
    uint8_t sendctr;
 
    for(sendctr = 0; sendctr < size; sendctr++)
 
    {
 
        usart_send(GPS_USART, dat[sendctr]);
 
        //usart_send(GPS_USART, dat[sendctr]);
 
    }
 
}
 

	
 
// Could inline if program space available
 
static void setParserState(uint8_t state)
 
{
 
	decodeState = state;
 

	
 
	// If resetting, clear vars
 
	if(state == INITIALIZE)
 
	{
 
		calculatedChecksum = 0;
 
	}
 
	
 
	// Every time we change state, we have parsed a byte
 
	nmeaBufferParsePosition = (nmeaBufferParsePosition + 1) % NMEABUFFER_SIZE;
 
}
 

	
 

	
 

	
 
//// MKa GPS transmission parser START
 
void parse_gps_transmission(void){
 
	
 
	// Pull byte off of the buffer
src/main.c
Show inline comments
 
@@ -30,86 +30,95 @@ uint8_t tx_buffer[255];
 
// Frequencies and channel info
 
uint32_t freq = WSPR_DEFAULT_FREQ;
 
uint8_t symbol_count = WSPR_SYMBOL_COUNT;
 
uint16_t ctc = WSPR_CTC;
 
uint16_t tone_spacing = WSPR_TONE_SPACING;
 
volatile uint8_t proceed = 0;
 
 
// Bring up TCXO and oscillator IC
 
void encode_wspr(void)
 
{
 
    HAL_GPIO_WritePin(OSC_NOTEN, 0);
 
    HAL_GPIO_WritePin(TCXO_EN, 1);
 
    HAL_Delay(100);
 
 
    // Bring up the chip
 
    si5351_init(i2c_get(), SI5351_CRYSTAL_LOAD_8PF, 0);
 
    si5351_set_correction(0);
 
    //si5351_set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
 
    //si5351_set_ms_source(SI5351_CLK0, SI5351_PLLA);
 
    si5351_set_freq(WSPR_DEFAULT_FREQ * 100, 0, SI5351_CLK0);
 
    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); // Set for max power if desired (8ma max)
 
    si5351_output_enable(SI5351_CLK0, 1);
 
    //si5351_pll_reset(SI5351_PLLA);
 
 
    // Make sure the other outputs of the SI5351 are disabled
 
    si5351_output_enable(SI5351_CLK1, 0); // Disable the clock initially
 
    si5351_output_enable(SI5351_CLK2, 0); // Disable the clock initially
 
 
    // disable clock powers
 
    si5351_set_clock_pwr(SI5351_CLK1, 0);
 
    si5351_set_clock_pwr(SI5351_CLK2, 0);
 
 
 
    // Encode message to transmit
 
    wspr_encode(call, loc, dbm, tx_buffer);
 
 
    // Key transmitter
 
    si5351_output_enable(SI5351_CLK0, 1);
 
 
    // Loop through and transmit symbols TODO: Do this from an ISR or ISR-triggered main loop function call (optimal)
 
    uint8_t i;
 
    for(i=0; i<symbol_count; i++)
 
    {
 
        uint32_t freq2 = (freq * 100) + (tx_buffer[i] * tone_spacing);
 
        si5351_set_freq(freq2, 0, SI5351_CLK0);
 
        HAL_GPIO_TogglePin(LED_BLUE);
 
 
        proceed = 0;
 
        while(!proceed);
 
    }
 
 
    // Disable transmitter
 
    si5351_output_enable(SI5351_CLK0, 0);
 
 
    HAL_GPIO_WritePin(OSC_NOTEN, 1);
 
    HAL_GPIO_WritePin(TCXO_EN, 0);
 
}
 
 
 
TIM_HandleTypeDef htim1;
 
 
int main(void)
 
{
 
    HAL_Init();
 
 
    sysclk_init();
 
    gpio_init();
 
    dma_init();
 
    adc_init();
 
    i2c_init();
 
    gps_init();
 
//    gps_init();
 
 
    // Disable ICs
 
    HAL_GPIO_WritePin(OSC_NOTEN, 1);
 
    HAL_GPIO_WritePin(TCXO_EN, 0);
 
 
 
    // Start timer for WSPR
 
    __TIM1_CLK_ENABLE();
 
    htim1.Instance = TIM1;
 
    htim1.Init.Prescaler = 512; // gives 64uS ticks from 8MHz ahbclk
 
    htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
 
    htim1.Init.Period = ctc; // Count up to this value (how many 64uS ticks per symbol)
 
    htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 
    htim1.Init.RepetitionCounter = 0;
 
    HAL_TIM_Base_Init(&htim1);
 
    HAL_TIM_Base_Start_IT(&htim1);
 
    HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, 0, 0);
 
    HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
 
 
    HAL_Delay(100);
 
 
 
    jtencode_init();
 
    //gps_init();
0 comments (0 inline, 0 general)