Exemplo n.º 1
0
int main(void)
{
  SystemInit();						// initialize MCU clocks and registers
  TM_DELAY_Init();					// initialize Delay library
  TM_DELAY_SetTime(0);				// Reset couter for systime
  Laser_GPIO_Conf();				// configure GPIO for laser control (to be able to enable/disable lasers via software
  TM_BKPSRAM_Init();				// initialize BKP RAM access library
  Laser_Update();			// load laser statuses saved in BKP RAM
  TM_USART_Init(OUTPUT_USART, OUTPUT_USART_PINS, OUTPUT_USART_SPEED);		// initialize UART used for collected Data output
  TM_USART_Init(MENU_USART, MENU_USART_PINS, MENU_USART_SPEED);				// initialize UART used for configuration
  TM_RTC_Init(TM_RTC_ClockSource_External);									// initialize RTC library
  TM_GPIO_Init(GPIOD, GPIO_Pin_8, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low); // configure GPIO for GSM status indication (RED LED)
  TM_GPIO_Init(GPIOD, GPIO_Pin_9, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low); // configure GPIO for GSM status indication (GREEN LED)
  Laser_ADC_Init();					// initialize ADC peripherals
  Menu_Init();						// initialize CLI library
  sfpInit();						// configure GPIO for SFP modules
  gsm_Init();						// initialize GSM module


  /* configure and initialize Ethernet hardware and LwIP stack */

  ETH_BSP_Config();					// configure ETH GPIOs
  printf("Ethernet MAC and PHY configured successfully!\n");
  LwIP_Init();						// start LwIP stack
  printf("LwIP stack initialized successfully!\n");
  UDP_Server_Init();				// start UDP Server
  printf("UDP Server initialized successfully!\n");

  //start periodic tasks

  /* GSM Status update "task" */
  GSM_Status_Update_Timer = TM_DELAY_TimerCreate(GSM_CHECK_INTERVAL, 1, 1, GSM_Status_Update_Timer_Task, NULL);
  printf("GSM status check task created!\n");
  /* Print results from remote devices "task" */
  Print_Results_Timer = TM_DELAY_TimerCreate(DATA_OUT_INTERVAL, 1, 1, Print_Results_Timer_Task, NULL);
  printf("Print collected data task created!\n");
  /* LaserLock status update "task" */
  LaserLock_Timer = TM_DELAY_TimerCreate(1000, 1, 1, LaserLock_Timer_Task, NULL);
  printf("Laser lock check task created!\n");

  while (1) {
	  /* CLI menu update */
	  Menu_Update();
      /* check if any packet received */
	  if (ETH_CheckFrameReceived())
	  {
		  /* process received ethernet packet */
		  LwIP_Pkt_Handle();
	  }
    /* handle periodic timers for LwIP */
    LwIP_Periodic_Handle(LocalTime);
    /* update laser statuses */
    Laser_Update();
    /* remove SMS messages which were read by system */
    delete_read_gsm_messages();
  }
} 
Exemplo n.º 2
0
int main(void) {
	/* RCC clocks typedef */
	RCC_ClocksTypeDef RCC_Clocks;
	/* RCC PLL structure */
	TM_RCC_PLL_t PLL;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay, systick has interrupts every 1ms by default */
	TM_DELAY_Init();
	
	/* Init USART2, TX: PA2, RX: PA3, 921600 baud */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 921600);
	
	/* Get current system clock */
	RCC_GetClocksFreq(&RCC_Clocks);
	
	/* Print current system clock */
	printf("System core clock: %d\n", RCC_Clocks.SYSCLK_Frequency);
	
	/* Read PLL settings */
	TM_RCC_GetPLL(&PLL);
	
	/* Set PLL N to some random value */
	PLL.PLLN = 200;
	
	/* Change PLL settings */
	TM_RCC_SetPLL(&PLL);
	
	/* Send something over USART */
	printf("This will not be seen correct on USART\n");
	
	/* Reinit everything with new clock */
	/* You have to reinit everything what depends on system CLOCK */
	/* Like timer prescalers, usarts, i2c, etc */
	
	/* Set new systick preload value */
	TM_DELAY_Init();
	
	/* Set new prescalers for USART settings */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 921600);
	
	/* Get current system clock */
	RCC_GetClocksFreq(&RCC_Clocks);
	
	/* Print current system clock */
	/* This will be seen on console with new settings */
	printf("System core clock after PLL change: %d\n", RCC_Clocks.SYSCLK_Frequency);
	
	while (1) {

	}
}
Exemplo n.º 3
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init USB peripheral */
	TM_USB_Init();
	
	/* Init VCP on HS port */
	TM_USBD_CDC_Init(TM_USB_HS);
	
	/* Start USB device mode on HS port */
	TM_USBD_Start(TM_USB_HS);
	
	while (1) {
		/* Process USB CDC device, send remaining data if needed */
		/* It is better if you call this in periodic timer, like each ms in SYSTICK handler */
		TM_USBD_CDC_Process(TM_USB_HS);
		
		/* Check if device is ready, if drivers are installed if needed on HS port */
		if (TM_USBD_IsDeviceReady(TM_USB_HS) == TM_USBD_Result_Ok) {
			/* Turn on green LED */
			TM_DISCO_LedOn(LED_GREEN);
			
			/* Check if user has changed parameters for COM port */
			TM_USBD_CDC_GetSettings(TM_USB_HS, &USB_Settings);
		
			/* Check if settings updated from user terminal */
			if (USB_Settings.Updated) {
				/* Reinit USART, only baudrate works in this example */
				TM_USART_Init(USART6, TM_USART_PinsPack_1, USB_Settings.Baudrate);
			}
		
			/* Check if anything received on HS port from user */
			while (TM_USBD_CDC_Getc(TM_USB_HS, &ch)) {
				/* One character received */
				
				/* Send character to USART */
				TM_USART_Putc(USART6, ch);
			}
			
			/* CHeck if any character received from USART */
			while (!TM_USART_BufferEmpty(USART6)) {
				/* Send data over USB CDC */
				TM_USBD_CDC_Putc(TM_USB_HS, TM_USART_Getc(USART6));
			}	
		} else {
			/* Turn off green LED */
			TM_DISCO_LedOff(LED_GREEN);
		}
	}
}
Exemplo n.º 4
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init USART, TX: PC6, RX: PC7, 921600 bauds */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 115200);
	
	/* Put test string */
	TM_USART_Puts(USART2, "Hello world\n");
	
	while (1) {
		/* Check if we have string "OK" in USART6 buffer */
		if (TM_USART_FindString(USART2, "OK")) {
			/* Send data back from buffer */
			while (!TM_USART_BufferEmpty(USART2)) {
				/* Send to computer */
				TM_USART_Putc(USART2, TM_USART_Getc(USART6));
			}
		}
	}
}
Exemplo n.º 5
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init USART, Pins not initialized yet, 921600 bauds */
	TM_USART_Init(USART6, TM_USART_PinsPack_Custom, 921600);
	
	/* Put test string */
	TM_USART_Puts(USART6, "Hello world\n");
	
	while (1) {
		/* Check if anything received */
		while (!TM_USART_BufferEmpty(USART6)) {
			/* Send data back from buffer */
			TM_USART_Putc(USART6, TM_USART_Getc(USART6));
		}
	}
}
uint8_t ESP8266_LL_USARTInit(uint32_t baudrate) {
	/* Init USART */
	TM_USART_Init(ESP8266_USART, ESP8266_USART_PP, baudrate);
	
	/* Return 0 = Successful */
	return 0;
}
Exemplo n.º 7
0
int main(void) {
	/* Initialize system */
	SystemInit();
	
	/* Init USART2 on pins TX = PA2, RX = PA3 */
	/* This pins are used on Nucleo boards for USB to UART via ST-Link */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 115200);
	
	/* Say string without DMA */
	TM_USART_Puts(USART2, "Hello via USART2 without DMA\n");
	
	/* Init TX DMA for USART2 */
	TM_USART_DMA_Init(USART2);
	
	/* Send data with DMA */
	TM_USART_DMA_Send(USART2, (uint8_t *)USART_Buffer, strlen(USART_Buffer));
	
	/* Wait till DMA works */
	/* You can do other stuff here instead of waiting for DMA to end */
	while (TM_USART_DMA_Sending(USART2));
	
	while (1) {
		/* If any string arrived over USART */
		/* Expecting "\n" at the end of string from USART terminal or any other source */
		if (TM_USART_Gets(USART2, USART_Buffer, sizeof(USART_Buffer))) {
			/* Send it back over DMA */
			TM_USART_DMA_Send(USART2, (uint8_t *)USART_Buffer, strlen(USART_Buffer));

			/* Wait till DMA works */
			/* You can do other stuff here instead of waiting for DMA to end */
			while (TM_USART_DMA_Sending(USART2));
		}
	}
}
Exemplo n.º 8
0
int main(void) {
	char str[15];
	//Initialize system
	SystemInit();
	//Initialize Delay library
	TM_DELAY_Init();
	
	//Initialize USART1-> TX: PA9, RX: PA10
	TM_USART_Init(USART1, TM_USART_PinsPack_1, 9600);
	
	TM_USART_Puts(USART1, "ADC example");
	
	//Initialize ADC1 on channel 0, this is pin PA0
	TM_ADC_Init(ADC1, ADC_Channel_0);
	//Initialize ADC1 on channel 3, this is pin PA3
	TM_ADC_Init(ADC1, ADC_Channel_3);
	
	while (1) {
		//							Read ADC1 Channel0					Read ADC1 Channel3
		sprintf(str, "%d: %d\n\r", TM_ADC_Read(ADC1, ADC_Channel_0), TM_ADC_Read(ADC1, ADC_Channel_3));
		TM_USART_Puts(USART1, str);
		
		Delayms(100);
	}
}
Exemplo n.º 9
0
int main(void) {
    /* Init system clock for maximum system speed */
    TM_RCC_InitSystem();

    /* Init HAL layer */
    HAL_Init();

    /* Init leds */
    TM_DISCO_LedInit();

    /* Init button */
    TM_DISCO_ButtonInit();

    /* Initialize USART, TX: PB6, RX: PB7 */
    TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);

    /* Initialize NRF24L01+ on channel 15 and 32bytes of payload */
    /* By default 2Mbps data rate and 0dBm output power */
    /* NRF24L01 goes to RX mode by default */
    TM_NRF24L01_Init(15, 32);

    /* Set RF settings, Data rate to 2Mbps, Output power to -18dBm */
    TM_NRF24L01_SetRF(TM_NRF24L01_DataRate_2M, TM_NRF24L01_OutputPower_M18dBm);

    /* Set my address, 5 bytes */
    TM_NRF24L01_SetMyAddress(MyAddress);

    /* Set TX address, 5 bytes */
    TM_NRF24L01_SetTxAddress(TxAddress);

    while (1) {
        /* If data is ready on NRF24L01+ */
        if (TM_NRF24L01_DataReady()) {
            /* Get data from NRF24L01+ */
            TM_NRF24L01_GetData(dataIn);

            /* Start send */
            TM_DISCO_LedOn(LED_GREEN);

            /* Send it back, automatically goes to TX mode */
            TM_NRF24L01_Transmit(dataIn);

            /* Wait for data to be sent */
            do {
                /* Wait till sending */
                transmissionStatus = TM_NRF24L01_GetTransmissionStatus();
            } while (transmissionStatus == TM_NRF24L01_Transmit_Status_Sending);

            /* Send done */
            TM_DISCO_LedOff(LED_GREEN);

            /* Go back to RX mode */
            TM_NRF24L01_PowerUpRx();
        }
    }
}
Exemplo n.º 10
0
int main(void) {
	uint16_t i, strposition;
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init USART6, TX: PC6, RX: PC7, 921600 bauds */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 921600);
	
	/* Create string with 10 predefined locations for strings */
	String = TM_STRING_Create(10);
	
	/* Add string to memory, allocated memory will be set depending on string length */
	TM_STRING_AddString(String, "First string");
	
	/* Add another string to memory, allocated memory will be set depending on string length */
	TM_STRING_AddString(String, "Second string");
	
	/* Send strings over USART */
	for (i = 0; i < String->Count; i++) {
		/* Print string to user */
		printf("%s\n", String->Strings[i]);
	}
	
	/* Add some strings */
	TM_STRING_AddString(String, "Third string");
	strposition = TM_STRING_AddString(String, "Forth string");
	TM_STRING_AddString(String, "Fifth string");
	
	/* Modify string number 4 */
	TM_STRING_ReplaceString(String, strposition, "Updated string");
	
	/* Send strings over USART */
	for (i = 0; i < String->Count; i++) {
		/* Print string to user */
		printf("%s\n", String->Strings[i]);
	}
	
	/* Delete string on position 1 = "Second string" */
	TM_STRING_DeleteString(String, 1);
	
	/* Free entire string memory with all strings */
	TM_STRING_FreeAll(String);
	
	while (1) {
		/* Do nothing */
	}
}
Exemplo n.º 11
0
int main(void){
	SystemInit();
	TM_DELAY_Init();
	TM_ILI9341_Init();
	TM_ILI9341_SetLayer1();

	/* Initialize USART2 at 115200 baud, TX: PD5, RX: PD6 */
	TM_USART_Init(USART2, TM_USART_PinsPack_2, 115200);
	
	uint8_t wacc = 0x3A; // 0xA6
	uint8_t racc = 0x3B; // 0xA7

	// 0x2D POWER_CTL: Power-saving features control
	TM_I2C_Write(I2C2, wacc, 0x2D, 0x08);
	// 0x31 DATA_FORMAT: Data format control
	//TM_I2C_Write(I2C1, wacc, 0x31, 0x0B); // FULL_RES and +- 16g
	TM_I2C_Write(I2C2, wacc, 0x31, 0x01); // fixed resolution and +- 4g
	// 0x2C BW_RATE: Data rate and power mode control
	TM_I2C_Write(I2C2, wacc, 0x2C, 0x0A);
	
	char str[16] = {0};
	sprintf(str, "delay = 100");
	TM_USART_Puts(USART2, str); 
	while(1){

		TM_ILI9341_Fill(ILI9341_COLOR_WHITE);
		TM_ILI9341_Puts(30, 30, str, &TM_Font_11x18, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLUE2);
		uint8_t buff[6] = {0};
		int16_t tri[3] = {0};
		TM_I2C_ReadMulti(I2C2, racc, 0x32, buff, 6);
		
		// original read digit
		tri[0] = (int16_t) ((uint16_t)buff[1] << 8 | (uint16_t)buff[0]);	
		tri[1] = (int16_t) ((uint16_t)buff[3] << 8 | (uint16_t)buff[2]);	
		tri[2] = (int16_t) ((uint16_t)buff[5] << 8 | (uint16_t)buff[4]);	
		
		float ftri[3] = {0}, divisor = 128.0f;
		ftri[0] = (float) tri[0] / divisor;
		ftri[1] = (float) tri[1] / divisor;
		ftri[2] = (float) tri[2] / divisor;
	
		sprintf(str, "%.3f,%.3f,%.3f\n\r", ftri[0], ftri[1], ftri[2]);
		TM_USART_Puts(USART2, str); 
		TM_ILI9341_Puts(30, 50, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE);
		
		Delayms(100);
	}

}
Exemplo n.º 12
0
int main(void) {
	char buf[30];
	uint8_t devices, i, j, count, device[2][8];
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize One Wire on pin PD0 */
	TM_OneWire_Init();
	
	/* Initialize USART, TX: PB6, RX: PB7 */
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	/* Checks for any device on 1-wire */
	devices = TM_OneWire_First();
	count = 0;
	while (devices) {
		count++;
		for (i = 0; i < 8; i++) {
			device[count - 1][i] = TM_OneWire_GetROM(i);
		}
		/* Check for new device */
		devices = TM_OneWire_Next();
	}
	/* If any devices on 1-wire */
	if (count > 0) {
		sprintf(buf, "Devices found on 1-wire: %d\n\r", count);
		TM_USART_Puts(USART1, buf);
		/* Display 64bit rom code */
		for (j = 0; j < count; j++) {
			for (i = 0; i < 8; i++) {
				sprintf(buf, "0x%02X ", device[j][i]);
				TM_USART_Puts(USART1, buf);
			}
			TM_USART_Puts(USART1, "\n\r");
		}
	} else {
		TM_USART_Puts(USART1, "No devices on OneWire.\n\r");
	}
	
	while (1) {

	}
}
Exemplo n.º 13
0
int main(void) {	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initiaize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize Leds */
	TM_DISCO_LedInit();
	
	/* Initialize USART, TX: PB10, RX: PB11 */
	TM_USART_Init(USART3, TM_USART_PinsPack_1, 115200);
	
	/* Initialize RTC with internal 32768Hz clock */
	/* It's not very accurate */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* RTC was first time initialized */
		/* Do your stuff here */
		/* eg. set default time */
	}
	
	/* Set wakeup interrupt every 125 ms */
	TM_RTC_Interrupts(TM_RTC_Int_125ms);
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonPressed()) {
			
			/* Subseconds are ignored when writing new time */
			
			datatime.hours = 0;
			datatime.minutes = 59;
			datatime.seconds = 55;
			datatime.year = 14;
			datatime.month = 6;
			datatime.date = 30;
			datatime.day = 6;
			
			/* Set new time */
			TM_RTC_SetDateTime(&datatime, TM_RTC_Format_BIN);
		}
	}
}
Exemplo n.º 14
0
int main(void) {
	__IO uint32_t i;
	
	/* CPU load structure */
	TM_CPULOAD_t CPU_LOAD;
	
	/* Init CPU load monitor */
	TM_CPULOAD_Init(&CPU_LOAD);
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init USART2, TX: PA2, RX: PA3, 921600 bauds */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 921600);
	
	while (1) {
		/* Check if CPU LOAD variable is updated */
		if (CPU_LOAD.Updated) {
			/* Print to user */
			printf("W: %u; S: %u; Load: %5.2f\n", CPU_LOAD.WCNT, CPU_LOAD.SCNT, CPU_LOAD.Load);
		}
		
		/* Toggle leds */
		TM_DISCO_LedToggle(LED_ALL);
		
		/* If button pressed, do some useless counting */
		if (TM_DISCO_ButtonPressed()) {
			/* Count something to waste some time before entering to sleep mode */
			i = 0;
			while (i++ < 0x1FFF);
		}
		
		/* Go low power mode, sleep mode until interrupt, measure CPU load */
		TM_CPULOAD_GoToSleepMode(&CPU_LOAD, TM_LOWPOWERMODE_SleepUntilInterrupt);
	}
}
Exemplo n.º 15
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init USART6, TX: PC6, 921600 baud */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 921600);
	
	/* Get system reset source and clear flags after read */
	printf("System reset source: %d\n", (uint8_t)TM_GENERAL_GetResetSource(1));
	
	/* Get system reset source and clear flags after read */
	/* You should see number which corresponds to "None", because we cleared flags in statement above */
	printf("System reset source: %d\n", (uint8_t)TM_GENERAL_GetResetSource(1));
	
	/* Get system core and PCLK1 (Peripheral Clock 1, APB1) clocks */
	printf("System core clock: %u Hz; PCLK1 clock: %u Hz\n", 
		TM_GENERAL_GetClockSpeed(TM_GENERAL_Clock_SYSCLK),
		TM_GENERAL_GetClockSpeed(TM_GENERAL_Clock_PCLK1)
	);
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonOnPressed()) {
			/* Send to USER */
			printf("Software reset will happen in a moment\n");
			/* Wait a little */
			Delayms(500);
			/* Perform system software reset */
			TM_GENERAL_SystemReset();
		}
	}
}
Exemplo n.º 16
0
int main(void) {
    TM_RCC_InitSystem();                                    /* Init system */
    HAL_Init();                                             /* Init HAL layer */
    TM_DISCO_LedInit();                                     /* Init leds */
    TM_DISCO_ButtonInit();                                  /* Init button */
    TM_DELAY_Init();                                        /* Init delay */
    TM_USART_Init(DEBUG_USART, DEBUG_USART_PP, 921600);     /* Init USART for debug purpose */

    /* Print first screen message */
    printf("ESP8266 commands parser; Compiled: %s %s\r\n", __DATE__, __TIME__);

    /* Initialize threads */
    ESP_Update_ThreadId = osThreadCreate(osThread(ESP_Update), NULL);
    ESP_Main_ThreadId = osThreadCreate(osThread(ESP_Main), NULL);

    /* Start kernel */
    osKernelStart();
    
	while (1) {

	}
}
Exemplo n.º 17
0
int main(void) {
	uint8_t c;
	
	//Initialize system
	SystemInit();

	TM_DELAY_Init();

	//Initialize USART1 at 9600 baud, TX: PA9, RX: PA10
	TM_USART_Init(USART1, TM_USART_PinsPack_1, 9600);
	//Put string to terminal
	TM_USART_Puts(USART1, "Hello world\n\r");

	while (1) {
		//Get character from internal buffer
		c = TM_USART_Getc(USART1);
		if (c) {
			//If anything received, put it back to terminal
			TM_USART_Putc(USART1, c);
		}
	}
}
Exemplo n.º 18
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init USART, check USART lib description for pinout */
	TM_USART_Init(USART, TM_USART_PinsPack_1, 921600);
	
	/* Say string without DMA */
	TM_USART_Puts(USART, "Hello via USART without DMA\n");
	
	/* Init TX DMA for USART */
	TM_USART_DMA_Init(USART);
	
	/* Enable interrupts for TX DMA */
	TM_USART_DMA_EnableInterrupts(USART);
	
	/* Send data with DMA */
	TM_USART_DMA_Send(USART, (uint8_t *)USART_Buffer, strlen(USART_Buffer));
	
	/* Wait till DMA works */
	/* You can do other stuff here instead of waiting for DMA to end */
	while (TM_USART_DMA_Transmitting(USART));
	
	while (1) {
		/* If any string arrived over USART */
		/* Expecting "\n" at the end of string from USART terminal or any other source */
		if (TM_USART_Gets(USART, USART_Buffer, sizeof(USART_Buffer))) {
			/* Send it back over DMA */
			TM_USART_DMA_Send(USART, (uint8_t *)USART_Buffer, strlen(USART_Buffer));

			/* Wait till DMA works */
			/* You can do other stuff here instead of waiting for DMA to end */
			while (TM_USART_DMA_Transmitting(USART));
		}
	}
}
Exemplo n.º 19
0
int main(void) {
    char buffer[20];

    /* Initialize system */
    SystemInit();

    /* Initialize delay */
    TM_DELAY_Init();

    /* Initialize USART1, TX: PB6 */
    TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);

    /* Initialize random number generator */
    TM_RNG_Init();

    while (1) {
        /* Get number */
        sprintf(buffer, "Number: %u\n", TM_RNG_Get());
        /* Put to USART */
        TM_USART_Puts(USART1, buffer);
        Delayms(1000);
    }
}
Exemplo n.º 20
0
/* Public */
void TM_GPS_Init(TM_GPS_Data_t* GPS_Data, uint32_t baudrate) {
	/* Initialize USART */
	TM_USART_Init(GPS_USART, GPS_USART_PINSPACK, baudrate);
	/* Set first-time variable */
	TM_GPS_FirstTime = 1;
	/* Clear all flags */
	TM_GPS_INT_ClearFlags();
	
	/* Set flags used */
#ifndef GPS_DISABLE_GPGGA
	TM_GPS_Flags_OK |= GPS_FLAG_LATITUDE;
	TM_GPS_Flags_OK |= GPS_FLAG_NS;
	TM_GPS_Flags_OK |= GPS_FLAG_LONGITUDE;
	TM_GPS_Flags_OK |= GPS_FLAG_EW;
	TM_GPS_Flags_OK |= GPS_FLAG_SATS;
	TM_GPS_Flags_OK |= GPS_FLAG_FIX;
	TM_GPS_Flags_OK |= GPS_FLAG_ALTITUDE;
	TM_GPS_Flags_OK |= GPS_FLAG_TIME;
#endif
#ifndef GPS_DISABLE_GPRMC
	TM_GPS_Flags_OK |= GPS_FLAG_SPEED;
	TM_GPS_Flags_OK |= GPS_FLAG_DATE;
	TM_GPS_Flags_OK |= GPS_FLAG_VALIDITY;
	TM_GPS_Flags_OK |= GPS_FLAG_DIRECTION;
#endif
#ifndef GPS_DISABLE_GPGSA
	TM_GPS_Flags_OK |= GPS_FLAG_HDOP;
	TM_GPS_Flags_OK |= GPS_FLAG_VDOP;
	TM_GPS_Flags_OK |= GPS_FLAG_PDOP;
	TM_GPS_Flags_OK |= GPS_FLAG_FIXMODE;
	TM_GPS_Flags_OK |= GPS_FLAG_SATS1_12;
#endif
#ifndef GPS_DISABLE_GPGSV	
	TM_GPS_Flags_OK |= GPS_FLAG_SATSINVIEW;
#endif
}
Exemplo n.º 21
0
void USART_Config() {
    TM_USART_Init(USART1, TM_USART_PinsPack_1, 115200);
    TM_USART_SetCustomStringEndCharacter(USART1, '\r');
    TM_USART_Init(USART3, TM_USART_PinsPack_1, 115200);
    TM_USART_SetCustomStringEndCharacter(USART3, '\r');
}
Exemplo n.º 22
0
int main(void) {
	TM_NRF24L01_Transmit_Status_t transmissionStatus;
	char str[40];
	
	//Initialize system
	SystemInit();
	
	//Initialize system and Delay functions
	TM_DELAY_Init();
	
	//Initialize onboard leds
	TM_DISCO_LedInit();
	
	//Initialize USART, TX: PB6, RX: PB7
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	//Initialize NRF24L01+ on channel 15 and 32bytes of payload
	//By default 2Mbps data rate and 0dBm output power
	//NRF24L01 goes to RX mode by default
	TM_NRF24L01_Init(15, 32);
	
	//Set 2MBps data rate and -18dBm output power
	TM_NRF24L01_SetRF(TM_NRF24L01_DataRate_2M, TM_NRF24L01_OutputPower_M18dBm);
	
	//Set my address, 5 bytes
	TM_NRF24L01_SetMyAddress(MyAddress);
	//Set TX address, 5 bytes
	TM_NRF24L01_SetTxAddress(TxAddress);
	
	//Reset counter
	TM_DELAY_SetTime(0);
	while (1) {
		//Every 2 seconds
		if (TM_DELAY_Time() > 2000000) {
			//Fill data with something
			sprintf((char *)dataOut, "abcdefghijklmnoszxABCDEFCBDA");
			//Display on USART
			TM_USART_Puts(USART1, "pinging: ");
			//Reset time, start counting microseconds
			TM_DELAY_SetTime(0);
			//Transmit data, goes automatically to TX mode
			TM_NRF24L01_Transmit(dataOut);
			
			TM_DISCO_LedOn(LED_PIN);
			//Wait for data to be sent
			do {
				transmissionStatus = TM_NRF24L01_GetTransmissionStatus();
			} while (transmissionStatus == TM_NRF24L01_Transmit_Status_Sending);
			TM_DISCO_LedOff(LED_PIN);
			
			//Go back to RX mode
			TM_NRF24L01_PowerUpRx();
			
			//Wait received data, wait max 100ms, if time is larger, than data was probably lost
			while (!TM_NRF24L01_DataReady() && TM_DELAY_Time() < 100000);
			
			//Format time
			sprintf(str, "%d us", TM_DELAY_Time());
			//Show ping time
			TM_USART_Puts(USART1, str);
			
			//Get data from NRF2L01+
			TM_NRF24L01_GetData(dataIn);
			
			//Check transmit status
			if (transmissionStatus == TM_NRF24L01_Transmit_Status_Ok) {
				//Transmit went OK
				TM_USART_Puts(USART1, ": OK\n\r");
			} else if (transmissionStatus == TM_NRF24L01_Transmit_Status_Lost) {
				//Message was LOST
				TM_USART_Puts(USART1, ": LOST\n\r");
			} else {
				//This should never happen
				TM_USART_Puts(USART1, ": SENDING\n\r");
			}
		}
	}
}
Exemplo n.º 23
0
int main(void) {
	char buffer[50];
	
	/* Working structure */
	TM_BMP180_t BMP180_Data;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize USART1, 11500baud, TX: PB6 */
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	/* Initialize BMP180 pressure sensor */
	if (TM_BMP180_Init(&BMP180_Data) == TM_BMP180_Result_Ok) {
		/* Init OK */
		TM_USART_Puts(USART1, "BMP180 configured and ready to use\n\n");
	} else {
		/* Device error */
		TM_USART_Puts(USART1, "BMP180 error\n\n");
		while (1);
	}
	
	/* Imagine, we are at 1000 meters above the sea */
	/* And we read pressure of 95000 pascals */
	/* Pressure right on the sea is */
	sprintf(buffer, "Pressure right above the sea: %d pascals\n", TM_BMP180_GetPressureAtSeaLevel(95000, 1000));
	TM_USART_Puts(USART1, buffer);
	sprintf(buffer, "Data were calculated from pressure %d pascals at know altitude %d meters\n\n\n", 95000, 1000);
	TM_USART_Puts(USART1, buffer);

	while (1) {
		/* Start temperature conversion */
		TM_BMP180_StartTemperature(&BMP180_Data);
		
		/* Wait delay in microseconds */
		/* You can do other things here instead of delay */
		Delay(BMP180_Data.Delay);
		
		/* Read temperature first */
		TM_BMP180_ReadTemperature(&BMP180_Data);
		
		/* Start pressure conversion at ultra high resolution */
		TM_BMP180_StartPressure(&BMP180_Data, TM_BMP180_Oversampling_UltraHighResolution);
		
		/* Wait delay in microseconds */
		/* You can do other things here instead of delay */
		Delay(BMP180_Data.Delay);
		
		/* Read pressure value */
		TM_BMP180_ReadPressure(&BMP180_Data);
		
		/* Format data and print to USART */
		sprintf(buffer, "Temp: %2.3f degrees\nPressure: %6d Pascals\nAltitude at current pressure: %3.2f meters\n\n",
			BMP180_Data.Temperature,
			BMP180_Data.Pressure,
			BMP180_Data.Altitude
		);
		/* Send to USART */
		TM_USART_Puts(USART1, buffer);
		
		/* Some delay */
		Delayms(1000);
	}
}
Exemplo n.º 24
0
int main(void) {
	uint8_t i;
	float temp;
	
	/* Initialize system */
	SystemInit();
	
	/* Delay init */
	TM_DELAY_Init();
	
	/* Initialize GPS on 115200 baudrate */
	TM_GPS_Init(&GPS_Data, 115200);
	
	/* Initialize USART2 for debug */
	/* TX = PA2 */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 115200);
	
	/* Version 1.1 added */
	/* Set two test coordinates */
	GPS_Distance.Latitude1 = 48.300215;
	GPS_Distance.Longitude1 = -122.285903;
	GPS_Distance.Latitude2 = 45.907813;
	GPS_Distance.Longitude2 = 56.659407;
	
	/* Calculate distance and bearing between 2 points */
	TM_GPS_DistanceBetween(&GPS_Distance);
	
	/* Convert float number */
	TM_GPS_ConvertFloat(GPS_Distance.Distance, &GPS_Float, 6);
	printf("Distance is: %d.%06d meters\n", GPS_Float.Integer, GPS_Float.Decimal);
	
	TM_GPS_ConvertFloat(GPS_Distance.Bearing, &GPS_Float, 6);
	printf("Bearing is: %d.%06d degrees\n\n", GPS_Float.Integer, GPS_Float.Decimal);
	
	/* Reset counter */
	TM_DELAY_SetTime(0);
	while (1) {
		/* Update GPR data */
		/* Call this as faster as possible */
		result = TM_GPS_Update(&GPS_Data);

		/* If we have any unread data */
		if (result == TM_GPS_Result_NewData) {
			/* We received new packet of useful data from GPS */
			current = TM_GPS_Result_NewData;
			
			/* Is GPS signal valid? */
			if (GPS_Data.Validity) {
				/* If you want to make a GPS tracker, now is the time to save your data on SD card */
				
				/* We have valid GPS signal */
				printf("New received data have valid GPS signal\n");
				printf("---------------------------------------\n");
#ifndef GPS_DISABLE_GPGGA
				/* GPGGA data */
				printf("GPGGA statement:\n");
				
				/* Latitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Latitude, &GPS_Float, 6);
				printf(" - Latitude: %d.%d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Longitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Longitude, &GPS_Float, 6);
				printf(" - Longitude: %d.%d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Satellites in use */
				printf(" - Sats in use: %02d\n", GPS_Data.Satellites);
				
				/* Current time */
				printf(" - UTC Time: %02d.%02d.%02d:%02d\n", GPS_Data.Time.Hours, GPS_Data.Time.Minutes, GPS_Data.Time.Seconds, GPS_Data.Time.Hundredths);
				
				/* Fix: 0 = invalid, 1 = GPS, 2 = DGPS */
				printf(" - Fix: %d\n", GPS_Data.Fix);
				
				/* Altitude */
				/* Convert float to integer and decimal part, with 6 decimal places */
				TM_GPS_ConvertFloat(GPS_Data.Altitude, &GPS_Float, 6);
				printf(" - Altitude: %3d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
#endif
#ifndef GPS_DISABLE_GPRMC
				/* GPRMC data */
				printf("GPRMC statement:\n");
				
				/* Current date */
				printf(" - Date: %02d.%02d.%04d\n", GPS_Data.Date.Date, GPS_Data.Date.Month, GPS_Data.Date.Year + 2000);
				
				/* Current speed in knots */
				TM_GPS_ConvertFloat(GPS_Data.Speed, &GPS_Float, 6);
				printf(" - Speed in knots: %d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Current speed in km/h */
				temp = TM_GPS_ConvertSpeed(GPS_Data.Speed, TM_GPS_Speed_KilometerPerHour);
				TM_GPS_ConvertFloat(temp, &GPS_Float, 6);
				printf(" - Speed in km/h: %d.%06d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				TM_GPS_ConvertFloat(GPS_Data.Direction, &GPS_Float, 3);
				printf(" - Direction: %3d.%03d\n", GPS_Float.Integer, GPS_Float.Decimal);
#endif
#ifndef GPS_DISABLE_GPGSA
				/* GPGSA data */
				printf("GPGSA statement:\n");
				
				/* Horizontal dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.HDOP, &GPS_Float, 2);
				printf(" - HDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Vertical dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.VDOP, &GPS_Float, 2);
				printf(" - VDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Position dilution of precision */ 
				TM_GPS_ConvertFloat(GPS_Data.PDOP, &GPS_Float, 2);
				printf(" - PDOP: %2d.%02d\n", GPS_Float.Integer, GPS_Float.Decimal);
				
				/* Current fix mode in use */ 
				printf(" - Fix mode: %d\n", GPS_Data.FixMode);
				
				/* Display IDs of satellites in use */
				printf(" - ID's of used satellites: ");
				for (i = 0; i < GPS_Data.Satellites; i++) {
					printf("%d,", GPS_Data.SatelliteIDs[i]);
				}
				printf("\n");
				
#endif
#ifndef GPS_DISABLE_GPGSV
				/* GPGSV data */
				printf("GPGSV statement:\n");
				
				/* Satellites in view */
				printf(" - Satellites in view: %d\n", GPS_Data.SatellitesInView);
				
				/* Print satellites description */
				for (i = 0; i < GPS_Data.SatellitesInView; i++) {
					printf(" - S: %02d, A: %03d, E: %02d, SNR: %02d\n", 
						GPS_Data.SatDesc[i].ID, 
						GPS_Data.SatDesc[i].Azimuth, 
						GPS_Data.SatDesc[i].Elevation, 
						GPS_Data.SatDesc[i].SNR
					);
				}
#endif
				printf("---------------------------------------\n");
			} else {
				/* GPS signal is not valid */
				printf("New received data haven't valid GPS signal!\n");
			}
		} else if (result == TM_GPS_Result_FirstDataWaiting && current != TM_GPS_Result_FirstDataWaiting) {
			current = TM_GPS_Result_FirstDataWaiting;
			printf("Waiting first data from GPS!\n");
		} else if (result == TM_GPS_Result_OldData && current != TM_GPS_Result_OldData) {
			current = TM_GPS_Result_OldData;
			/* We already read data, nothing new was received from GPS */
		}
	}
}
Exemplo n.º 25
0
int main(void) {

    int accelData[3];
    int analogData[BUFFER];
    int i=0;
    for(i=0;i<BUFFER;i++){ analogData[i]=0;	}
    int a = 0;
    int analogIn = 0;
    int analogMin, analogMax;

    /* Initialize system */
    SystemInit();

    /* Initialize delay */
    //TM_DELAY_Init();

    /* Initialize PG13 (GREEN LED) and PG14 (RED LED) */
    TM_GPIO_Init(GPIOG, GPIO_PIN_13 | GPIO_PIN_14, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast);
    TM_GPIO_SetPinValue(GPIOG, GPIO_PIN_14, 1); // Red: ON

#ifdef ENABLE_USART
    /* Initialize USART1 at 115200 baud, TX: PA10, RX: PA9 */
    TM_USART_Init(USART1, TM_USART_PinsPack_1, 115200);
#endif

#ifdef ENABLE_VCP
    /* Initialize USB Virtual Comm Port */

    TM_USB_VCP_Result status = TM_USB_VCP_NOT_CONNECTED;
    while (TM_USB_VCP_GetStatus() != TM_USB_VCP_CONNECTED) {
    	TM_USB_VCP_Init();
    	TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14);
    	Delay(500000);
    }
    SendString("USB VCP initialized and connected\n");
    TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14 | GPIO_PIN_13); // Red: OFF, Gr: ON

#endif

#ifdef ENABLE_MMA

    /* Initialize MMA845X */
    uint8_t mma_status = MMA845X_Initialize(MMA_RANGE_4G);
    if (mma_status == MMA_OK) {
    	SendString("MMA initialized\n");
    } else {
    	SendString("MMA initialization failed, error code: ");
    	// Add 48 to the byte value to have character representation, (48 = '0')
    	SendChar('0'+mma_status);
    	SendChar('\n');
    }

#endif

    /* Initialize Display */
	TM_ILI9341_Init();
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_1);
	TM_ILI9341_SetLayer1();
	TM_ILI9341_Fill(ILI9341_COLOR_BLACK); /* Fill data on layer 1 */

	/* Initialize ADC1 */
	TM_ADC_Init(CURRENT_ADC, CURRENT_CH);

	/* Initialize PE2 and PE3 for digital output (Motor direction) */
    TM_GPIO_Init(GPIOE, GPIO_PIN_2 | GPIO_PIN_3, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast);
    // Set them to HIGH/LOW
    TM_GPIO_SetPinHigh(GPIOE, GPIO_PIN_3);
    TM_GPIO_SetPinLow(GPIOE, GPIO_PIN_2);

#ifdef ENABLE_PWM
    /* Set up PE5 (in front of PE4) for PWM (TIM9 CH1 PP2) (Motor speed control) */
    TM_PWM_TIM_t TIM9_Data;
    // Set PWM to 1kHz frequency on timer TIM4, 1 kHz = 1ms = 1000us
	TM_PWM_InitTimer(TIM9, &TIM9_Data, 1000);
	// Initialize PWM on TIM9, Channel 1 and PinsPack 2 = PE5
	TM_PWM_InitChannel(&TIM9_Data, TM_PWM_Channel_1, TM_PWM_PinsPack_2);
	// Set channel 1 value, 50% duty cycle
	TM_PWM_SetChannelPercent(&TIM9_Data, TM_PWM_Channel_1, 50);
#endif

	/* Initialize DAC channel 2, pin PA5 (Shaker control) */
	//TM_DAC_Init(TM_DAC2);
	/* Set 12bit analog value of 2047/4096 * 3.3V */
	//TM_DAC_SetValue(TM_DAC2, 4096);

#ifdef ENABLE_DAC
	// DAC PIN PA5
	/* Initialize DAC1, use TIM4 for signal generation */
	TM_DAC_SIGNAL_Init(TM_DAC2, TIM4);
	/* Output predefined triangle signal with frequency of 5kHz */
	TM_DAC_SIGNAL_SetSignal(TM_DAC2, TM_DAC_SIGNAL_Signal_Sinus, 50);
#endif

	/* MAIN LOOP */
    while (1) {

    	// Read acceleration data
#ifdef ENABLE_MMA
		MMA845X_ReadAcceleration(accelData);
#endif

		// Read analog input
		analogData[a] = TM_ADC_Read(CURRENT_ADC, CURRENT_CH);
		a++;
		if(a==BUFFER) {a=0;}

		// Analog average
		analogIn=0;
		analogMax=0;
		analogMin=4096;
		for(i=0;i<BUFFER;i++){
			if(analogData[i] > analogMax) { analogMax = analogData[i]; }
			if(analogData[i] < analogMin) { analogMin = analogData[i]; }
			analogIn+=analogData[i];
		}
		analogIn/=BUFFER;

		// Print graphs
		printGraphsLCD(accelData, analogData[a], analogIn, analogMin, analogMax);

		// Toggle Green led
		TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_13);

    }
}
Exemplo n.º 26
0
int main(void) {
	uint8_t i;
	
	/* Initialize system */
	SystemInit();
	
	/* Delay init */
	TM_DELAY_Init();
	
	/* Initialize GPS on 115200 baudrate */
	TM_GPS_Init(&GPS_Data, 115200);
	
	/* Initialize USART2 for debug */
	/* TX = PA2 */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 115200);
	
	/* Register custom GPGxx statements */
	
	/* $GPRMC statement, term number 7 = Speed over ground in knots */
	GPRMC = TM_GPS_AddCustom(&GPS_Data, "$GPRMC", 7);
	/* $GPGLL statement, term number 1 = Current latitude */
	GPGLL = TM_GPS_AddCustom(&GPS_Data, "$GPGLL", 1);
	/* $GPGSA statement, term number 1 = M = Manual, forced to operate in 2D or 3D A=Automatic, 3D/2D */
	GPGSA = TM_GPS_AddCustom(&GPS_Data, "$GPGSA", 1);
	/* Add here more custom tags you want */
	/* ... */
	
	/* Reset counter */
	TM_DELAY_SetTime(0);
	while (1) {
		/* Update GPR data */
		/* Call this as faster as possible */
		result = TM_GPS_Update(&GPS_Data);

		/* If we have any unread data */
		if (result == TM_GPS_Result_NewData) {
			/* We received new packet of useful data from GPS */
			current = TM_GPS_Result_NewData;
			
			/* Is GPS signal valid? */
			if (GPS_Data.Validity) {
				/* If you want to make a GPS tracker, now is the time to save your data on SD card */
				
				/* We have valid GPS signal */
				printf("New received data have valid GPS signal\n");
				printf("---------------------------------------\n");

				/* We have all data from GPS_Data structure valid, you can do here what you want */
				/* We will in this example show only custom data to user */
			
				/* Print custom statements */
				printf("Custom statements defined by user:\n");
				
				/* Go through all custom statements */
				for (i = 0; i < GPS_Data.CustomStatementsCount; i++) {
					printf(" - Statement: %s; TermNumber: %d; Value: %s\n",
						GPS_Data.CustomStatements[i]->Statement,  /*!< Statement value */
						GPS_Data.CustomStatements[i]->TermNumber, /*!< Term number */
						GPS_Data.CustomStatements[i]->Value       /*!< Value from GPS receiver */
					);
				}
				
				/* You can do it this way too for all your custom statements separatelly */
				printf(" - Statement2: %s; TermNumber: %d; Value: %s\n",
					GPRMC->Statement, GPRMC->TermNumber, GPRMC->Value
				);
				
				printf("---------------------------------------\n");
			} else {
				/* GPS signal is not valid */
				printf("New received data haven't valid GPS signal!\n");
			}
		} else if (result == TM_GPS_Result_FirstDataWaiting && current != TM_GPS_Result_FirstDataWaiting) {
			current = TM_GPS_Result_FirstDataWaiting;
			printf("Waiting first data from GPS!\n");
		} else if (result == TM_GPS_Result_OldData && current != TM_GPS_Result_OldData) {
			current = TM_GPS_Result_OldData;
			/* We already read data, nothing new was received from GPS */
		}
	}
}
Exemplo n.º 27
0
int main(void) {
	TM_KEYPAD_Button_t Keypad_Button;
	char buff[20];
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize leds */
	TM_DISCO_LedInit();
	
	/* Initialize USART 1, TX: PB6 */
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	/* Initialize matrix keyboard */
	TM_KEYPAD_Init(TM_KEYPAD_Type_Large);

	while (1) {
		/* Read keyboard data */
		Keypad_Button = TM_KEYPAD_Read();
		
		/* Keypad was pressed */
		if (Keypad_Button != TM_KEYPAD_Button_NOPRESSED) {/* Keypad is pressed */
			switch (Keypad_Button) {
				case TM_KEYPAD_Button_0:		/* Button 0 pressed */
					TM_DISCO_LedToggle(LED_GREEN | LED_RED | LED_BLUE | LED_ORANGE);
					break;
				case TM_KEYPAD_Button_1:		/* Button 1 pressed */
					TM_DISCO_LedOn(LED_GREEN);
					break;
				case TM_KEYPAD_Button_2:		/* Button 2 pressed */
					TM_DISCO_LedOff(LED_GREEN);
					break;
				case TM_KEYPAD_Button_3:		/* Button 3 pressed */
					TM_DISCO_LedOn(LED_RED);
					break;
				case TM_KEYPAD_Button_4:		/* Button 4 pressed */
					TM_DISCO_LedOff(LED_RED);
					break;
				case TM_KEYPAD_Button_5:		/* Button 5 pressed */
					TM_DISCO_LedOn(LED_ORANGE);
					break;
				case TM_KEYPAD_Button_6:		/* Button 6 pressed */
					TM_DISCO_LedOff(LED_ORANGE);
					break;
				case TM_KEYPAD_Button_7:		/* Button 7 pressed */
					TM_DISCO_LedOn(LED_BLUE);
					break;
				case TM_KEYPAD_Button_8:		/* Button 8 pressed */
					TM_DISCO_LedOff(LED_BLUE);
					break;
				case TM_KEYPAD_Button_9:		/* Button 9 pressed */
					/* Do your stuff here */
					break;
				case TM_KEYPAD_Button_STAR:		/* Button STAR pressed */
					TM_DISCO_LedOn(LED_GREEN | LED_RED | LED_BLUE | LED_ORANGE);
					break;
				case TM_KEYPAD_Button_HASH:		/* Button HASH pressed */
					TM_DISCO_LedOff(LED_GREEN | LED_RED | LED_BLUE | LED_ORANGE);
					break;
				case TM_KEYPAD_Button_A:		/* Button A pressed, only on large keyboard */
					/* Do your stuff here */
					break;
				case TM_KEYPAD_Button_B:		/* Button B pressed, only on large keyboard */
					/* Do your stuff here */
					break;
				case TM_KEYPAD_Button_C:		/* Button C pressed, only on large keyboard */
					/* Do your stuff here */
					break;
				case TM_KEYPAD_Button_D:		/* Button D pressed, only on large keyboard */
					/* Do your stuff here */
					break;
				default:
					break;
			}
			
			sprintf(buff, "Pressed: %u us\n", (uint8_t)Keypad_Button);
			TM_USART_Puts(USART1, buff);
		}
	}
}
Exemplo n.º 28
0
int main(void) {
		char str[100];

//		char buffer1[100];
		
//	/* Free and total space */
//	uint32_t total, free;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delays */
	TM_DELAY_Init();
	/* Enable watchdog, 4 seconds before timeout */
	if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_8s)) {
		/* Report to user */
		//printf("Reset occured because of Watchdog\n");
	}	
	/* Reset counter to 0 */
	TM_DELAY_SetTime(0);
	/* init DTMF*/
	TM_GPIO_Init(DTMF_BIT0_PORT, DTMF_BIT0_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	TM_GPIO_Init(DTMF_BIT1_PORT, DTMF_BIT1_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	TM_GPIO_Init(DTMF_BIT2_PORT, DTMF_BIT2_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	TM_GPIO_Init(DTMF_BIT3_PORT, DTMF_BIT3_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	/* DTMF*/
		if (TM_EXTI_Attach(DFMF_BIT4_PORT, DTMF_BIT4_PIN, TM_EXTI_Trigger_Rising) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat DFMF_BIT4\n");
	}
	
	/*init interrup INPUT*/
		if (TM_EXTI_Attach(W1_D0_PORT, W1_D0_PIN, TM_EXTI_Trigger_Rising) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat W1_D0\n");
	}
		if (TM_EXTI_Attach(W1_D1_PORT, W1_D1_PIN, TM_EXTI_Trigger_Rising) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat W1_D1\n");
	}
		if (TM_EXTI_Attach(W2_D1_PORT, W2_D1_PIN, TM_EXTI_Trigger_Falling) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat W2_D1\n");
	}
		if (TM_EXTI_Attach(W2_D0_PORT, W2_D0_PIN, TM_EXTI_Trigger_Falling) == TM_EXTI_Result_Ok) {
		TM_USART_Puts(USART3, "khoi tao ngat W2_D0\n"); // W2D0
	}
	/*init SWADD*/
	TM_GPIO_Init(ADD_BIT0_PORT, ADD_BIT0_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);	
	TM_GPIO_Init(ADD_BIT1_PORT, ADD_BIT1_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT2_PORT, ADD_BIT2_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT3_PORT, ADD_BIT3_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT4_PORT, ADD_BIT4_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT5_PORT, ADD_BIT5_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT6_PORT, ADD_BIT6_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	TM_GPIO_Init(ADD_BIT7_PORT, ADD_BIT7_PIN, TM_GPIO_Mode_IN, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium);
	/* init OUTPUT*/
	TM_GPIO_Init(RELAY_DK1_PORT, RELAY_DK1_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
	TM_GPIO_Init(RELAY_DK2_PORT, RELAY_DK2_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
	TM_GPIO_Init(RELAY_DK3_PORT, RELAY_DK3_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
	TM_GPIO_Init(RELAY_DK4_PORT, RELAY_DK4_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
/* Initialize USART6 at 115200 baud, TX: PC6, RX: PC7 , COM 1 - RFID1 gan cong tac nguon*/ 
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);
/* Initialize USART3 at 115200 baud, TX: PD8, RX: PD9 ,	COM 2 -RFID 2 gan ethernet*/
	TM_USART_Init(USART3, TM_USART_PinsPack_3, 115200);
/* Initialize USART1 at 115200 baud, TX: PA9, RX: PA10, CONG 485 */
	TM_USART_Init(USART1, TM_USART_PinsPack_1, 9600);
	/* Initialize USART2, with custom pins */					// COM 3 extension PC
	//TM_USART_Init(USART2, TM_USART_PinsPack_Custom,9600);
	TM_USART_Init(USART2, TM_USART_PinsPack_2,9600);
	
/* int DIR 485 set = send , reset = recvice*/ 
	TM_GPIO_Init(CCU_DIR_PORT, CCU_DIR_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_UP, TM_GPIO_Speed_High);
	TM_GPIO_SetPinHigh(CCU_DIR_PORT,CCU_DIR_PIN);
/* Init 2 custom timers */
/* Timer1 has reload value each 500ms, enabled auto reload feature and timer is enabled */
	CustomTimer1 = TM_DELAY_TimerCreate(500, 1, 1, CustomTIMER1_Task, NULL);
	/* Timer1 has reload value each 1000ms, enabled auto reload feature and timer is enabled */
	CustomTimer2 = TM_DELAY_TimerCreate(100, 1, 1, CustomTIMER2_Task, NULL);
/* Init LCD*/
		TM_GPIO_Init(HD44780_RW_PORT, HD44780_RW_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High);
		TM_GPIO_SetPinLow(HD44780_RW_PORT,HD44780_RW_PIN);

		read_sw_add();
		timeout = value_dip;
		memset(str,'\0',0);
    //Initialize LCD 20 cols x 4 rows
    TM_HD44780_Init(16, 4);
    //Save custom character on location 0 in LCD
    TM_HD44780_CreateChar(0, &customChar[0]);    
    //Put string to LCD
    TM_HD44780_Puts(0, 0, "STM32F407VET\n\rCreartbyR&D-TIS"); /* 0 dong 1, 1 dong 2*/
    TM_HD44780_Puts(0, 2, "Welcome");
		Delayms(1000);
		TM_HD44780_Clear();
		sprintf(str,"Timer out %d", timeout);
		TM_HD44780_Puts(0, 0,str);
		Delayms(1000);
		TM_HD44780_Clear();
		TM_HD44780_Puts(0, 0,"----TIS8 PRO----");
		//TM_USART_Puts(USART3, "Welcome2");

	/*creat by duc*/
		TM_WATCHDOG_Reset();

//		TM_USART_BufferEmpty(USART3);
//		TM_USART_BufferEmpty(USART6);
		flag_RFID2=0;	
		flag_RFID1=0;
	/*end by duc*/
	while (1) {
/*process 485*/
	if(flag_485){
	flag_485=0;
	if(LEDStatus==0) TM_USART_Puts(USART1, "/LED000>\r\n");
	if(LEDStatus==1) TM_USART_Puts(USART1, "/LED001>\r\n");
	if(LEDStatus==2) TM_USART_Puts(USART1, "/LED002>\r\n");
	}	

/* xu li W1D0 - dk1*/
	if(flag_W1D0){
		turn_on_dk1();
		//flag_W1D0=0;
	}
/* xu li W1D1 - dk2*/
	if(flag_W1D1){
		turn_on_dk2();
		//flag_W1D1=0;
	}
	//TM_WATCHDOG_Reset();
//		/*end*/


if(Process!=1)
		TM_HD44780_Puts(0, 2,"Wait for Card"); /* 0 dong 1, 1 dong 2*/
if(flag_RFID1==1)
		{	
		
		Process=1;
		IDCAR1[0]=BufferCom1[4];
		IDCAR1[1]=BufferCom1[5];
		IDCAR1[2]=BufferCom1[6];
		IDCAR1[3]=BufferCom1[7];
		IDCAR1[4]=BufferCom1[8];
		IDCAR1[5]=BufferCom1[9];
		IDCAR1[6]=BufferCom1[10];
		
		if(BufferCom1[1]==0x08)	
			{
			sprintf(UID1,"%02x %02x %02x %02x,1",IDCAR1[0],IDCAR1[1],IDCAR1[2],IDCAR1[3]);
			}
		if(BufferCom1[1]==0x0B) 
			{
			sprintf(UID1,"%02x %02x %02x %02x %02x %02x %02x,1",IDCAR1[0],IDCAR1[1],IDCAR1[2],IDCAR1[3],IDCAR1[4],IDCAR1[5],IDCAR1[6]);
			}
		TM_HD44780_Puts(0, 2,"Waiting PC..."); /* 0 dong 1, 1 dong 2*/
				if(check_vip(UID1)){
			flag_PC=1;
			flag_R11=1;
			timerdk1 =0;
			Process=0;
		}
		else{
		if(Process)TM_USART_Puts(USART2,UID1);
		}
		WaitPC(200);
		flag_RFID1=0;
		if(flag_PC)
		{
			TM_HD44780_Puts(0, 2,"Door opened.."); /* 0 dong 1, 1 dong 2*/
			flag_PC=0;
			ProcessAction();
		}
		else Process=0;
		flag_RFID1=0;
	}
if(flag_RFID2==1)
		{	
		
		Process=1;
		IDCAR2[0]=BufferCom2[4];
		IDCAR2[1]=BufferCom2[5];
		IDCAR2[2]=BufferCom2[6];
		IDCAR2[3]=BufferCom2[7];
		IDCAR2[4]=BufferCom2[8];
		IDCAR2[5]=BufferCom2[9];
		IDCAR2[6]=BufferCom2[10];
		
		if(BufferCom2[1]==0x08)	
			{
			sprintf(UID2,"%02x %02x %02x %02x ,2",IDCAR2[0],IDCAR2[1],IDCAR2[2],IDCAR2[3]);
			}
		if(BufferCom2[1]==0x0B) 
			{
			sprintf(UID2,"%02x %02x %02x %02x %02x %02x %02x ,2",IDCAR2[0],IDCAR2[1],IDCAR2[2],IDCAR2[3],IDCAR2[4],IDCAR2[5],IDCAR2[6]);
			}
		TM_HD44780_Puts(0, 2,"Waiting PC..."); /* 0 dong 1, 1 dong 2*/
			if(check_vip(UID2)){
			flag_PC=1;
			flag_R31=1;
			timerdk2 =0;
			Process=0;
		}
		else{
		if(Process)TM_USART_Puts(USART2,UID2);}
		WaitPC(200);
		flag_RFID2=0;
		if(flag_PC)
		{
			TM_HD44780_Puts(0, 2,"Door opened.."); /* 0 dong 1, 1 dong 2*/
			flag_PC=0;
			ProcessAction();
		}
		else Process=0;
		flag_RFID2=0;
	}
		
/**/
timer_dk1 = timerdk1/2;	
if (timer_dk1 >= timeout){
			turn_off_dk1();
			flag_R11 =0;
			flag_W1D0=0;
			timerdk1=0;
			timer_dk1=0;
			flag_RFID1=0;
			flag_RFID2=0;
			Process=0;
//			if(LEDStatus==0) TM_USART_Puts(USART3, "/LED000>\r\n");
		}
timer_dk2 = timerdk2/2;
if (timer_dk2 >= timeout){
			turn_off_dk2();
			//flag_R21 =0;
			flag_R31 =0;
			flag_W1D1=0;
			timerdk2=0;
			timer_dk2=0;
			//flag_RFID1=0;
			Process=0;
//			if(LEDStatus==0) TM_USART_Puts(USART3, "/LED000>\r\n");
		}
timer_dk3 = timerdk3;
if (timer_dk3 >= 1){
			turn_off_dk3();
			flag_R12 =0;
			timerdk3=0;
			timer_dk3=0;
		}
timer_dk4 = timerdk4;
if (timer_dk4 >= 1){
			turn_off_dk4();
			flag_R22 =0;
			timer_dk4=0;
			timerdk4=0;
		}


		TM_WATCHDOG_Reset();
}
}
Exemplo n.º 29
0
int main(void) {
    /* Initialize system */
    SystemInit();

    /* Init USART6, TX: PC6 for debug */
    TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);

    /* Enable watchdog, 4 seconds before timeout */
    if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_4s)) {
        /* Report to user */
        printf("Reset occured because of Watchdog\n");
    }

    /* Initialize delay */
    TM_DELAY_Init();

    /* Initialize leds on board */
    TM_DISCO_LedInit();

    /* Initialize button */
    TM_DISCO_ButtonInit();

    /* Display to user */
    printf("Program starting..\n");

    /* Initialize ethernet peripheral */
    /* All parameters NULL, default options for MAC, static IP, gateway and netmask will be used */
    /* They are defined in tm_stm32f4_ethernet.h file */
    if (TM_ETHERNET_Init(NULL, NULL, NULL, NULL) == TM_ETHERNET_Result_Ok) {
        /* Successfully initialized */
        TM_DISCO_LedOn(LED_GREEN);
    } else {
        /* Unsuccessfull communication */
        TM_DISCO_LedOn(LED_RED);
    }

    /* Reset watchdog */
    TM_WATCHDOG_Reset();

    while (1) {
        /* Update ethernet, call this as fast as possible */
        TM_ETHERNET_Update();

        /* If DNS is not working and we don't have IP yet */
        if (MyDNS.Working == 0 && MyDNS.HaveIP == 0) {
            /* Try to start DNS */
            /* It will return error in case Ethernet is not ready yet so you have to try more than one time */
            if (TM_ETHERNETDNS_GetHostByName("stm32f4-discovery.com") == TM_ETHERNET_Result_Ok) {
                /* We started with working */
                MyDNS.Working = 1;
            }
        }

        /* On button pressed, make a new connection and if we have IP known */
        if (TM_DISCO_ButtonOnPressed() && MyDNS.HaveIP) {
            /* Try to make a new connection, port 80 */
            if (TM_ETHERNETCLIENT_Connect("stm32f4-discovery.com", MyDNS.ip[0], MyDNS.ip[1], MyDNS.ip[2], MyDNS.ip[3], 80, &requests_count) != TM_ETHERNET_Result_Ok) {
                /* Print to user */
                printf("Can not make a new connection!\n");
            }
        }

        /* Reset watchdog */
        TM_WATCHDOG_Reset();
    }
}
Exemplo n.º 30
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init debug USART */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 921600);
	
	/* Display message */
	printf("ESP8266 AT commands parser\r\n");
	
	/* Init ESP module */
	while (ESP8266_Init(&ESP8266, 115200) != ESP_OK) {
		printf("Problems with initializing module!\r\n");
	}
	
	/* Set mode to STA+AP */
	while (ESP8266_SetMode(&ESP8266, ESP8266_Mode_STA_AP) != ESP_OK);
	
	/* Enable server on port 80 */
	while (ESP8266_ServerEnable(&ESP8266, 80) != ESP_OK);
	
	/* Module is connected OK */
	printf("Initialization finished!\r\n");
	
	/* Disconnect from wifi if connected */
	ESP8266_WifiDisconnect(&ESP8266);
	
#if ESP8266_USE_APSEARCH
	/* Get a list of all stations */
	ESP8266_ListWifiStations(&ESP8266);
#endif
	
	/* Wait till finishes */
	ESP8266_WaitReady(&ESP8266);
	
	/* Connect to wifi and save settings */
	ESP8266_WifiConnect(&ESP8266, "YOUR SSID", "SSID PASSWORD");
	
	/* Wait till finish */
	ESP8266_WaitReady(&ESP8266);
	
	/* Get connected devices */
	ESP8266_WifiGetConnected(&ESP8266);
	
	while (1) {
		/* Update ESP module */
		ESP8266_Update(&ESP8266);
		
		/* Check for button */
		if (TM_DISCO_ButtonOnPressed()) {
			/* Starting with connection to web */
			while (ESP8266_StartClientConnection(&ESP8266, "stm32f4_discovery", "stm32f4-discovery.com", 80, NULL));
		}
	}
}