int main(void) { initButton(); initLEDs(); init_USART1(54000); // initialize USART1 @ 9600 baud //USART_puts(USART1, "Init complete! Hello World!&"); // just send a message to indicate that it works byte bull[5]; //Set lowest power parameter bull[0]=0x43; bull[1]=0x78; bull[2]=0x1E; bull[3]=0x09; bull[4]=7; USART_puts(USART1, bull); //Set 50000bps bull[0]=0x43; bull[1]=0x78; bull[2]=0x1E; bull[3]=0x08; bull[4]=50; USART_puts(USART1, bull); while (1){ char buff[4]="*&*"; USART_puts(USART1, buff); } }
int main(void) { unsigned char welcome_str[] = "xxyyzz\r\n"; u8 loop = 1; initPA15(); init_USART1(BT_BAUD); init_LIS302DL(); // setPA15On(); // togglePA15(); while(loop){ //Read and print the accelerometer values LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 6); printf("%d, %d ,%d\n",Buffer[0],Buffer[2],Buffer[4]); //Send data through the bluetooth communication UARTSend(welcome_str, sizeof(welcome_str)); //Wait some time befor ending the loop Delay(10000000); } /* Disable SPI1 used to drive the MEMS accelerometre */ SPI_Cmd(LIS302DL_SPI, DISABLE); /* Disable the UART connection */ USART_Cmd(USART1, DISABLE); }
int main(void) { ///////// Initial Portion ///////////////////////// init_USART1(9600); // initialize USART1 @ 9600 baud SystemCoreClockUpdate(); /* Get Core Clock Frequency */ if (SysTick_Config(SystemCoreClock / 1000)) { /* SysTick 1 msec interrupts */ while (1); /* Capture error */ } USART_puts(USART1, "Init 1 complete! Hello World!rn"); // just send a message to indicate that it works //Init GPIO for Leds on board and button input init_GPIO(); /////////////////- Loop - //////////////////////////////////// while (1){ // You can do whatever you want in here USART_puts(USART1, "Init 2 complete! Hello World! \r \n"); // just send a message to indicate that it works //GPIO_ToggleBits(GPIOD, GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13| GPIO_Pin_12 ); GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board Delay(200); GPIO_ToggleBits(GPIOD, GPIO_Pin_13 ); //Test Leds on board Delay(200); GPIO_ToggleBits(GPIOD, GPIO_Pin_14 ); //Test Leds on board Delay(1000); } ////////////////////////////////////////////////////////// }
int main(void) { // инициализация USART1 init_USART1(9600); while (1){ } }
int main() { SystemInit(); init_USART1(USART_BAUD_RATE); // initialize USART1 @ 9600 baud xTaskCreate(MainTask, (const signed char*)"MainTask", 1024, NULL, 1, NULL); vTaskStartScheduler(); return 0; }
int main(void) { AutoSampler_Init(); init_USART1(9600); WS2812_init(); DFT_Init(50); for(j = 0; j < 11; j++) WS2812_setPixelColor(100, 10, 10, 0, j); for(j = 0; j < 11; j++) WS2812_setPixelColor(100, 10, 10, 1, j); for(j = 0; j < 11; j++) WS2812_setPixelColor(100, 10, 10, 2, j); while (1) { int i, temp; DFT_Process(); for (i = 0; i < 3; i++) { prev_height[i] = height[i]; if (dft_outs[i] < prev_height[i]) height[i] = prev_height[i] - 1; else height[i] = dft_outs[i]; } // max height 64 so cast to int and right shift // height[0] = 10 * cq_out[0]; // height[1] = 10 * cq_out[1];//(uint32_t)(power[1]); // height[2] = 10 * cq_out[2];//(uint32_t)(power[2]); // height[0] = (uint32_t)(alpha * height[0]) + ((1 - alpha) * Output[2]); // height[1] = (uint32_t)(alpha * height[1]) + ((1 - alpha) * Output[8]); // height[2] = (uint32_t)(alpha * height[2]) + ((1 - alpha) * Output[38]); for(i = 0; i < 3; i++) { if(height[i] > 11) height[i] = 11; // turn on pixels to height for(j = 0; j < height[i]; j++) WS2812_setPixelBrightness(MAX_BRIGHTNESS, i, j); // turn off pixels past height for(j = height[i]; j < 11; j++) WS2812_setPixelBrightness(0, i, j); } WS2812_updateLEDs(); } }
int main(void) { init_USART1(9600); // initialize USART1 @ 9600 baud USART_puts(USART1, "Init complete! Hello World!\r\n"); // just send a message to indicate that it works while (1){ /* * You can do whatever you want in here */ } }
int main(void) { init_pins(); //Initializes the leds and the read write enabler pins as outputs init_USART1(BOTTOM_MOTOR_BAUD); // initialize USART1 baud rate init_USART2(TOP_BOTTOM_BAUD); // initialize USART2 baud rate GPIO_SetBits(GPIOD, READ_WRITE_ENABLER); //Turns the read/write pin for rs485 to write mode Delay(0xFFF); //Delays to give the read/write pin time to initialize while (1){ //Reads the top packet, converts the top packet to motor packets, and then sends the motor packets to the motor controllers if(handleTopPacket()) //If the read top packet function was successful, go within the if statement { GPIO_ResetBits(GPIOD, BLUE_LED); //Increments how many times the motor packets have been sent pollCounter++; //Waits for twenty packets to be sent to the motors before polling a motor. if(pollCounter > PACKETS_SENT_BEFORE_POLLED) { GPIO_SetBits(GPIOD, RED_LED); //Sends a packet to poll the motor at pollAddress pollMotor(pollAddress); if(!readSlavePacket()) //If we cannot read the packet { //TODO } //Add the fault data information to the packet we are sending back to the battle station //Increments through the addresses and goes back to address one after eight time pollAddress++; //Changes which motor will be polled next if(pollAddress == 9) pollAddress = 1; pollCounter = 0; //Resets the poll counter } } GPIO_ResetBits(GPIOD, GREED_LED); //Turns off the led GPIO_ResetBits(GPIOD, RED_LED); } }
//==================================================================== // MAIN FUNCTION //==================================================================== void main (void){ init_LCD(); init_GPIO(); //Get operating CLK freq RCC_ClocksTypeDef CLK; RCC_GetClocksFreq(&CLK); sysclock= (CLK.SYSCLK_Frequency)/((float)(pow(10,6))); //Sys clocks in MHz sprintf(lcdstring,"CLK %d MHz",sysclock); lcd_putstring(lcdstring); lcd_command(LINE_TWO); lcd_putstring("Servo Step Test, SW0"); //Init procedure waits for SW0 while(GPIO_ReadInputData(GPIOA)&GPIO_IDR_0){} lcd_command(CLEAR); init_ADC(); init_EXTI(); init_USART1(); init_TIM2(); init_TIM3(); init_TIM14(); init_TIM17(); for(;;){ while(TIM3OC2<=3800){ TIM3OC2++; TIM_SetCompare2(TIM3,TIM3OC2); for(int x=0;x<=255;x++){ for(int y=0;y<=255;y++){} } } lcd_command(CURSOR_HOME); sprintf(lcdstring,"ADC:%d ",(int) ADCval); lcd_putstring(lcdstring); lcd_command(LINE_TWO); sprintf(lcdstring,"TIM:%d ",(int) TIM2->CCR3);//TIMcmp); //TIM_SetCompare2(TIM3,(int)(64000*((0.9+1.1*ADCval/2047.0)/20.0))); lcd_putstring(lcdstring); } } // End of main
/******************************************************************************* * Function Name : main. * Descriptioan : Main routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int main(void) { Set_System(); Set_USBClock(); USB_Interrupts_Config(); USB_Init(); init_USART1(); Led_init(); //Configure Systick timing if (SysTick_Config(SystemCoreClock / 1000)) { /* Capture error */ STM_EVAL_LEDOn(LED10); while (1); } char dat[7]; strcpy(dat, conv_f2c(1.53)); while (1) { // if (bDeviceState == CONFIGURED) // { /* CDC_Receive_DATA(); //Check to see if we have data yet if (Receive_length != 0) { if (packet_sent == 1) CDC_Send_DATA ((unsigned char*)Receive_Buffer,Receive_length); Receive_length = 0; }*/ /* Toggle LED3 */ STM_EVAL_LEDToggle(LED3); /* Insert 100 ms delay */ USART_puts( USART1, dat); Delay(500); // } } }
int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* SysTick end of count event each 10ms */ unsigned int line; enum { TYPE_UNKNOWN=0, TYPE_RGB24, TYPE_RGB16, TYPE_YUV, } image_type = TYPE_UNKNOWN; RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); init_USART1(1048576); USART_puts(USART2,"\nLoaded,"); image_type = TYPE_YUV; frame_done=0; // LIS302DL_Reset(); /* SET USER Key */ /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */ // EXTILine0_Config(); // /* Initialize the LCD */ // STM32f4_Discovery_LCD_Init(); // LCD_Clear(LCD_COLOR_WHITE); // LCD_SetTextColor(LCD_COLOR_BLUE); // DCMI_Control_IO_Init();//funtion to configure reset and power pins of the camera **dont need for tw9910 // LCD_DisplayStringLine(LINE(2), " Camera Init.."); /* OV9655 Camera Module configuration */ // ****INIT the TW9910 in the following function if (DCMI_OV9655Config() == 0x00)//configures pins of DCMI,I2C and DMA and the camera settings, if it returns a positive response { //Successful // int fr=0; USART_puts(USART2,"In TW9910\n"); // LCD_DisplayStringLine(LINE(2), " "); // LCD_SetDisplayWindow(0, 0, 320, 240); // LCD_WriteRAM_Prepare(); //initialise an array here for the Image and ensure it is set up in the DMA configuration /* Enable DMA transfer */ DMA_Cmd(DMA2_Stream1, ENABLE); /* Enable DCMI interface */ DCMI_Cmd(ENABLE); /* Start Image capture */ DCMI_CaptureCmd(ENABLE); /*init the picture count*/ //useless for tw9910 and our case //init_picture_count(); // a function to initialise a variable from a counter file in the sdcard to name the new bmp file and file-xxx.bmp while (1) { // int i; //Delay(50); // int i; //for(i=0;i<1000;i++); if (frame_done) { // char s[5]; // fr++; // USART_puts(USART2,"\nNewFrame\n"); // if (capture_Flag == ENABLE) { DCMI_CaptureCmd(DISABLE); USART_puts(USART2,"\njpeg2\n"); huffman_start(IMG_HEIGHT & -8, IMG_WIDTH & -8); huffman_resetdc(); // USART_puts(USART2,"\njpeg\n"); // // for(i=0;i<FULLIMAGESIZE;i++){ // sprintf(s,",%x",imagearray[i]); // USART_puts(USART2,s); // //USART_writebyte(USART2,&imagearray[i]); // // } // // USART_puts(USART2,"\nDone"); // capture_Flag = DISABLE; // // Capture_Image_TO_Bmp(); //// LCD_SetDisplayWindow(0, 0, 320, 240); //// LCD_WriteRAM_Prepare(); // capture_Flag = ENABLE; // } // USART_puts(USART2,"\njpeg2\n"); for (line=0; line<NUM_LINES; line++) { uint8_t* line_buffer=(uint8_t *)&(imagearray[line*(IMG_WIDTH*IMG_HEIGHT*2/NUM_LINES)]); // encode the line using appropriate encoder switch (image_type) { // case TYPE_RGB24: encode_line_rgb24(line_buffer, line); break; // case TYPE_RGB16: encode_line_rgb16(line_buffer, line); break; case TYPE_YUV: encode_line_yuv(line_buffer, line); break; case TYPE_UNKNOWN: default:break; // fprintf(stderr, "error: %s, unsupported encoder for input '%s'\n", argv[0], argv[1]); // exit(1); } } // write .jpeg footer (end-of-image marker) huffman_stop(); USART_puts(USART2,"\njpegends\n"); DCMI_CaptureCmd(ENABLE); frame_done = 0; //if(fr==2) //while(1); } } } else { // LCD_SetTextColor(LCD_COLOR_RED); // LCD_DisplayStringLine(LINE(2), "Camera Init.. fails"); // LCD_DisplayStringLine(LINE(4), "Check the Camera HW "); // LCD_DisplayStringLine(LINE(5), " and try again "); /* Go to infinite loop */ while (1); } }
int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* SysTick end of count event each 10ms */ #ifndef YUVDEBUG unsigned int line; #endif RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); init_USART1(1048576); USART_puts(USART2,"\nLoaded,"); frame_done=0; /*Camera configuration */ // ****INIT the TW9910 in the following function if (DCMI_OV9655Config() == 0x00)//configures pins of DCMI,I2C and DMA and the camera settings, if it returns a positive response { //Successful int fr=0; USART_puts(USART2,"In TW9910\n"); /* Enable DMA transfer */ DMA_Cmd(DMA2_Stream1, ENABLE); /* Enable DCMI interface */ DCMI_Cmd(ENABLE); /* Start Image capture */ DCMI_CaptureCmd(ENABLE); while (1) { // int i; // Delay(50); if (frame_done) { char s[5]; int i; fr++; DCMI_CaptureCmd(DISABLE); #ifndef YUVDEBUG USART_puts(USART2,"\njpeg2\n"); huffman_start(IMG_HEIGHT & -8, IMG_WIDTH & -8); huffman_resetdc(); #endif #ifdef YUVDEBUG USART_puts(USART2,"\nNewFrame\n"); for(i=0;i<FULLIMAGESIZE*2;i++){ sprintf(s,",%x",imagearray[i]); USART_puts(USART2,s); } #endif #ifndef YUVDEBUG for (line=0; line<NUM_LINES; line++) { uint8_t* line_buffer=(uint8_t *)&(imagearray[line*(IMG_WIDTH*8*2)]); // encode the line using encoder encode_line_yuv(line_buffer, line); } // write .jpeg footer (end-of-image marker) huffman_stop(); #endif // /* print the frame counter */ // sprintf(s,",%d",fr); // USART_puts(USART2,s); //USART_puts(USART2,"\njpegends\n"); DCMI_CaptureCmd(ENABLE); frame_done = 0; } } } else {// Cant INIT the TW9910 USART_puts(USART2,"Cant Init TW9910"); /* Go to infinite loop */ while (1); } }
int main(void) { init_USART1(9600); // initialize USART1 @ 9600 baud USART_puts(USART1, "Init complete! Hello World!rn"); // just send a message to indicate that it works GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // address line RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); // clock and chip select line RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); // data line // GPIOA Configuration: Address line GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); // GPIOD Configuration: Data line GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOD, &GPIO_InitStructure); // GPIOB Configuration: TIM3 CH4 (PB1) - clock GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_TIM3); // GPIOB Configuration: chip enable GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Time base configuration */ unsigned int frequency = 600000; TIM_TimeBaseStructure.TIM_Period = 10000000 / (2 * frequency); TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 10000000) - 1; // Taktung: 100MHz TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); // PWM1 Mode configuration: Channel4 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC4Init(TIM3, &TIM_OCInitStructure); TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM3, ENABLE); /* TIM3 enable counter */ TIM_Cmd(TIM3, ENABLE); TIM3->CCR4 = TIM_TimeBaseStructure.TIM_Period / 2; SID_writeRegister(REG_VOICE_1_FREQ_LOW, 50); SID_writeRegister(REG_VOICE_1_FREQ_HI, 0); SID_writeRegister(REG_VOICE_1_CONTROL, 64); // square wave while (1) { } }
//*************************************************************************************** int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* Initialize Leds mounted on STM32F4-Discovery board */ STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); init_USART1(9600); // initialize USART1 @ 9600 baud char hello[] = "Init complete! Hello World!/n"; USART_puts_chars(USART1, hello); // just send a message to indicate that it works /* ADC3 configuration *******************************************************/ /* - Enable peripheral clocks */ /* - DMA2_Stream0 channel2 configuration */ /* - Configure ADC Channel12 pin as analog input */ /* - Configure ADC3 Channel12 */ ADC3_CH12_DMA_Config(); /* Start ADC3 Software Conversion */ ADC_SoftwareStartConv(ADC3); DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE); /* TIM Configuration */ TIM_Config(); PWM_Config(); /* Setup SysTick Timer for 1 msec interrupts. ------------------------------------------ 1. The SysTick_Config() function is a CMSIS function which configure: - The SysTick Reload register with value passed as function parameter. - Configure the SysTick IRQ priority to the lowest value (0x0F). - Reset the SysTick Counter register. - Configure the SysTick Counter clock source to be Core Clock Source (HCLK). - Enable the SysTick Interrupt. - Start the SysTick Counter. 2. You can change the SysTick Clock source to be HCLK_Div8 by calling the SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined inside the misc.c file. 3. You can change the SysTick IRQ priority by calling the NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function call. The NVIC_SetPriority() is defined inside the core_cm4.h file. 4. To adjust the SysTick time base, use the following formula: Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s) - Reload Value is the parameter to be passed for SysTick_Config() function - Reload Value should not exceed 0xFFFFFF */ if (SysTick_Config(SystemCoreClock / (6250))) { /* Capture error */ while (1); } set_PWM_duty( 75, LEFT_LED_880); static uint8_t duty_cycle = 0; while (1) { /* Toggle LED3 and LED6 */ //STM_EVAL_LEDToggle(LED3); //Delay(100); STM_EVAL_LEDToggle(LED4); Delay(100); STM_EVAL_LEDToggle(LED6); Delay(100); STM_EVAL_LEDToggle(LED5); Delay(100); } }
int main(void) { u8 loop = 1; char string[256]; //char string1[256]; uint16_t value; uint16_t sizestring; int icase = 0; initPA15(); init_USART1(BT_BAUD); systick_init(); led_Init(); button_init(); UART2_CONFIG(9600);// DMA_CONFIG(); setPA15On(); togglePA15(); while(loop){ //Send data through the bluetooth communication if (GPIOA->IDR & 0x0001) { if (CheckTick(delay_1,500)) { delay_1 = GetTickCount(); USART_puts(USART1, "troi oi 1 2 3 4 5 6 7 8 9 10\n"); led12(); } } if (CheckTick(delay_2,1000)) { delay_2 = GetTickCount(); //led13(); } if (CheckTick(delay_3,5000)) { delay_3 = GetTickCount(); led14(); } if (CheckTick(delay_4,100)) { delay_4 = GetTickCount(); while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET); //while(DMA_GetFlagStatus(DMA1_Stream2,DMA_FLAG_TCIF1) == RESET); value = USART_ReceiveData(USART1); memset(string,0,sizeof(string[0])*256); // Clear all to 0 so string properly represented sprintf(string,"%c",value); //sizestring = sizeof(string); //sprintf(string1,"%c",sizestring); if (string != NULL) { //USART_puts(USART1,string); if (string != NULL) icase = 1; else if (memchr(string, '2', sizeof(string))) icase = 2; else if (memchr(string, '3', sizeof(string))) icase = 3; else if (memchr(string, '4', sizeof(string))) icase = 4; else if (memchr(string, '5', sizeof(string))) icase = 5; //else icase = 6; switch (icase) { case 1: { USART_puts(USART1,string); icase = 0; led15(); } break; case 2: { USART_puts(USART1,"di xuong"); icase = 0; //led14(); } break; case 3: { USART_puts(USART1,"sang trai"); icase = 0; //led13(); } break; case 4: { USART_puts(USART1,"sang phai"); icase = 0; } break; case 5: { USART_puts(USART1,"can bang"); icase = 0; } break; // case 6: // { // //USART_puts(USART1,string); // icase = 0; // } // break; default: break; } //usart_send_string(string); //USART_SendData(USART1,value); } else { //usart_send_string(string); } led15(); } if (CheckTick(delay_5,250)) { delay_5 = GetTickCount(); } /* Disable the UART connection */ //USART_Cmd(USART1, DISABLE); } }
void comm_init (void) { init_USART1(9600); //init_USART1(460800); //seems to work OK //921600 doesnt seem to work }
void retarget_init() { init_USART1(9600); }
//////////////////// 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
int main(void) { ///////// Initial Portion ///////////////////////// init_USART1(460800); // initialize USART1 @ 9600 baud SystemCoreClockUpdate(); /* Get Core Clock Frequency */ if (SysTick_Config(SystemCoreClock / 1000000)) { /* SysTick 1 micro sec interrupts */ while (1); /* Capture error */ } USART_puts(USART1, "START !"); // just send a message to indicate that it works USART_puts(USART1, " \r \n"); // new line //Init GPIO for Leds on board and button input init_GPIO(); //Init SPI1 mySPI_Init(); //Delay for all periferals to be ready Delay(1000000); //Delay 1s for cap to be charged // mySPI_SendByte(0x11); //SDATAC //mySPI_Send3Byte(0x20,0x00,0x00); //Issue Reset Pulse for ADS1299 GPIO_ResetBits(GPIOD, GPIO_Pin_2); Delay(5); //Delay couples of clock cycles for ADS to read the signal GPIO_SetBits(GPIOD, GPIO_Pin_2); // Complete reset Pulse Delay(18); //Delay at least 18 clock cycles //Send stop command for ADS1299 /*Put CS line down send out command (stop command) SDATAC = 0x11, delay 1 micro seccond; put CS line up again*/ mySPI_SendByte(0x11); //SDATAC Delay(10000); //¾WREG CONFIG3 E0h // mySPI_SendData(0x43); //Configure register mySPI_Send3Byte(0x43,0x00,0xE1); //config3 ENABLE internal reference mySPI_Send3Byte(0x41,0x00,0xD6); // Config1 noi daisy chain; output data rate 250sps(F/4096) mySPI_Send3Byte(0x42,0x00,0xC0); //Config 2: test source externa, keep all as default //Write to 8 channel open the shorted mySPI_Send3Byte(0x45,0x00,0x00); //collecting data for channel 1-4 mySPI_Send3Byte(0x46,0x00,0x00); mySPI_Send3Byte(0x47,0x00,0x00); mySPI_Send3Byte(0x48,0x00,0x00); mySPI_Send3Byte(0x20,0x00,0x00); switch (getIDval & 0x1F ) { //least significant bits reports channels case 0x10: //16 gMaxChan = 4; //ads1294 break; case 0x11: //17 gMaxChan = 6; //ads1296 break; case 0x12: //18 gMaxChan = 8; //ads1298 break; case 0x1E: //30 gMaxChan = 8; //ads1299 USART_puts(USART1, "ADS1299 Hooray!"); break; default: gMaxChan = 0; } readRegister(18,0); // Read all register from address 0 //Start conversation. Set start pin to 1 GPIO_SetBits(GPIOD, GPIO_Pin_0); // Asking for data to send continueously mySPI_SendByte(0x10); //SDATAC begin to read data /////////////////- Loop - //////////////////////////////////// while (1){ uint8_t i =0; // You can do whatever you want in here /* USART_puts(USART1, "Init 2 complete! Hello World! \r \n"); // just send a message to indicate that it works //GPIO_ToggleBits(GPIOD, GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13| GPIO_Pin_12 ); GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board Delay(200); GPIO_ToggleBits(GPIOD, GPIO_Pin_13 ); //Test Leds on board Delay(200); GPIO_ToggleBits(GPIOD, GPIO_Pin_14 ); //Test Leds on board Delay(1000); */ // GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board if(!(GPIO_ReadInputData(GPIOD) & GPIO_Pin_1)){ //Read state of D1 (DRDY signal). Start new process if it is 0 for( i=0; i<9; i++){ char strADS[50]; getdata = mySPI_GetData(0x00); // regAddress = (0x20 | i); // getDataSPI = mySPI_Send3Byte((0x20 | i),0x00,0x00); //Increase to required address from the base address; if( i==2){ //Read 1 register at a time if (getdata > 0x007FFFFF) //Convert minus data { getdata = 0xFFFFFF - getdata; getdata = getdata/19373; //snprintf(strADS, 50, "Channel %d Val: %X \r \n", i, getdata); //convert int to string snprintf(strADS, 50, "E0,%d\n",getdata); //convert int to string USART_puts(USART1, strADS); //pirnt the address in string format } else{ getdata = getdata/19373; //snprintf(strADS, 50, "Channel %d Val: %X \r \n", i, getdata); //convert int to string snprintf(strADS, 50, "E0,%d\n",getdata); //convert int to string USART_puts(USART1, strADS); //pirnt the address in string format } } } //Delay(50000); } //if }// while (1) ////////////////////////////////////////////////////////// } //main