Advertisement
Guest User

compas3

a guest
May 24th, 2012
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.28 KB | None | 0 0
  1. #include <stm32f10x.h>
  2. #include "DWLOS_config.h"
  3. #include "DWLOS.h"
  4.  
  5. #define  __INITh
  6. #include "Init.h"
  7. #include "i2c_interrupt.h"
  8. #include "z_S65.h"
  9.  
  10.  
  11. void initAll ()
  12.  {
  13.   SystemInit ();
  14.  
  15. //  RCC_Configuration
  16.   RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN |
  17.                     RCC_APB2ENR_IOPBEN |
  18.                     RCC_APB2ENR_AFIOEN |
  19.                     RCC_APB2ENR_SPI1EN;
  20.  
  21.  
  22. //  GPIO_Configuration
  23.   // TIM2 CH2 = PA1
  24.   GPIOA -> CRL |= GPIO_CRL_CNF1_1;
  25.   GPIOA -> CRL &= ~GPIO_CRL_CNF1_0; // 0
  26.   GPIOA -> CRL |= GPIO_CRL_MODE1_1 | GPIO_CRL_MODE1_0;
  27.  
  28.   // (RS) = PA2
  29.   GPIOA -> CRL &= ~GPIO_CRL_CNF2_1;
  30.   GPIOA -> CRL &= ~GPIO_CRL_CNF2_0;
  31.   GPIOA -> CRL |= GPIO_CRL_MODE2_1 | GPIO_CRL_MODE2_0;
  32.  
  33.   // (RESET) = PA3
  34.   GPIOA -> CRL &= ~GPIO_CRL_CNF3_1;
  35.   GPIOA -> CRL &= ~GPIO_CRL_CNF3_0;
  36.   GPIOA -> CRL |= GPIO_CRL_MODE3_1 | GPIO_CRL_MODE3_0;
  37.   GPIOA -> BSRR |= GPIO_BSRR_BS3;
  38.  
  39.   // SPI1.NSS (CS) = PA4
  40.   GPIOA -> CRL &= ~GPIO_CRL_CNF4_1; //1
  41.   GPIOA -> CRL &= ~GPIO_CRL_CNF4_0;
  42.   GPIOA -> CRL |= GPIO_CRL_MODE4_1 | GPIO_CRL_MODE4_0;
  43.   GPIOA -> BSRR |= GPIO_BSRR_BS4;
  44.  
  45.   // SPI1.CLK (CLK) = PA5
  46.   GPIOA -> CRL |= GPIO_CRL_CNF5_1;
  47.   GPIOA -> CRL &= ~GPIO_CRL_CNF5_0;
  48.   GPIOA -> CRL |= GPIO_CRL_MODE5_1 | GPIO_CRL_MODE5_0;
  49.  
  50.   // SPI1.MOSI (DAT) = PA7
  51.   GPIOA -> CRL |= GPIO_CRL_CNF7_1;
  52.   GPIOA -> CRL &= ~GPIO_CRL_CNF7_0;
  53.   GPIOA -> CRL |= GPIO_CRL_MODE7_1 | GPIO_CRL_MODE7_0;
  54.  
  55.   // SPI1.MISO = PA6
  56.   GPIOA -> CRL |= GPIO_CRL_CNF6_1;
  57.   GPIOA -> CRL &= ~GPIO_CRL_CNF6_0;
  58.   GPIOA -> CRL |= GPIO_CRL_MODE6_1 | GPIO_CRL_MODE6_0;
  59.  
  60. // PB0 -- Button 1
  61.   GPIOB -> CRL &= ~GPIO_CRL_CNF0_1;
  62.   GPIOB -> CRL |= GPIO_CRL_CNF0_0;
  63.   GPIOB -> CRL &= ~(GPIO_CRL_MODE0_1 | GPIO_CRL_MODE0_0);
  64.   GPIOB -> BSRR |= GPIO_BSRR_BR0;
  65.  
  66.   // PB1 -- Button 2
  67.   GPIOB -> CRL &= ~GPIO_CRL_CNF1_1;
  68.   GPIOB -> CRL |= GPIO_CRL_CNF1_0;
  69.   GPIOB -> CRL &= ~(GPIO_CRL_MODE1_1 | GPIO_CRL_MODE1_0);
  70.   GPIOB -> BSRR |= GPIO_BSRR_BR1;
  71.  
  72.   // PB10 -- Button 3
  73.   GPIOB -> CRH &= ~GPIO_CRH_CNF10_1;
  74.   GPIOB -> CRH |= GPIO_CRH_CNF10_0;
  75.   GPIOB -> CRH &= ~(GPIO_CRH_MODE10_1 | GPIO_CRH_MODE10_0);
  76.   GPIOB -> BSRR |= GPIO_BSRR_BR10;// */
  77.  
  78.  
  79.   // Disable JTAG and SWD pins
  80.   AFIO -> MAPR |= AFIO_MAPR_SWJ_CFG_DISABLE;
  81.  
  82.  
  83.  
  84.  
  85.  
  86. // upTime Timer
  87.   RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN;
  88.  
  89.   TIM2 -> CR1 &= ~(TIM_CR1_CKD_1 | TIM_CR1_CKD_0);  // Clock division
  90.   TIM2 -> CR1 &= ~(TIM_CR1_CMS_1 | TIM_CR1_CMS_0);  // Center-aligned mode
  91.   TIM2 -> CR1 &= ~(TIM_CR1_DIR);            // Direction - UP
  92.   TIM2 -> CR1 |= TIM_CR1_ARPE;              // Autoreload
  93.   TIM2 -> ARR = 10000;                  // Max value
  94.   TIM2 -> PSC = 36000;                  // Prescalar
  95.   TIM2 -> EGR = TIM_EGR_TG | TIM_EGR_UG;        // Load ARR to snacke registers
  96.  
  97.   /*/ OC1
  98.   TIM2 -> CCMR1 &= ~(TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2);
  99.   TIM2 -> CCMR1 |= TIM_CCMR1_OC1M_0;
  100.   TIM2 -> CCER |= TIM_CCER_CC1E;
  101.   TIM2 -> CCR1 = 500;// */
  102.  
  103.   TIM2 -> DIER |= TIM_DIER_UIE;     // TIM IT enable
  104.   TIM2 -> CR1 |= TIM_CR1_CEN;       // TIM2 enable counter
  105.  
  106.   NVIC_SetPriority (TIM2_IRQn, 0);
  107.   NVIC_EnableIRQ (TIM2_IRQn);
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. //  NVIC_Configuration
  115.   NVIC_SetPriority (DMA1_Channel3_IRQn, 7); // SPI1 TX
  116.   NVIC_EnableIRQ (DMA1_Channel3_IRQn);
  117.  
  118.  
  119.   I2C1_init (I2C_REMAP);
  120. //  I2C2_init ();
  121.  
  122.  
  123.  
  124.  
  125.  
  126. // DMA1 Channel3 -- SPI
  127.   SPI_Tx_DMA -> CCR &= ~DMA_CCR3_MEM2MEM;
  128.   SPI_Tx_DMA -> CCR |= DMA_CCR3_PL_1 | DMA_CCR3_PL_0;
  129.   SPI_Tx_DMA -> CCR &= ~DMA_CCR3_MSIZE_1;
  130.   SPI_Tx_DMA -> CCR |= DMA_CCR3_MSIZE_0;
  131.   SPI_Tx_DMA -> CCR &= ~DMA_CCR3_PSIZE_1;
  132.   SPI_Tx_DMA -> CCR |= DMA_CCR3_PSIZE_0;
  133.   SPI_Tx_DMA -> CCR |= DMA_CCR3_MINC;
  134.   SPI_Tx_DMA -> CCR &= ~DMA_CCR3_PINC;
  135.   SPI_Tx_DMA -> CCR &= ~DMA_CCR3_CIRC;
  136.   SPI_Tx_DMA -> CCR |= DMA_CCR3_DIR;
  137.   SPI_Tx_DMA -> CPAR = (uint32_t) (SPI1_BASE + 0x0C);
  138. //  SPI_Tx_DMA -> CCR |= DMA_CCR3_TCIE;
  139.  
  140.  
  141. // SPI Configuration
  142. //  SPI1 -> CR1 |= SPI_CR1_BIDIMODE;
  143. //  SPI1 -> CR1 |= SPI_CR1_BIDIOE;
  144.   SPI1 -> CR1 &= ~SPI_CR1_CRCEN;
  145.   SPI1 -> CR1 |= SPI_CR1_DFF;
  146. //    SPI1 -> CR1 |= SPI_CR1_BR_2;
  147.     SPI1 -> CR1 |= SPI_CR1_BR_1;
  148. //    SPI1 -> CR1 |= SPI_CR1_BR_0;
  149.   SPI1 -> CR1 |= SPI_CR1_SSM;
  150.   SPI1 -> CR1 |= SPI_CR1_SSI;
  151.   SPI1 -> CR1 |= SPI_CR1_MSTR;
  152.   SPI1 -> CR1 &= ~SPI_CR1_CPOL;
  153.   SPI1 -> CR1 &= ~SPI_CR1_CPHA;
  154. //  SPI1 -> CR2 |= SPI_CR2_SSOE;
  155. //  SPI1 -> CR2 |= SPI_CR2_TXDMAEN;
  156.   SPI1 -> CR1 |= SPI_CR1_SPE;
  157.  
  158.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement