Author Topic: stm32 UART communcation problems  (Read 2870 times)

0 Members and 1 Guest are viewing this topic.

Offline pranay singhTopic starter

  • Newbie
  • Posts: 3
stm32 UART communcation problems
« on: March 28, 2014, 06:52:11 am »
Hello,
I'm using a stm32f100RB microcontroller, I'm having 2 issues

1)
When i plug in the board via USB, after installing the drivers succesfully, in device manager the board is shown under disk drives instead of ports. How do i get it under ports ? My computer is recognizing the board as a mass storage device. Although I'm having no problem burning codes via the IAR embedded toolchain and everything is working fine. However Im having a big issue trying to establish serial communication as i'm unable to specify a port no.

2)To get around this i tried using a USB to RS232 converter via a MAX232 for the voltage conversions. It's picking up garbage value when i try to program it and after that the terminal dosent show anything.

This is the Code ==>>


#include "stm32f10x.h"
#include "stm32f10x_usart.h"


//Structure initialization
GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

void Delay(__IO uint32_t nCount);


int putchar(__IO uint32_t c)
{
while (USART_GetFlagStatus(USART1 , USART_FLAG_TXE) == RESET);
 {   
  USART1->DR = (c & 0xff);
 }
return c;
}


int main(void)
{
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
                         RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOD |
                         RCC_APB2Periph_GPIOE, ENABLE); 
   
 
  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  GPIO_Init(GPIOE, &GPIO_InitStructure);

 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
                         RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOD |
                         RCC_APB2Periph_GPIOE, DISABLE); 
 
  //Clock enable
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |
                         RCC_APB2Periph_GPIOA |
                         RCC_APB2Periph_USART1 |
                         RCC_APB2Periph_AFIO , ENABLE);
 
 
  //LED pin initialization
  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz ;
  GPIO_Init(GPIOC, &GPIO_InitStructure); 
 
  // Button pin initialization
  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  //Tx initialization
  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  //Rx initialization
  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  //USART1 initialization
  USART_StructInit (& USART_InitStructure);
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;  //Word Length = 8 Bits
  USART_InitStructure.USART_StopBits = USART_StopBits_1;  //Two Stop Bit
  USART_InitStructure.USART_Parity = USART_Parity_No ;   //No parity
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
 
  USART_Init(USART1 ,& USART_InitStructure);
  USART_Cmd(USART1 , ENABLE);
 
 int a;
  while (1)
  {


 putchar(a);
 USART_SendData(USART1,a); //trying both commands but none of them seem to work     
   
  }
}

/**
  * @brief  Inserts a delay time.
  * @param  nCount: specifies the delay time length.
  * @retval None
  */
void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/**
  * @}
  */

/**
  * @}
  */

/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/



 
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf