Guest User

Untitled

a guest
Feb 22nd, 2010
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.20 KB | None | 0 0
  1. #include "stm32f10x_lib.h"
  2. #include "stm32f10x_usart.h"
  3. #include "stm32f10x_gpio.h"
  4. #include "stm32f10x_map.h"
  5. #include "stm32f10x_rcc.h"
  6. #include "bits.h"
  7.  
  8. #define STACK_TOP 0x20000800
  9. #define NVIC_CCR ((volatile unsigned long *)(0xE000ED14))
  10.  
  11. void nmi_handler(void);
  12. void hardfault_handler(void);
  13. void myDelay(unsigned long delay);
  14. void out_string(char* str);
  15.  
  16. int main(void);
  17.  
  18. // Define the vector table
  19.     unsigned int * myvectors[59]
  20.      __attribute__ ((section("vectors")))= {
  21.     (unsigned int *)    0x20000800, // stack pointer
  22.     (unsigned int *)    main,       // code entry point
  23.     (unsigned int *)    nmi_handler,        // NMI handler (not really)
  24.     (unsigned int *)    hardfault_handler       // hard fault handler (let's hope not)
  25.    /*(unsigned int *)   0,0,0,0,0,0,0,0,0,0
  26.                         0,0,0,0,0,0,0,0,0,0
  27.                         0,0,0,0,0,0,0,0,0,0
  28.                         0,0,0,0,0,0,0,0,0,0
  29.                         0,0,0,0,0,0,0,0,0,0
  30.                         0,0,0,0,0,0*/
  31. };
  32.  
  33.  
  34. //Definiton of Structure
  35. USART_InitTypeDef USART_InitStructure;
  36. GPIO_InitTypeDef GPIO_InitStructure;
  37.  
  38. //#define TxBufferSize   (countof(TxBuffer))
  39. //#define countof(a)   (sizeof(a) / sizeof(*(a)))
  40.  
  41. int main(void)
  42. {
  43.     //Private Variable
  44.     u8 TxBuffer[] = "Buffer Send from USART2 to USART1 using Flags";
  45.     u8 RxBuffer[45];
  46.     u8 TxCounter = 0, RxCounter = 0;
  47.  
  48.  
  49.     *NVIC_CCR = *NVIC_CCR | 0x200; /* Set STKALIGN in NVIC */
  50.  
  51. //---------------Clock Init------------------------------------------------------
  52.         RCC_DeInit();
  53.  
  54.         // 1. Cloking the controller from internal HSI RC (8 MHz)
  55.         RCC_HSICmd(ENABLE);
  56.  
  57.         // wait until the HSI is ready
  58.         while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
  59.  
  60.         //System Clock auf HSI 8Mhz
  61.         RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
  62.  
  63.         RCC_PCLK2Config(RCC_HCLK_Div1);
  64.         RCC_PCLK1Config(RCC_HCLK_Div2);
  65.  
  66.         RCC_HCLKConfig(RCC_SYSCLK_Div1);
  67.         // Flash 1 wait state
  68.         *(vu32 *)0x40022000 = 0x12;
  69.  
  70.         //Clock Enable USART2 & GPIOA
  71.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
  72.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
  73.  
  74. //---------------------------- GPIO - Configuration --------------------------------------
  75.  
  76.         // Configure PA.0 as output push-pull
  77.         GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0;
  78.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  79.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  80.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  81.  
  82.         // Configure PA.12 as output push-pull
  83.         GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_12;
  84.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  85.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  86.         GPIO_Init(GPIOC, &GPIO_InitStructure);
  87.  
  88.  
  89.         //Configure TX as Output - Alternate Function Push-Pull
  90.         GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2;
  91.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  92.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  93.  
  94.         //Configure RX as Input - Input Floating
  95.         GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_3;
  96.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  97.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  98.  
  99. //------------------------------------------------------------------------------------
  100.  
  101.     //Configuration of USART2
  102.     USART_InitStructure.USART_BaudRate = 11500;//0x2580; /* 9600 Baud */
  103.     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  104.     USART_InitStructure.USART_Parity = USART_Parity_No;
  105.     USART_InitStructure.USART_StopBits = USART_StopBits_1;
  106.     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  107.     USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  108.     USART_Init(USART2,&USART_InitStructure);
  109.  
  110.     USART_Cmd(USART2,ENABLE);
  111.  
  112.  //----------------- String senden ---------------------------------------------
  113.     while(TxCounter <= 45)
  114.     {
  115.         USART_SendData(USART2,TxBuffer[TxCounter++]);
  116.         while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
  117.         {
  118.         }
  119.  
  120.     }
  121.     while(1)
  122.     {
  123.     }
  124.  
  125. }
  126.  
  127. //-------------------------------------------------------------------------------
  128. void nmi_handler(void)
  129. {
  130.     return ;
  131. }
  132.  
  133. void hardfault_handler(void)
  134. {
  135.     return ;
  136. }
  137.  
  138. void myDelay(unsigned long delay)
  139. {
  140.     while(delay) delay--;
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment