Guest User

GSM interfacing STM32F407

a guest
Feb 6th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.36 KB | None | 0 0
  1. main()
  2. {
  3.  GPIOInitialize();
  4.  UART_Initialize();
  5.  USART_puts("AT\r");
  6.  USART_puts("AT+CREG?\r");
  7.  USART_puts("AT+CGATT=1\r"); //GPRS ok
  8.  USART_puts("AT+CIPSHUT\r");
  9.  USART_puts("AT+CSTT=\"airtelgprs.com\"\r");
  10.  USART_puts("AT+CIICR\r");
  11.  USART_puts("AT+CIPSTART=\"TCP\",\"www.google.com\",\"80\"\r");
  12. }
  13. void USART1_IRQHandler()
  14. {  
  15.  if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //it checks receive complete interrupt(USART_IT_RXNE) on USARTx
  16.  {
  17.    
  18.      rx_web = USART_ReceiveData(USART1);
  19.          
  20.      if(rx_web == 0x0A || rx_web == 0x0D)
  21.          {
  22.                 count++;
  23.              if(count==4)
  24.              {end_flag=1;}
  25.        }
  26.      else if(rx_index < LINEMAX)
  27.      {
  28.          rx_buf_web[rx_index++]=rx_web;
  29.                          
  30.          }
  31.          
  32.      }   
  33. }
  34. void UART_Initialize(void)
  35. {
  36.    
  37.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  38.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
  39.  USART_InitStructure.USART_BaudRate = 9600;
  40.  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  41.  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  42.  USART_InitStructure.USART_Parity = USART_Parity_No;
  43.  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  44.  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  45.  USART_Init(USART1, &USART_InitStructure); // USART configuration
  46.  USART_Init(USART2, &USART_InitStructure); // USART configuration  
  47.  USART_Cmd(USART1, ENABLE); // Enable USART
  48.  USART_Cmd(USART2, ENABLE); // Enable USART
  49. }
  50. void GPIOInitialize(void)
  51. {
  52.   GPIO_InitTypeDef GPIO_InitStructure; 
  53.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); //Enable clock for GPIOB
  54.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  55.    
  56.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7  ;
  57.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  58.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  59.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  60.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  61.   GPIO_Init(GPIOB, &GPIO_InitStructure);
  62.   GPIO_Init(GPIOD, &GPIO_InitStructure);   
  63.   GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);//Connect PB6 to USART1_Tx
  64.   GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);//Connect PB7 to USART1_Rx
  65.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);//connect PA5 to USART2_Tx
  66.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);//Connect PA6 to USART2_Rx
  67.  
  68. }
Add Comment
Please, Sign In to add comment