Advertisement
Guest User

stm32f4

a guest
Aug 5th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.93 KB | None | 0 0
  1.  
  2. //main.c
  3. /* Includes ------------------------------------------------------------------*/
  4. #include "main.h"
  5. #define readAddress 0xEF       
  6. #define writeAddress 0xEE
  7.  
  8. /* Oversampling setting */
  9. //volatile uint8_t OSS = 0;
  10.  
  11. // Calibration values
  12. int ac1;
  13. int ac2;
  14. int ac3;
  15. unsigned int ac4;
  16. unsigned int ac5;
  17. unsigned int ac6;
  18. int b1;
  19. int b2;
  20. int mb;
  21. int mc;
  22. int md;
  23. /*
  24. long b5;
  25.  
  26. short temperature;
  27. long pressure;
  28.  
  29. // Use these for altitude conversions
  30. const float p0 = 101325;     // Pressure at sea level (Pa)
  31. float altitude;
  32. */
  33. /*
  34. int BMP085readCalibration(uint8_t address)
  35. {
  36.     uint8_t msb, lsb;
  37.     msb = TM_I2C_Read(I2C1, writeAddress, address);
  38.     lsb = TM_I2C_Read(I2C1, writeAddress, address + 1);
  39.    
  40.     return (int) msb << 8 | lsb;
  41.    
  42. }
  43.  
  44.  
  45. void BMP085Calibration()
  46. {
  47.     ac1 = BMP085readCalibration(0xAA);
  48.   ac2 = BMP085readCalibration(0xAC);
  49.   ac3 = BMP085readCalibration(0xAE);
  50.   ac4 = BMP085readCalibration(0xB0);
  51.   ac5 = BMP085readCalibration(0xB2);
  52.   ac6 = BMP085readCalibration(0xB4);
  53.   b1 = BMP085readCalibration(0xB6);
  54.   b2 = BMP085readCalibration(0xB8);
  55.   mb = BMP085readCalibration(0xBA);
  56.   mc = BMP085readCalibration(0xBC);
  57.   md = BMP085readCalibration(0xBE);
  58. }
  59.  
  60. int BMP085readUT()
  61. {
  62.     int ut,i;
  63.    
  64.    
  65.     TM_I2C_Write(I2C1, writeAddress, 0xF4, 0x2E);
  66.         Delayms(5);
  67.  
  68.    
  69.     ut = BMP085readCalibration(0xF6);
  70.    
  71.     return ut;
  72. }
  73. */
  74.  
  75.  
  76. int main(void)
  77. {
  78.  
  79.     /* System initialization*/
  80.   SystemInit();
  81.  
  82.   /* Initialize I2C, SCL = PB6 and SDA = PB7 with 100kHz serial clock */
  83.   //TM_I2C_Init(I2C1, TM_I2C_PinsPack_1, 100000);
  84.    
  85.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
  86.   GPIO_InitTypeDef GPIO_InitDef;
  87.  
  88.   GPIO_InitDef.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14;
  89.   GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
  90.   GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
  91.   GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;
  92.   GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz;
  93.   //Initialize pins
  94.   GPIO_Init(GPIOG, &GPIO_InitDef);
  95.    
  96.    
  97.    
  98.     TM_DELAY_Init();
  99.    
  100.    
  101.    
  102.     //BMP085Calibration();
  103.    
  104.     //int temperature = BMP085readUT();
  105.        
  106.    
  107.    
  108.    
  109.   while (1)
  110.     {
  111.         GPIO_ToggleBits(GPIOG, GPIO_Pin_13 | GPIO_Pin_14);
  112.         Delayms(1000);
  113.     }
  114. }
  115.  
  116.  
  117.  
  118. //main.h
  119. /* Define to prevent recursive inclusion -------------------------------------*/
  120. #ifndef __MAIN_H
  121. #define __MAIN_H
  122.  
  123. /* Includes ------------------------------------------------------------------*/
  124. #include "stm32f4xx.h"
  125. #include "tm_stm32f4_delay.h"
  126. #include "tm_stm32f4_onewire.h"
  127. #include "tm_stm32f4_usart.h"
  128. #include "tm_stm32f4_i2c.h"
  129. #include "tm_stm32f4_timer_properties.h"
  130. #include <stdio.h>
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. /* Exported types ------------------------------------------------------------*/
  140. /* Exported constants --------------------------------------------------------*/
  141. /* Exported macro ------------------------------------------------------------*/
  142. /* Exported functions ------------------------------------------------------- */
  143.  
  144.  
  145. #endif /* __MAIN_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement