int main(void) { uint8_t dest[] = {0x02,0x17,0x31,0x88,0xAF,0x4B}; uint8_t data[100];// = {0x11,0x23,0x58}; uint8_t buffer[100]; uint8_t sendData[100]; uint8_t packetId=0; uint8_t packetSize; uint16_t nextPacket; uint16_t j; //initialize DDRA = 0xFF; //set PORTA to output wdt_disable(); //disable watchdog init_SPI(); //init SPI src_ENC(); //init ENC init_ENC(); rxen_ENC(); //start reading packets //read packets while(1); }
//////////////////// MAIN ///////////////////////////// int main (void) { int i; float temperature, pressure; float QNHPA; const int QNH_Calib=2; //AO: TODO Make this settable at startup and //write to nvRAM. float altitude_m,altitude_ft; struct ms5611_vars baro; //Coordinates for writing values on screen: uint8_t ALTFT_x=190, ALTFT_y=100; uint8_t QNH_x=90,QNH_y=120; //Location on screen to print QNH uint8_t ALTM_x=QNH_x, ALTM_y=140; uint8_t BARO_x=QNH_x,BARO_y=160; //Location on screen to print BARO uint8_t TEMP_x=QNH_x,TEMP_y=180; //Location on screen to print TEMP //TODO: Remove obsolete code. //TODO: Baro_Delay_Max becomes a #define. // int GPIO_Delay_Max =250; //Led's will stay on for this many ms. // int BARO_Delay_Max =200; //Baro refresh rate. //Display related: int a; // Both single speed and double speed access works. // Single speed is slower, needs less memory, vice versa for double speed. //u8g_InitComFn(&u8g, &u8g_dev_ssd1306_128x64_i2c, u8g_com_hw_i2c_fn); u8g_InitComFn(&u8g, &u8g_dev_ssd1306_128x64_2x_i2c, u8g_com_hw_i2c_fn); // Initialize hardware: disable_JTAG(); //So that some pins (notably LED) are freed up for use. init_BKP(); //Battery backup/RTC module init. init_ENC(); //Initialize ports connected to encoder. init_LED_GPIO(); //Initialize ports connected to LED. /* Init Chan's Embedded String Functions (xprintf etc) */ xdev_out(uart_putc); xdev_in(uart_getc); init_USART1(); // Initialize USART1: uart_open (USART1, 115200, 0); //USART2 is not supported. if (SysTick_Config(SystemCoreClock/1000)) while (1); // Every 1 msec, the timer will trigger a call to the SysTick_Handler. xprintf ("STM32F103 Naze32/Flip32.\n\r"); xprintf("System core clock rate is %d Hz\n\r",SystemCoreClock); xprintf("QNH calibration value set to: %d. \n\r",QNH_Calib); //Turn off LED LED_OFF(); QNH = BKP_ReadBackupRegister (BKP_DR1); QNH=1013; //TODO: Naze32 has no provision for backup battery connection. // The pin V_bat is connected to supply... // The function works correctly. Needs a board with V_bat wired correctly. if (QNH<950) //Quick sanity check. QNH=950; else if (QNH>1050) QNH=1050; ms5611_init(&baro); ms5611_measure(&baro); ms5611_calculate(&baro); QNHPA = (QNH+QNH_Calib)*100; //Convert to Pa. baro.pressure is also in pa. //Note: Uncomment following line for AGL measurement. //QNHPA= baro.pressure; BARO_Delay = BARO_Delay_Max; //Counts the number of timer ticks so far. //Display an introductory info message and wait 3s before starting: u8g_FirstPage(&u8g); do { draw_Intro(); } while ( u8g_NextPage(&u8g) ); i=0; while(i < INTRO_WAIT_MS){ //Keep info screen up for some time. if (TimerEventFlag==TRUE){ TimerEventFlag=FALSE; ++i; } } while (1) { if (TimerEventFlag==TRUE){ // QNH adjustment used to live here but because of the long delay // in calculating the altitude, it was moved into the ISR. TimerEventFlag=FALSE; } //Time to update barometer?: if (BARO_Delay >=BARO_Delay_Max){ BARO_Delay=0; //LED_ON(); //To check utilization. ms5611_measure(&baro); ms5611_calculate(&baro); //Note: Comment following line for AGL measurement. QNHPA = (QNH+QNH_Calib)*100;//Convert to Pa. baro.pressure is also in pa. altitude_m = 44330*(1- powf((baro.pressure/QNHPA),(0.19029495))); //m altitude_ft =altitude_m *3.28084; //ft. } //END: if (BARO_Delay >=BARO_Delay_Max) if (printQNH==TRUE){ //Time to print QNH: printQNH=FALSE; u8g_FirstPage(&u8g); do { draw_qnh((int)baro.pressure/100,(int)baro.temperature/100,(int)altitude_m,(int)altitude_ft,(int)QNH); } while ( u8g_NextPage(&u8g) ); BKP_WriteBackupRegister (BKP_DR1, QNH); } else if (printINFO==TRUE){ u8g_FirstPage(&u8g); do { draw_Intro(); } while ( u8g_NextPage(&u8g) ); }else{ u8g_FirstPage(&u8g); do { draw_alt((int)baro.pressure/100,(int)baro.temperature/100,(int)altitude_m,(int)altitude_ft,(int)QNH); } while ( u8g_NextPage(&u8g) ); } //LED_OFF(); //To check utilization. } //END: while(1) } //END: main