示例#1
0
void initALL()
{
	int flag;
				/*initialize the clocks and basic peripherals*/
   RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);		//set the SYSCLOCK
   RCC_HCLKConfig(RCC_SYSCLK_Div1);				//set the SYSCLOCK
   initUSART(USART1); 							//Initialize USART1
   //initUSART(USART3); 							//Initialize USART3
   ADC_Initialize();							//Initialize ADCs
   I2C_LowLevel_Init(I2C1, 100000, 0);			//Initialize I2C1 bus @ 100Khz speed
   I2C_LowLevel_Init(I2C2, 100000, 0);			//Initialize I2C1 bus @ 100Khz speed
   initLED();	         						//Initialize LEDs D3 D4
   initGPIO();									//initialize PB2 and PB12 used as external GPIO
   //InitTimer();  									//Initialize Timer

   	   	 /* Initialize and configure RF related functions */
   initRFconfpin();	// Init the GPIO PB15 used as CONFIG PIN with the RADIOCRAFT module


   //Configure the RF BOARD to standard value (configfile.c): NETID 2.2.2.2 Channel 2
   if (readintvalue(FLAG_EEPROM)!=0xf0f0f0f0){ //flag eeprom = f0f0f0f0 only when already initialized
   	   flag= ConfigureRF();
	   close_RFconfig();
	   if (flag==ERROR)
	   	   printf("Configuration Failed");
	   else
		   printf("Configuration RF ok");
   }
   else
	   close_RFconfig();

   	  /* Initialize EEPROM VALUES*/
   if (readintvalue(FLAG_EEPROM)!=0xf0f0f0f0){   //flag eeprom = f0f0f0f0 only when already initialized
	   init_eeprom(); //Initialize eeprom
	   Receivedpackage.bytes[0]='$';
	   Receivedpackage.bytes[1]='V';
	   Receivedpackage.bytes[2]='x';
	   Receivedpackage.bytes[3]='x';
   	}

	   	   /*Initialize Sensors*/

   init_acceler();			//initialize accelerometer

 	  	  /* Initialize interrupts sources*/
EnRtcInter();								//Initialize RTC Interrupt Source
EnUsartInter();								//Enable the USART Interrupts
//EnPVDInter();      						//Enable the power PVD
//EnExtInter();								//Initialize External Interrupt Source
//EnTimInterr();								//Initialize Timer Interrupt Source

}
示例#2
0
int main(void)
{
	USART2_Init(9600);

	NVIC_Configuration();
	I2C_LowLevel_Init(I2C1);

	// Tick every 1 ms
	if (SysTick_Config(SystemCoreClock / 1000))  while (1);

	printf("Ready\n\r");
	if (bmp180_check_presence()) {
		printf("Sensor is present\n\r");
	} else {
		printf("Sensor is NOT present\n\r");
		while(1){}
	}

	CalibrationData data;
	data.oss = 3;
	bmp180_get_calibration_data(&data);
	bmp180_get_uncompensated_temperature(&data);
	bmp180_get_uncompensated_pressure(&data);
	bmp180_calculate_true_temperature(&data);
	bmp180_calculate_true_pressure(&data);
	bmp180_get_absolute_altitude(&data);

    while(1)
    {

    }
}
示例#3
0
/*******************************************************************************
* Function Name  : CODEC_Config
* Description    : Configure the Codec in Headphone mode.
* Input          :  - OutputDevice: OutputDeviceHEADPHONE or OutputDeviceSPEAKER
*                :  - I2S_Standard: I2S communication standard could be I2S_Standard_Phillips
*                :       I2S_Standard_MSB or I2S_Standard_LSB.
*                :  - I2S_MCLKOutput: could be I2S_MCLKOutput_
*                :  - Volume:
* Output         : None
* Return         : 0-> correct communication, else wrong communication
*******************************************************************************/
uint32_t CODEC_Config(uint16_t I2S_Standard, uint16_t I2S_MCLKOutput, uint8_t Volume)
{
	/* blah blah blah */
	I2C_LowLevel_Init(I2C1);
	SI47XX_Powerup();
	return 0;
}
示例#4
0
void i2c_init(i2c_dev *dev, uint16_t address, uint32_t speed)
{
    I2C_InitTypeDef I2C_InitStructure;

    I2C_LowLevel_Init(dev);

    /* I2C configuration */
    I2C_StructInit(&I2C_InitStructure);
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStructure.I2C_OwnAddress1 = address;
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_InitStructure.I2C_ClockSpeed = speed;

    I2C_ITConfig(dev->I2Cx, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR, DISABLE);

    /* I2C Peripheral Enable */
    I2C_Cmd(dev->I2Cx, ENABLE);
    /* Apply I2C configuration after enabling it */
    I2C_Init(dev->I2Cx, &I2C_InitStructure);

//	/* Enable the sEE_I2C peripheral DMA requests */
//	I2C_DMACmd(dev->I2Cx, ENABLE);
}
示例#5
0
bool GsmModem::Init()
{
	if(!m_bHasInit) {
		I2C_LowLevel_Init();
		m_bHasInit = true;
	}
	return true;
}
示例#6
0
文件: balancing.c 项目: GMHSA/Test
//----------------------------------------------------------------------------------------------------------------------------------------
// Hauptprogramm
//----------------------------------------------------------------------------------------------------------------------------------------
int main (void)
{ 	
	// I2C initialisieren
	I2C_LowLevel_Init(I2C1, I2C_Clockspeed , I2C_OwnAddress);		// I2C initialisieren -> Kanal 1, clockspeed, Materadresse
	
	// Systick timer initialisieren
  InitSysTick();																							// SysTick timer initialisieren (Ladewert, Clockspeed)
		
	// Timer2 initialisieren
	InitTIM2_PWM();																							// Timer 2 initialisieren -> notwendig um PWM Signal auszugeben
	
	// Aktiviere Port C für Motor Polarität
	RCC->APB2ENR |= (1UL << 4);     														// Enable GPIOC
	GPIOC->CRL		=  0x33333333;    														// PortC 0..7 als Output -> Output Mode, max speed 50MHz ; General purpose output Open-drain
	
	// MPU-6050 initialisieren
	Init_MPU6050();
	
	// Beschleunigungswerte und Drehraten vom MPU-6050 lesen
	i2cData[0] = 0x3B;
	I2C_Write(I2C1, i2cData, 1, I2C_MPUAddress);
	I2C_Read(I2C1, i2cDataRead, 14, I2C_MPUAddress);
	
	// Daten ordnen und abspeichern
	accY = ((i2cDataRead[2] << 8) | i2cDataRead[3]);
	accZ = ((i2cDataRead[4] << 8) | i2cDataRead[5]);
	gyroX = ((i2cDataRead[8] << 8) | i2cData[9]);
	
	//Kalibrierung von accY, accZ und gyroX - Werte wurden in einem Versuch ermittelt
	accY = accY - 150;
  accZ = accZ - 451.63;
  gyroX = gyroX + 273.25;
	
	//Winkel initialisieren
	accYangle = (atan2(accY, accZ))*RAD_TO_DEG; 				// Winkel aus Beschleunigungswerten berechnen
	setAngle(accYangle);																// Kalman-(Start)Winkel setzen
	gyroAngle = accYangle;															// Drehratenwinkel initialisieren
	compAngle = accYangle;															// Komplementärwinkel initialisieren
	
	SysTick->CTRL |= 0x01; 															// Systick timer einschalten - sonst würde dieser bereits vor der Inittialisierung auslösen
	
	
	//while-Schleife um auf den Interrupt des Systick timers zu warten
	while(1) {
		
	}//while

}//int main
示例#7
0
void hd44780_init(TIM_TypeDef *t) {
    timer = t;
    // Setup clock
    setup_delay_timer(timer);

    hd44780_data[0] = 0x00 | backlight;
    hd44780_data[1] = 0x00 | backlight;

    // Init I2C
    I2C_LowLevel_Init(I2C1);

    // Reset all
    I2C_Master_BufferWrite(I2C1, hd44780_data, 1, Polling, hd44780_address << 1);

    hd44780_cmd(0x03);
    delay_us(timer, 5000);
    hd44780_cmd(0x03);
    delay_us(timer, 100);
    hd44780_cmd(HD44780_MOVE_TO_HOME);
    delay_us(timer, 200);

    hd44780_cmd(0x28); // 4 bit mode
    hd44780_cmd(0x06); // set direction of cursor to right
    hd44780_cmd(HD44780_DISPLAY_ERASE); // clear display, go to 0x0
//    hd44780_cmd(0x0E); // turn on display, set solid cursor
    hd44780_cmd(HD44780_DISPLAY_SHOW); // turn on display, set invisiblecursor

//    u8 arr[] = {0,10,31,31,14,4,0,0};
//    u8 arr2[]= {0,10,21,17,10,4,0,0};

//    hd44780_cgram_write(0, arr);
//    hd44780_cgram_write(1, arr2);

    hd44780_cmd(0x01); // clear display, go to 0x0

//    hd44780_backlight(initial_backlight);
//    hd44780_print("Linia 0");
//    hd44780_go_to_line(1);
//    hd44780_print("Linia 1");
//    hd44780_go_to_line(2);
//    hd44780_print("Linia 2");
//    hd44780_go_to_line(3);
//    hd44780_print("Linia 3");

//    hd44780_char(0);
//    hd44780_char(1);
}
 /**
   * @brief		ADXL345_LowLevel_Init, low level initialization routine for ADXL345 connected via I2C Peripheral
   * @param		None
   * @retval	None
   */
  void ADXL345_LowLevel_Init(){
	  GPIO_InitTypeDef	GPIO_InitStructure;

	  I2C_LowLevel_Init();

	  //Enable INT1 GPIO Clock
	  RCC_AHB1PeriphClockCmd(ADXL345_I2C_INT1_GPIO_CLK, ENABLE);

	  //Enable INT2 GPIO Clock
	  RCC_AHB1PeriphClockCmd(ADXL345_I2C_INT2_GPIO_CLK, ENABLE);

	  //Configure INT1 and INT2 pins to detect interrupts
	  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

	  GPIO_InitStructure.GPIO_Pin = ADXL345_I2C_INT1_PIN;
	  GPIO_Init(ADXL345_I2C_INT1_GPIO_PORT, &GPIO_InitStructure);

	  GPIO_InitStructure.GPIO_Pin = ADXL345_I2C_INT2_PIN;
	  GPIO_Init(ADXL345_I2C_INT2_GPIO_PORT, &GPIO_InitStructure);
  }
int i2cdevInit(I2C_TypeDef *I2Cx)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  
  if (I2Cx == I2C1)
  {
    i2cdevResetBusI2c1();
    // Enable the DMA1 channel6 Interrupt
    NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_ADC_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    // Enable the DMA1 channel7 Interrupt
    NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_ADC_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    // Enable the I2C error interrupt
    NVIC_InitStructure.NVIC_IRQChannel = I2C1_ER_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_ADC_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE);
    DMA_ITConfig(DMA1_Channel7, DMA_IT_TC, ENABLE);
    vSemaphoreCreateBinary(i2cdevDmaEventI2c1);
  }
  else if (I2Cx == I2C2)
  {
    I2C_LowLevel_Init(I2Cx);
    // Enable the DMA1 channel4 Interrupt
    NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_ADC_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    // Enable the DMA1 channel5 Interrupt
    NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_ADC_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    // Enable the I2C error interrupt
    NVIC_InitStructure.NVIC_IRQChannel = I2C2_ER_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_ADC_PRI;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    DMA_ITConfig(DMA1_Channel4, DMA_IT_TC, ENABLE);
    DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE);
    vSemaphoreCreateBinary(i2cdevDmaEventI2c2);
  }
  else
  {
    return FALSE;
  }
  
  return TRUE;
}