2014-08-22 08:09 AM
Hello everybody!
It's not my first experience with USART but this time I have an unsolvable problem :) I try to use USART1 TX with the pin PA9 but I can't send datas. The pin PA9 always outputs 1.1V and never switch. When I configure the pin as a standard GPIO, I can set it to high and low level (0V and 3.3V) without problems. I think this is maybe due to the fact I use the USB and the pin PA9 can be used as the VUSB input. This my code for the USART1 config:void
USART_Config(
void)
{ RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1 clockRCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
// GPIOA clockGPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
// PIN A9 linked to the USART1// Tx GPIO init
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // alternate function!GPIO_InitStructure.GPIO_OType = GPIO_OType_OD ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); // USART init: // Vitesse du MIDI = 31250 USART_InitStructure.USART_BaudRate = 31250; 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_Tx; USART_Init(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE); } Then to send a data I simply useUSART_SendData(USART1, data_out);
Thanks a lot for your help! #rtfs2014-08-22 08:56 AM
hi, try to configure the IO as Push-Pull (not Open-drain + pull-up).
2014-08-22 09:50 AM
Hi Laurent ! Thanks for this tip. Now the PA9 always outputs 3.3V, no switches...
2014-08-22 10:36 AM
> RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
// USART1 clock
So, is it APB1 or APB2?
JW
2014-08-22 10:51 AM
On the STM32F4-DISCO there is a very large bulk capacitor on PA9, you'd have to removed that for it to be usable. Suggest if you must use USART1, pick some alternate pins.
2014-08-22 10:55 AM
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00039084.pdf
.2014-08-25 02:48 AM
Hello!
1) Sorry it was a post mistake forRCC_APB1PeriphClockCmd
, the true line isRCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
2) I'm not on STM32 discovery but on my own board, PA9 is a free pin. The alternate pin for USART TX is not free, so I have to find a solution with PA9.When I don't config the USB (to more precise when I don't call the lineUSBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &MIDI_cb, &USR_cb);
)
my USART PA9 pin works! I can send USART messages...This is strange because when I check the USB libraries the PA9 pin is not used. Do you have any idea of how to ''disconnect'' PA9 and USB?Thanks a lot!2014-08-26 02:12 AM
I'm a little disturbed because when I search in my workspace ''GPIO_Pin_9'' or ''GPIO_PinSource9'' I have no results, excepted my declarations for USART PA9. I don't understand where and why the USB configure the PA9 pin...
Otherwise, when I init the USB with USB_OTG_CORE_ID_TypeDef =USB_OTG_FS_CORE_ID
The USART PA9 doesn't work, but my USB works fine.When I init the USB with USB_OTG_CORE_ID_TypeDef =USB_OTG_HS_CORE_ID
The USART PA9 works, but my computer doesn't recognize the peripherial.I Hope it can help!2014-08-27 05:25 AM
Is my problem linked to this note from ST on this AN page 28? http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/CD00167594.pdf
''PA9 excessive power consumption when USB cable is pluggedin bootloader V2.0 DescriptionWhen connecting an USB cable after booting from System-Memory mode, PA9 pin (connected to VBUS=5 V) is also shared with USART TX pin which is configured as alternate push-pull and forced to 0 since the USART peripheral is not yet clocked. As a consequence, a current higher than 25 mA is drained by PA9 I/O and may affect the I/O pad reliability. This limitation is fixed in bootloader version 2.1 by configuring PA9 as alternate function push-pull when a correct 0x7F is received on RX pin and the USART is clocked. Otherwise, PA9 is configured as alternate input floating. WorkaroundNone. ''