#include "stm32l4xx.h"
#include "systick.h"
#include "sysinit.h"
#include "uart.h"
#include "NBiot.h"
#include "I2C.h"
#include "LIS331DLH.h"
#include "sht31.h"


	int main()
	{
		sys_init();					//initialisation of MCU clocks and GPIO for button and LED
		SysTick_init();			//systick for delay_ms function 
		DBGUART_init();			//UART for debuging
		NBUART_init();			//UART communication with NB-IoT modul
		I2C_init();						//I2C initialisation
		while( NBiot_init() != 0);//initialisation of NB-IoT module
		LIS331DLH_Init();			//initialisation of accelerometer
		SHT31_init();					//initialisation of humudity and temperature sensor
		GPIOB->BSRR	=	0x01<<5|0x01U<<6; //both led OFF
		while(1)
		{
			sleep_mode();							//MCU sleep
			GPIOB->BSRR	=	0x01<<21;		//RED LED ON
			delay_ms(2);
			while(send_data() != 0); //function for measuring and sending data
			GPIOB->BSRR	=	0x01<<5|0x01U<<22; //GREEN LED ON RED LED OFF
			delay_ms(500);
			GPIOB->BSRR	=	0x01<<5|0x01U<<6; //both led OFF
		}
	}
