cancel
Showing results for 
Search instead for 
Did you mean: 

Discovery Kit STM32f0308 - USART QUESTION

vendor
Associate II
Posted on January 17, 2014 at 16:40

Please help,

I am able to transmit on USART1 okay. They receive does not appear to be working.

I am using the provided discovery code, with the following USART Setup- (I modified this slightly from the half-duplex code as I am simply attempting to send a byte at a time, then receive a response.  

void USART1_Configure(void)

{

   RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);

   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

   

  // Configure USART1 pins:  Rx and Tx

    

    USART_InitTypeDef USART_InitStructure;

    GPIO_InitTypeDef GPIO_InitStructure;

    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9 | GPIO_Pin_10;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;         

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); 

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); // IS THIS CORRECT for full duplex? 

   

    GPIO_Init(GPIOA, &GPIO_InitStructure); // Commit Changes

    

    USART_InitStructure.USART_BaudRate = 9600; //?? Demo code requests BAUD in Integer format, correct ?  

    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;

In full duplex mode do you have to configure the USART for send, then change to receive mode?  It appears that what I Tx is in the Rx register. With the DEMO software, the desired BAUD rate is set as an integer (this is the default), but comments have a formula. How can the actual baud rate be measured? 

Sample code is like 

USART_SendData(USART1, 0xAA);

Rx= USART_ReceiveData(USART1);

uint16_t USART_ReceiveData(USART_TypeDef* USARTx)

{

  /* Check the parameters */

  assert_param(IS_USART_ALL_PERIPH(USARTx));

  

  /* Receive Data */

  return (uint16_t)(USARTx->RDR & (uint16_t)0x01FF);

Note I have not yet implemented DMA for the USART this may simply be an issue of missing data... I wanted to Tx / Rx byte to check interface before implemented DMA or  interrupt routines. I am also a bit confused, the routines provided use uint16_t while only a byte (unsigned char) is sent, that is okay if the uint16_t datasent is =< 0xFF but will be truncated if larger, right?

I thank you in advance for any assistance you can provide.  

#stm32f0308 #discovery #usart
1 REPLY 1
Posted on January 17, 2014 at 17:23

http://www.st.com/web/en/catalog/tools/PF259100

I only have the original F051 DISCO

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/UART%20example%20code%20for%20STM32F0&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=8341]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FUART%20example%20code%20for%20STM32F0&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=8341

It's uses a 16-bit integer because the 9-bit mode won't fit in 8-bits, so yes in 8-bit mode it truncates to 8-bits across the wire.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..