# HG changeset patch # User Ethan Zonca # Date 2016-10-08 23:40:53 # Node ID 50cc79d449a428d9ad2295884ff1139249823f77 # Parent 659774b354b1d7cfd20e1187bc8813a80f67dbb1 GPS comms with ubx interface now functional! diff --git a/inc/gpio.h b/inc/gpio.h --- a/inc/gpio.h +++ b/inc/gpio.h @@ -9,7 +9,7 @@ enum _blinkrate BLINK_FAST = 50, BLINK_MED = 250, BLINK_SLOW = 500 -} +}; #define OSC_EN_Pin GPIO_PIN_1 diff --git a/src/gpio.c b/src/gpio.c --- a/src/gpio.c +++ b/src/gpio.c @@ -17,6 +17,7 @@ void gpio_init(void) GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + HAL_GPIO_WritePin(GPIOF, OSC_EN_Pin, 0); // disable // GPS enable pin @@ -25,7 +26,7 @@ void gpio_init(void) GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPS_NEN_GPIO_Port, &GPIO_InitStruct); - + HAL_GPIO_WritePin(GPS_NEN_GPIO_Port, GPS_NEN_Pin, 1); // disable /*Configure GPIO pins : PA0 PA2 PA3 PA4 PA5 PA7 PA15 */ @@ -60,6 +61,7 @@ void gpio_init(void) GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(TCXO_EN_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_WritePin(TCXO_EN_GPIO_Port, TCXO_EN_Pin, 0); // disable } diff --git a/src/gps.c b/src/gps.c --- a/src/gps.c +++ b/src/gps.c @@ -39,45 +39,84 @@ void gps_init() // Initialize serial port // done in poweron uart_init(); + gps_poweron(); + HAL_Delay(500); - // 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); - HAL_UART_Transmit(uart_gethandle(), disable_glonass, 20, 100); +// // uart1 ubx only +// +// uint8_t setUBXuart1 = {0xB5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0xD0, 0x08, 0x00, 0x00, 0x80, 0x25, +// 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9A, 0x79}; +// HAL_UART_Transmit(uart_gethandle(), setUBXuart1, sizeof(setUBXuart1)/sizeof(uint8_t), 100); +// HAL_Delay(100); +// +// +// // uart0 ubx only +// uint8_t setUBXuart0 = {0xB5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x08, 0x00, 0x00, 0x80, 0x25, +// 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x65}; +// HAL_UART_Transmit(uart_gethandle(), setUBXuart0, sizeof(setUBXuart0)/sizeof(uint8_t), 100); +// HAL_Delay(100); +// +// +// // uart1 ubx only +// +// uint8_t setUBXuart2 = {0xB5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x02, 0x00, 0x00, 0x00, 0xD0, 0x08, 0x00, 0x00, 0x80, 0x25, +// 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9B, 0x8D}; +// HAL_UART_Transmit(uart_gethandle(), setUBXuart2, sizeof(setUBXuart2)/sizeof(uint8_t), 100); +// HAL_Delay(100); - // Enable power saving - uint8_t enable_powersave[10] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92}; - //gps_sendubx(enable_powersave, 10); - HAL_UART_Transmit(uart_gethandle(), enable_powersave, 10, 100); + // Disable messages + uint8_t setGGA[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0XFF, 0X23}; + HAL_UART_Transmit(uart_gethandle(), setGGA, sizeof(setGGA)/sizeof(uint8_t), 100); + HAL_Delay(100); + + uint8_t ackbuffer[10]; + for(uint8_t i=0; i<10; i++) + ackbuffer[i] = 0xaa; + HAL_UART_Receive(uart_gethandle(), ackbuffer, 10, 100); + + uint8_t setZDA[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X08, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X07, 0X5B}; + HAL_UART_Transmit(uart_gethandle(), setZDA, sizeof(setZDA)/sizeof(uint8_t), 100); + HAL_Delay(100); + uint8_t setGLL[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X01, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X2A}; + HAL_UART_Transmit(uart_gethandle(), setGLL, sizeof(setGLL)/sizeof(uint8_t), 100); + HAL_Delay(100); - // 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)); - HAL_UART_Transmit(uart_gethandle(), airborne_model, sizeof(airborne_model)/sizeof(uint8_t), 100); + uint8_t setGSA[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X02, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X01, 0X31}; + HAL_UART_Transmit(uart_gethandle(), setGSA, sizeof(setGSA)/sizeof(uint8_t), 100); + HAL_Delay(100); + + uint8_t setGSV[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X03, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X02, 0X38}; + HAL_UART_Transmit(uart_gethandle(), setGSV, sizeof(setGSV)/sizeof(uint8_t), 100); + HAL_Delay(100); + + uint8_t setRMC[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X04, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X03, 0X3F}; + HAL_UART_Transmit(uart_gethandle(), setRMC, sizeof(setRMC)/sizeof(uint8_t), 100); + HAL_Delay(100); + + uint8_t setVTG[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X05, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X04, 0X46}; + HAL_UART_Transmit(uart_gethandle(), setVTG, sizeof(setRMC)/sizeof(uint8_t), 100); + HAL_Delay(100); - // Disable messages - uint8_t setGLL[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x2B}; - HAL_UART_Transmit(uart_gethandle(), setGLL, sizeof(setGLL)/sizeof(uint8_t), 100); - HAL_Delay(1); - - uint8_t setGSA[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x32}; - HAL_UART_Transmit(uart_gethandle(), setGSA, sizeof(setGSA)/sizeof(uint8_t), 100); - HAL_Delay(1); +// // 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); +// volatile HAL_StatusTypeDef res = HAL_UART_Transmit(uart_gethandle(), disable_glonass, 20, 100); +// +// // Enable power saving +// uint8_t enable_powersave[10] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92}; +// //gps_sendubx(enable_powersave, 10); +// res = HAL_UART_Transmit(uart_gethandle(), enable_powersave, 10, 100); +// +// +// // 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)); +// res = HAL_UART_Transmit(uart_gethandle(), airborne_model, sizeof(airborne_model)/sizeof(uint8_t), 100); - uint8_t setGSV[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x39}; - HAL_UART_Transmit(uart_gethandle(), setGSV, sizeof(setGSV)/sizeof(uint8_t), 100); - HAL_Delay(1); - uint8_t setRMC[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x40}; - HAL_UART_Transmit(uart_gethandle(), setRMC, sizeof(setRMC)/sizeof(uint8_t), 100); - HAL_Delay(1); - - uint8_t setVTG[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x46}; - HAL_UART_Transmit(uart_gethandle(), setVTG, sizeof(setRMC)/sizeof(uint8_t), 100); - HAL_Delay(1); } @@ -86,14 +125,25 @@ void gps_init() void gps_update_position() { // Request a NAV-POSLLH message from the GPS - uint8_t request[8] = {0xB5, 0x62, 0x01, 0x02, 0x00, 0x00, 0x03, - 0x0A}; + uint8_t request[8] = {0xB5, 0x62, 0x01, 0x02, 0x00, 0x00, 0x03, 0x0A}; + + volatile uint8_t check_a = 0; + volatile uint8_t check_b = 0; + for(uint8_t i = 2; i<6; i++) + { + check_a += request[i]; + check_b += check_a; + } + + //_gps_send_msg(request, 8); uint8_t flushed = uart_gethandle()->Instance->RDR; - HAL_UART_Transmit(uart_gethandle(), request, 8, 100); + volatile HAL_StatusTypeDef txres = HAL_UART_Transmit(uart_gethandle(), request, 8, 100); uint8_t buf[36]; - HAL_UART_Receive(uart_gethandle(), buf, 36, 100); + for(uint8_t i =0; i<36; i++) + buf[i] = 0xaa; + volatile HAL_StatusTypeDef result = HAL_UART_Receive(uart_gethandle(), buf, 36, 1000); //for(uint8_t i = 0; i < 36; i++) // buf[i] = _gps_get_byte(); @@ -125,6 +175,16 @@ void gps_update_time(uint8_t* hour, uint { // Send a NAV-TIMEUTC message to the receiver uint8_t request[8] = {0xB5, 0x62, 0x01, 0x21, 0x00, 0x00, 0x22, 0x67}; + + volatile uint8_t check_a = 0; + volatile uint8_t check_b = 0; + for(uint8_t i = 2; i<6; i++) + { + check_a += request[i]; + check_b += check_a; + } + + uint8_t flushed = uart_gethandle()->Instance->RDR; volatile HAL_StatusTypeDef res = HAL_UART_Transmit(uart_gethandle(), request, 8, 100); @@ -152,14 +212,17 @@ void gps_update_time(uint8_t* hour, uint void gps_check_lock(uint8_t* lock, uint8_t* sats) { // Construct the request to the GPS - uint8_t request[8] = {0xB5, 0x62, 0x01, 0x06, 0x00, 0x00, - 0x07, 0x16}; + uint8_t request[8] = {0xB5, 0x62, 0x01, 0x06, 0x00, 0x00, 0x07, 0x16}; uint8_t flushed = uart_gethandle()->Instance->RDR; HAL_UART_Transmit(uart_gethandle(), request, 8, 100); + + // Get the message back from the GPS uint8_t buf[60]; - HAL_UART_Receive(uart_gethandle(), buf, 60, 100); + for(uint8_t i=0; i<60; i++) + buf[i] = 0xaa; + volatile HAL_StatusTypeDef res = HAL_UART_Receive(uart_gethandle(), buf, 60, 3000); // Verify the sync and header bits // if( buf[0] != 0xB5 || buf[1] != 0x62 ) @@ -168,7 +231,9 @@ void gps_check_lock(uint8_t* lock, uint8 // led_set(LED_RED, 1); // Check 60 bytes minus SYNC and CHECKSUM (4 bytes) -// if( !_gps_verify_checksum(&buf[2], 56) ) led_set(LED_RED, 1); + if( !_gps_verify_checksum(&buf[2], 56) ) + led_blink(2); + // Return the value if GPSfixOK is set in 'flags' if( buf[17] & 0x01 ) diff --git a/src/main.c b/src/main.c --- a/src/main.c +++ b/src/main.c @@ -22,7 +22,7 @@ enum _state SYSTEM_IDLE, // awaiting RTC interrupt for wakeup TODO wake up before scheduled time to get fix? SYSTEM_GPSACQ, // RTC interrupted SYSTEM_WSPRTX, // Wait for timeslot and actually transmit the message -} +}; int main(void) @@ -54,7 +54,7 @@ int main(void) { blink_rate = BLINK_SLOW; // Wait for RTC wakeup interrupt - wfi(); + //wfi(); //enter_sleep(); // Somehow go to another state when we get an interrupt @@ -68,9 +68,14 @@ int main(void) blink_rate = BLINK_FAST; // TODO: probably don't power on all the time, just on state transition - gps_poweron(); - HAL_Delay(500); - gps_update_position(); +// gps_poweron(); +// HAL_Delay(100); + HAL_Delay(1000); +// gps_update_position(); + + uint8_t fix_ok = 0; + uint8_t numsats = 0; + gps_check_lock(&fix_ok, &numsats); if(fix_ok) { @@ -84,10 +89,10 @@ int main(void) // TODO: Set wspr countdown timer for this transmission! state = SYSTEM_WSPRTX; } - else if(fix_timeout) - { - // Flash error code and go to idle probably? or just try forever? - } +// else if(fix_timeout) + // { + // // Flash error code and go to idle probably? or just try forever? + // } } break; @@ -96,10 +101,10 @@ int main(void) case SYSTEM_WSPRTX: { // Wait for wspr countdown timer to expire and go to tx - if(timeout_expired) - { - wspr_transmit(); - } +// if(timeout_expired) +// { +// wspr_transmit(); +// } // Schedule next wakeup (maybe 2mins prior ot timeslot if no osc trim) // Next wakeup should enter SYSTEM_GPSACQ state...