cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f107vc usart

michaelscott2509
Associate II
Posted on January 23, 2012 at 17:49

Hi,

I am trying to get the usart to work on the olimex stm32-p107 board. I setup the GPIO ports and USART, but cannot seem to send, or receive any data. Has anyone has this problem? or any ideas? 

Here is my code: RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );

/* Enable USART3 clock */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

/* Configure USART Tx as alternate function push-pull */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOB, &GPIO_InitStructure);

/* Configure USART Rx as input floating */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOB, &GPIO_InitStructure);

/* Remap USART, as USART3 is used as alternate pins */

//GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE);

/* Configure USART 9600 8N1 */

USART_DeInit(USART3);

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_Tx;// | USART_Mode_Rx;

USART_InitStructure.USART_Clock = USART_Clock_Enable;

USART_InitStructure.USART_CPOL = USART_CPOL_Low;

USART_InitStructure.USART_CPHA = USART_CPHA_1Edge;

USART_InitStructure.USART_LastBit = USART_LastBit_Enable;

USART_Init(USART3, &USART_InitStructure);

/* Enable USART3 */

  USART_Cmd(USART3, ENABLE);

/* Send some test data */

while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);

  USART_SendData(USART3, (u8) 'T');

while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);

USART_SendData(USART3, (u8) 'e');

while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);

USART_SendData(USART3, (u8) 's');

while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);

USART_SendData(USART3, (u8) 't');

#stm32f107-usart
10 REPLIES 10
Posted on January 23, 2012 at 18:30

I am trying to get the usart to work on the olimex stm32-p107 board. I setup the GPIO ports and USART, but cannot seem to send, or receive any data. Has anyone has this problem? or any ideas?

 

To remap you must enable the AFIO clock.

The USART3 PB10/PB11 is the default mapping, the remapped locations would be PD8/PD9, right? In which case you'd need to initialize those pins. If you really want PB10/PB11 then don't remap the USART3 some place else.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelscott2509
Associate II
Posted on January 23, 2012 at 20:15

Thanks for the quick response. 

The AFIO clock is enabled in a section of code before this code. 

I tried using the pins PD8/9 and calling the remap function, but that didn't work either. 

Cheers

Posted on January 23, 2012 at 20:32

Ok, then consider how you are connecting it to whatever. The pins are NOT RS232 compatible, so sticking them directly into a PC won't work, you need a buffer. Consider also the TX/RX connections, that the TX of the STM32 goes to a Receive input of the host.

Consider enabling both the Rx and Tx, and looping them back externally to confirm it is working.

Look at the pins with a scope, confirm that you have the bit rate you want. Perhaps the library code is assuming an 8 MHz external clock? Probably something else on a Connectivity series. Make sure the code and the board are in agreement about what the clock is. Use the HSI as a known alternative.

I'd also lose the clock and last bit stuff for the USART.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 23, 2012 at 20:41

/* Enable GPIOD and Alternate Function Remapping */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE );
/* Enable USART3 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* Configure USART Tx (PD.08) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure USART Rx (PD.09) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Remap USART, as USART3 is used as alternate pins on PD8/9*/
GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE);
/* Configure USART 9600 8N1 */
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_Tx | USART_Mode_Rx;
USART_Init(USART3, &USART_InitStructure);
/* Enable USART3 */
USART_Cmd(USART3, ENABLE);
/* Send some test data */
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, (u16) 'T');
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, (u16) 'e');
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, (u16) 's');
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, (u16) 't');

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelscott2509
Associate II
Posted on January 24, 2012 at 00:24

Thanks for the modified code and suggestions. 

That's where I've been going wrong, I've been trying to test the USART by connecting it to a USB-to-RS232 converter and using minicom.

I would basically be using the USART to print messages to the user, which would be running something like minicom, is this possible? Would it just require the right signals

and buffers to be used?

It looks like the code sets the system up to use the high speed external clock, i'll investigate it a bit more. 

I will investigate with a scope and looping Tx/Rx tomorrow and see what I find.

Posted on January 24, 2012 at 03:44

For RS232 voltages you need a buffer chip like a MAX232 or MAX3232, alternatively you can use a USB adapter that supports CMOS Serial signals directly, like a DLP-TXRX

http://www.dlpdesign.com/usb/txrx.shtml

One piece of advice I will offer is that you should consider using USART1 for your debug/telemetry/user/programming interface. If you are going to add a RS232 serial port hardware to you design, on USART1, you can use this to production program the STM32 in a very cost effective way, with no additional hardware resources or custom interfaces. If you have other serial devices in your design hang them off USART2, 3, etc. If you don't plan to export an RS232 port, then think of providing a header or test points to USART1 so you can attach a programming/debug connection.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelscott2509
Associate II
Posted on January 24, 2012 at 17:14

I'm a bit confused. On the board I'm using (olimex stm32-p107 rev.A) there is a RS232 port, looking at the data sheet, the Tx and Rx pins are connected to USART3. Is only USART1 RS232 compatible, while USART2-5 are not? If they are not then would it be possible to map the USART3 pins to USART1?  Surely they wouldn't connect an RS232 port to a USART not capable of using it fully? 

Posted on January 24, 2012 at 19:52

I'm a bit confused. On the board I'm using (olimex stm32-p107 rev.A) there is a RS232 port, looking at the data sheet, the Tx and Rx pins are connected to USART3. Is only USART1 RS232 compatible, while USART2-5 are not? If they are not then would it be possible to map the USART3 pins to USART1?  Surely they wouldn't connect an RS232 port to a USART not capable of using it fully?

 

connection.

 

None of the STM32 serial ports are capable of signalling with RS232 voltages, period.

The board you cite has an ST3232/MAX3232 to do the conversion to/from CMOS voltage levels used by the STM32 and the RS232 voltage levels.

Rev B uses USART2

Rev A uses USART3 remapped to pins PD8/PD9

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelscott2509
Associate II
Posted on January 24, 2012 at 21:47

Okay, so surely after initialising the UART, GPIO etc, I should be able to send  characters from the UART (like in the example code) and pick them up on a PC with minicom? Or do I need to additional things such as enable hardware flow control, or use additional signals described in the RS232 specification? 

Thanks for all the assistance, I've been researching RS232 a bit, but fairly new to this kind of embedded development.