AnsweredAssumed Answered

Discovery Kit STM32f0308 - USART QUESTION

Question asked by Lesueur.Rick on Jan 17, 2014
Latest reply on Jan 17, 2014 by Clive One
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_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 */
  /* 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.