Advertisement
tejaganeshkumar

gsm code for sending message with stm32f40vct6 not working

Oct 12th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.40 KB | None | 0 0
  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ******************************************************************************
  6.   *
  7.   * COPYRIGHT(c) 2015 STMicroelectronics
  8.   *
  9.   * Redistribution and use in source and binary forms, with or without modification,
  10.   * are permitted provided that the following conditions are met:
  11.   *   1. Redistributions of source code must retain the above copyright notice,
  12.   *      this list of conditions and the following disclaimer.
  13.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  14.   *      this list of conditions and the following disclaimer in the documentation
  15.   *      and/or other materials provided with the distribution.
  16.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  17.   *      may be used to endorse or promote products derived from this software
  18.   *      without specific prior written permission.
  19.   *
  20.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.   *
  31.   ******************************************************************************
  32.   */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32f4xx_hal.h"
  35. #include <stdio.h>
  36. #include  <string.h>
  37.  
  38.  
  39. /* USER CODE BEGIN Includes */
  40.  
  41. /* USER CODE END Includes */
  42. void delay(void);
  43. /* Private variables ---------------------------------------------------------*/
  44. UART_HandleTypeDef huart2;
  45.  
  46. /* USER CODE BEGIN PV */
  47. /* Private variables ---------------------------------------------------------*/
  48. #define  temp1
  49. /* USER CODE END PV */
  50. static void USART_INIT(unsigned int );
  51. /* Private function prototypes -----------------------------------------------*/
  52. void SystemClock_Config(void);
  53. static void MX_GPIO_Init(void);
  54.  
  55.  
  56. /* USER CODE BEGIN PFP */
  57. /* Private function prototypes -----------------------------------------------*/
  58.  
  59. /* USER CODE END PFP */
  60.  
  61. /* USER CODE BEGIN 0 */
  62. /* USER CODE END 0 */
  63. uint8_t Data1[6]={'A','T','E','0','\r','\n'};
  64. uint8_t rxread1[11];
  65. uint16_t R1=11;
  66. uint8_t Data2[4]={'A','T','\r','\n'};
  67. uint8_t rxread2[6];
  68. uint16_t R2=6;
  69. uint8_t rxread5[6];
  70. uint16_t R5=6;
  71. uint8_t Data3[22]={'A','T','+','C','M','G','S','=','"','x','x','x','x','x','x','x','x','x','x','"','\r','\n'};
  72. uint8_t rxread3[3];
  73. uint16_t R3=3;
  74. uint8_t Data4[8]={'E','M','B','S','Y','S','2','6'};
  75. uint8_t rxread6[19];
  76. uint16_t R6=19;
  77. uint8_t rxread4[17];
  78. uint16_t R4=17;
  79. uint16_t S1=6;
  80. uint16_t S2=4;
  81. uint16_t S3=22;
  82. uint16_t S4=6;
  83. uint16_t S5=2;
  84. uint32_t T=9;
  85. unsigned char at=0;
  86. unsigned char st=10;   
  87. unsigned char st2=10;  
  88. unsigned char st3=10;  
  89. uint8_t cmprxrd1[11]={'A','T','E','0','\r','\r','\n','O','K','\r','\n'};   
  90. uint8_t cmprxrd2[6]={'\r','\n','O','K','\r','\n'};
  91. uint8_t cmprxrd3[3]={'\r','\n','>'};
  92. //uint8_t cmprxrd4[]={};   
  93. void delay(void)
  94. {
  95. unsigned int c=900;
  96.  
  97. while(c)
  98. {
  99. c--;
  100. }  
  101.    
  102. }
  103.  
  104. unsigned int ret=10;
  105.  
  106. int main(void)
  107. {
  108.  
  109.   /* USER CODE BEGIN 1 */
  110.  
  111.   /* USER CODE END 1 */
  112.  
  113.   /* MCU Configuration----------------------------------------------------------*/
  114.  
  115.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  116. ////  HAL_Init();
  117.  
  118.   /* Configure the system clock */
  119.   SystemClock_Config();
  120.   /* Initialize all configured peripherals */
  121.   MX_GPIO_Init();
  122.  
  123.      USART_INIT(9600);
  124.  
  125.         delay();
  126.     delay();
  127.    
  128.  
  129. HAL_UART_Transmit(&huart2,Data1,S1,T);
  130. delay();
  131. if (USART_SR_TC)
  132. HAL_UART_Receive(&huart2,rxread1,R1,T);
  133. delay();
  134. if (rxread1==cmprxrd1)
  135.  
  136.      HAL_UART_Transmit(&huart2,Data2,S2,T);
  137.      delay();
  138.      HAL_UART_Receive(&huart2,rxread2,R2,T);
  139.      delay();
  140. /*     HAL_UART_Transmit(&huart2,Data2,S2,T);
  141.      delay();
  142.      HAL_UART_Receive(&huart2,rxread2,R2,T);
  143.      delay();*/
  144.         if (rxread2==cmprxrd2)
  145.  
  146.              HAL_UART_Transmit(&huart2,Data3,S3,T);
  147.              delay();
  148.                 at++;
  149.              HAL_UART_Receive(&huart2,rxread3,R3,T);
  150.              delay();
  151.                 if (rxread3==cmprxrd3)
  152.                  HAL_UART_Transmit(&huart2,Data4,S4,T);
  153.         HAL_UART_Receive(&huart2,rxread4,R4,T);
  154.                     delay();
  155.                                      
  156.                                
  157. while(1)       
  158.     {
  159.        
  160.    
  161.    
  162.    
  163.     }
  164.        
  165.        
  166. return 0;
  167. }  
  168. /** System Clock Configuration
  169. */
  170. void SystemClock_Config(void)
  171. {
  172.  
  173.   RCC_OscInitTypeDef RCC_OscInitStruct;
  174.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  175.  
  176.   __PWR_CLK_ENABLE();
  177.  
  178.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  179.  
  180.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  181.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  182.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  183.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  184.   RCC_OscInitStruct.PLL.PLLM = 8;
  185.   RCC_OscInitStruct.PLL.PLLN = 336;
  186.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  187.   RCC_OscInitStruct.PLL.PLLQ = 7;
  188.   HAL_RCC_OscConfig(&RCC_OscInitStruct);
  189.  
  190.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
  191.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  192.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  193.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  194.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  195.   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
  196.  
  197.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  198.  
  199.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  200.  
  201. }
  202.  
  203.  
  204. static void USART_INIT(unsigned int baud )
  205. {
  206.    
  207.     huart2.Instance = USART2;
  208.   huart2.Init.BaudRate = 9600;
  209.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  210.   huart2.Init.StopBits = UART_STOPBITS_1;
  211.   huart2.Init.Parity = UART_PARITY_NONE;
  212.   huart2.Init.Mode = UART_MODE_TX_RX;
  213.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  214.   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  215.   HAL_UART_Init(&huart2);
  216.    
  217. }
  218.  
  219.  
  220. void MX_GPIO_Init(void)
  221. {
  222.  
  223.   GPIO_InitTypeDef GPIO_InitStruct;
  224.  
  225.   /* GPIO Ports Clock Enable */
  226.   __GPIOE_CLK_ENABLE();
  227.   __GPIOC_CLK_ENABLE();
  228.   __GPIOH_CLK_ENABLE();
  229.   __GPIOA_CLK_ENABLE();
  230.   __GPIOB_CLK_ENABLE();
  231.   __GPIOD_CLK_ENABLE();
  232.  
  233.   /*Configure GPIO pin : PE2 */
  234.   GPIO_InitStruct.Pin = GPIO_PIN_2;
  235.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  236.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  237.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  238.  
  239.   /*Configure GPIO pin : PE3 */
  240.   GPIO_InitStruct.Pin = GPIO_PIN_3;
  241.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  242.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  243.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  244.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  245.  
  246.   /*Configure GPIO pins : PE4 PE5 PE1 */
  247.   GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_1;
  248.   GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  249.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  250.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  251.  
  252.   /*Configure GPIO pin : PC0 */
  253.   GPIO_InitStruct.Pin = GPIO_PIN_0;
  254.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  255.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  256.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  257.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  258.  
  259.   /*Configure GPIO pin : PC3 */
  260.   GPIO_InitStruct.Pin = GPIO_PIN_3;
  261.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  262.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  263.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  264.   GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  265.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  266.  
  267.   /*Configure GPIO pin : PA0 */
  268.   GPIO_InitStruct.Pin = GPIO_PIN_0;
  269.   GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  270.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  271.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  272.  
  273.   /*Configure GPIO pin : PA4 */
  274.   GPIO_InitStruct.Pin = GPIO_PIN_4;
  275.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  276.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  277.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  278.   GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  279.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  280.  
  281.   /*Configure GPIO pins : PA5 PA6 PA7 */
  282.   GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  283.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  284.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  285.   GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  286.   GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  287.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  288.  
  289.   /*Configure GPIO pins : PB10 PB12 */
  290.   GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_12;
  291.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  292.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  293.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  294.   GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  295.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  296.  
  297.   /*Configure GPIO pins : PD12 PD13 PD14 PD15
  298.                            PD4 */
  299.   GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
  300.                           |GPIO_PIN_4;
  301.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  302.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  303.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  304.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  305.  
  306.   /*Configure GPIO pins : PC7 PC10 PC12 */
  307.   GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_10|GPIO_PIN_12;
  308.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  309.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  310.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  311.   GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  312.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  313.  
  314.   /*Configure GPIO pin : PA9 */
  315.   GPIO_InitStruct.Pin = GPIO_PIN_9;
  316.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  317.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  318.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  319.  
  320.   /*Configure GPIO pins : PA10 PA11 PA12 */
  321.   GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
  322.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  323.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  324.   GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  325.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  326.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  327.  
  328.   /*Configure GPIO pin : PD5 */
  329.   GPIO_InitStruct.Pin = GPIO_PIN_5;
  330.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  331.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  332.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  333.  
  334.   /*Configure GPIO pins : PB6 PB9 */
  335.   GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_9;
  336.   GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  337.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  338.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  339.   GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
  340.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  341.  
  342. }
  343.  
  344. /* USER CODE BEGIN 4 */
  345.  
  346. /* USER CODE END 4 */
  347.  
  348. #ifdef USE_FULL_ASSERT
  349.  
  350. /**
  351.    * @brief Reports the name of the source file and the source line number
  352.    * where the assert_param error has occurred.
  353.    * @param file: pointer to the source file name
  354.    * @param line: assert_param error line source number
  355.    * @retval None
  356.    */
  357. void assert_failed(uint8_t* file, uint32_t line)
  358. {
  359.   /* USER CODE BEGIN 6 */
  360.   /* User can add his own implementation to report the file name and line number,
  361.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  362.   /* USER CODE END 6 */
  363.  
  364. }
  365.  
  366. #endif
  367.  
  368. /**
  369.   * @}
  370.   */
  371.  
  372. /**
  373.   * @}
  374. */
  375.  
  376. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement