cancel
Showing results for 
Search instead for 
Did you mean: 

USART Problems

luis239955
Associate II
Posted on October 26, 2012 at 10:57

Hi Guys,

Been trying to get the USART to work for a couple of days now and is time to get some help... This is my code:

GPIO_InitTypeDef GPIO_InitStructure; 
USART_InitTypeDef USART_InitStructure;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured, 
this is done through SystemInit() function which is called from startup
file (startup_stm32f4xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f4xx.c file
*/ 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2); 
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2); 
/* GPIO Pins configuration for Alternative Function */
/* for TX Pin */ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; 
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* for RX Pin */ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
GPIO_Init(GPIOD, &GPIO_InitStructure); 
/* USARTx configured as follow:
- BaudRate = 115200 baud 
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
/* Output a message on Hyperterminal using printf function */
//printf(''\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r'');
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
//RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
USART_Cmd(USART2,ENABLE);
USART_SendData(USART2, (uint8_t) 0x31);
while (1)
{
}
}

I tried pretty much all the USARTs on the board and I can not send anything. I looped back the TX & RX pins on my USB to Serial converter and that works fine. The processor seems to be cycling fine thorough the code when on Debug. I am complety at a loss why the program will not work, Any assistance would be appreciated. Best Regards Luis
28 REPLIES 28
Posted on April 12, 2013 at 22:16

Without connecting Vcc(pin 2)???

Why would I connect it? Do you plan on running the STM32F4-Discovery from this supply? USBPWR might be more appropriate for that.

The data sheet for the part doesn't suggest this is necessary for the configuration used here (USB Powered, 3V3 signalling), please review.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamedgl2003
Associate II
Posted on April 12, 2013 at 22:30

as usual you are always right ....

thank you Mr clive 1.

mohamedgl2003
Associate II
Posted on April 17, 2013 at 18:53

when I connect my MM232R my pc (windows 7) I  can t find   any new hardware detected to install the driver!!!!

Posted on April 17, 2013 at 19:10

Does it appear in Device Manager under Ports (COM & LPT)?

Does it make the ding-dong noise in Windows when you plug it in?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamedgl2003
Associate II
Posted on April 17, 2013 at 20:46

no...as if I have nothing connected.

mohamedgl2003
Associate II
Posted on April 17, 2013 at 21:09

i will try with an other PC....if i find it in Port(com LPT) what can i do to install my mm232r??,

Posted on April 17, 2013 at 21:20

I guess you can re-read the manual and see if I missed something. I'm not a user of this device.

You could stick a multi-meter between USBPWR and GND and confirm it's powered.

I'm using other, simpler, USB-to-Serial adapters.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamedgl2003
Associate II
Posted on April 17, 2013 at 23:03

ok....thank you.

mohamedgl2003
Associate II
Posted on April 18, 2013 at 00:22

Some hubs and host controllers appear to be extremely sensitive to noise.  A glitch on the USB lines can causes the device to hang.  This problem can be fixed by adding two 47pF capacitors to ground on the USB DP and DM lines.  These should be located between the 27Ohm series resistors and the hub.

i find this in 

http://www.ftdichip.com/

 but how can i connect the capacitor to the usb DM and DP lines of the PC.??

Posted on April 18, 2013 at 02:50

Solder them on the back of the connectors, or splice into the cable?

Some how I doubt this is your issue, double check the connections on your MMR board, get a meter and track down what is, and what is not working. The connection of USBPWR and VCC50 being the most critical.

Use shorter cables, and don't use a hub, if you think that is a reasonable test to eliminate those as an issue. The capacitors seem like a straw clutching exercise, more targeted at people using the FTDI chips on there own boards, not on a module designed to work out of the box.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..