AnsweredAssumed Answered

STM32F4 USART COMMUNICATION

Question asked by delos_reyes.kristian on Feb 6, 2013
Latest reply on Feb 6, 2013 by delos_reyes.kristian
Hi Guyz,

it doesnot want to output, I have checked RCC and all initialization..  what am I still Missing?

001./**
002.  ******************************************************************************
003.  * @file    IO_Toggle/main.c
004.  * @author  MCD Application Team
005.  * @version V1.0.0
006.  * @date    19-September-2011
007.  * @brief   Main program body
008.  ******************************************************************************
009.  * @attention
010.  *
011.  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
012.  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
013.  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
014.  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
015.  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
016.  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
017.  *
018.  * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
019.  ****************************************************************************** 
020.  */
021. 
022./* Includes ------------------------------------------------------------------*/
023.#include "stm32f4_discovery.h"
024. 
025. 
026.GPIO_InitTypeDef  GPIO_InitStructure;
027.USART_InitTypeDef USART_InitStructure;
028. 
029.void Delay(__IO uint32_t nCount);
030.void resetDataAndCounter(void);
031.void SendData(void);
032. 
033.int datas[40];
034.int DIOData = 0;
035.int ctr=0;
036. 
037.int main(void)
038.{
039.  /* GPIOD Periph clock enable */
040.  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
041.  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
042.  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
043.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
044. 
045.  /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
046.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
047.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
048.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
049.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
050.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
051.  GPIO_Init(GPIOD, &GPIO_InitStructure);
052.   
053.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
054.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
055.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
056.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
057.  GPIO_Init(GPIOA, &GPIO_InitStructure);
058.   
059.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
060.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
061.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
062.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
063.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
064.  GPIO_Init(GPIOA, &GPIO_InitStructure);
065.   
066.  USART_InitStructure.USART_BaudRate = 115200;
067.  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
068.  USART_InitStructure.USART_StopBits = USART_StopBits_1;
069.  USART_InitStructure.USART_Parity = USART_Parity_No ;
070.  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
071.  USART_InitStructure.USART_Mode = USART_Mode_Tx;
072.  USART_Init(USART2, &USART_InitStructure);
073.  USART_Cmd(USART2, ENABLE);
074.   
075.   
076.   
077.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
078.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
079.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
080.   GPIO_Init(GPIOC, &GPIO_InitStructure);
081.    
082.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ; 
083.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
084.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
085.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
086.   GPIO_Init(GPIOA, &GPIO_InitStructure);
087.   
088.  resetDataAndCounter();
089.  while (1)
090.  {
091.    USART_SendData(USART2,65);
092.    if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)==1)
093.    {
094.      GPIOD->BSRRL = GPIO_Pin_12;
095.      DIOData = 255 - GPIOC ->IDR>>0 & 0x00FF;
096.      if ((DIOData > 40)&&(DIOData <=96))
097.      {
098.        datas[ctr] = DIOData;
099.        ctr++;
100.      }
101.    if (ctr ==40)
102.    {
103.      SendData();
104.      ctr = 0;
105.    }
106.    }
107.    else
108.    {
109.      //GPIOD->BSRRH = GPIO_Pin_12;
110.    }
111.  }
112.}
113. 
114.void resetDataAndCounter(void)
115. {
116.    ctr = 0;
117.    for (int ctr1 = 0; ctr1 <40; ctr1++)
118.    {
119.      datas[ctr1] = 0;
120.    }
121. }
122.  
123. void SendData(void)
124. {
125.   for (int ctr1 = 0; ctr1<30; ctr1++)
126.   {
127.    USART_SendData(USART2, datas[ctr1]);
128.    for (int ctr2=0; ctr2<=70024; ctr2++);
129.   }
130.   USART_SendData(USART2,44);
131. }
132. 
133./**
134.  * @brief  Delay Function.
135.  * @param  nCount:specifies the Delay time length.
136.  * @retval None
137.  */
138.void Delay(__IO uint32_t nCount)
139.{
140.  while(nCount--)
141.  {
142.  }
143.}
144. 
145.#ifdef  USE_FULL_ASSERT
146. 
147./**
148.  * @brief  Reports the name of the source file and the source line number
149.  *         where the assert_param error has occurred.
150.  * @param  file: pointer to the source file name
151.  * @param  line: assert_param error line source number
152.  * @retval None
153.  */
154.void assert_failed(uint8_t* file, uint32_t line)
155.{
156.  /* User can add his own implementation to report the file name and line number,
157.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
158. 
159.  /* Infinite loop */
160.  while (1)
161.  {
162.  }
163.}
164.#endif
165. 
166./**
167.  * @}
168.  */
169. 
170./**
171.  * @}
172.  */
173. 
174./******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

Outcomes