cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F373 USART2 Problem

fslhusni
Associate II
Posted on May 11, 2015 at 13:14

Hello, I have some problem with USART2 (stm32f373). USART1 is working with same code but, Usart2 does not work.  here is the code.

void Uart_Int(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  USART_InitTypeDef USART_InitStructure;

  USART_ClockInitTypeDef USART_ClockInitStructure;

 

  USART_ClockStructInit(&USART_ClockInitStructure);

  USART_ClockInit(USART2, &USART_ClockInitStructure);

 

 

  RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

 

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);

 

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_7);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_7);

 

 

  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_InitStructure.GPIO_Pin = GPIO_Pin_2;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

 

 

  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_InitStructure.GPIO_Pin = GPIO_Pin_3;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

 

  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);

  USART_Cmd(USART2, ENABLE); /**/

  }

int main(void)

{

   unsigned char data=0;

    Uart_Int();

 

     //

    while(1)

    {

         

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

  USART_SendData( USART2, 'a');

     

  }

 }

what kind of problem it has.....?

7 REPLIES 7
Posted on May 11, 2015 at 13:27

RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); // APB1 APB1 - Fix This

You can also lose the USART_Clock stuff, it doesn't do anything, isn't needed, and it is in the wrong spot.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fslhusni
Associate II
Posted on June 20, 2015 at 13:17

Thank you so much clive1, problem solved.

fslhusni
Associate II
Posted on June 20, 2015 at 13:48

Dear Clive1, Now i am using STM32f0 discovery board,(stm32f051r), i want to transmitte and receive Uart1 data over DMA, if i used Circular mode then any character received through uart1 send continuously, and if  i used normal mode then nothing happen. no data receive or transmite, here is my code.

#include ''main.h''

uint8_t AckBuffer [0x02] = {0x00, 0x00};

static void USART_Config(void);

DMA_InitTypeDef DMA_InitStructure;

int main(void)

{

 

 

  USART_Config();

 

   

    //----------------

    

      DMA_DeInit(DMA1_Channel3);

      DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART1->RDR;//USARTx_TDR_ADDRESS;//

      DMA_InitStructure.DMA_BufferSize = (uint16_t)1;

      DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)AckBuffer;

      DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

      DMA_InitStructure.DMA_Priority = DMA_Priority_High;

      DMA_Init(DMA1_Channel3, &DMA_InitStructure);

      

 

      DMA_DeInit(DMA1_Channel2);

      DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t)&USART1->TDR; //USARTx_TDR_ADDRESS;//

      DMA_InitStructure.DMA_BufferSize = (uint16_t)1;

      DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)AckBuffer;

      DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;

      DMA_InitStructure.DMA_Priority = DMA_Priority_High;

      DMA_Init(DMA1_Channel2, &DMA_InitStructure);

      

      

      

      USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);

      USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);

      

      DMA_Cmd(DMA1_Channel2, ENABLE);

      DMA_Cmd(DMA1_Channel3, ENABLE);

      

      

      

      

      USART_ClearFlag(USART1, USART_FLAG_TC);

      DMA_ClearFlag(DMA1_FLAG_GL2);

      DMA_ClearFlag(DMA1_FLAG_GL3);

    

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

    USART_SendData( USART1, 'F');

    //------------------

 

  while (1)

  {}

 

}

static void USART_Config(void)

{

  USART_InitTypeDef USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

 

 

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOA, ENABLE);

  USARTx_APBPERIPHCLOCK(RCC_APB2Periph_USART1, ENABLE);

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

 

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

 

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

 

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

 

  USART_InitStructure.USART_BaudRate = 115200;

  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(USARTx, &USART_InitStructure);

 

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;//Enable;

  DMA_InitStructure.DMA_Mode =DMA_Mode_Circular; //DMA_Mode_Normal;//

  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

    

  USART_Cmd(USARTx, ENABLE);

}

#ifdef  USE_FULL_ASSERT

void assert_failed(uint8_t* file, uint32_t line)

{

  /* Infinite loop */

  while (1)

  {

  }

}

#endif

fslhusni
Associate II
Posted on June 21, 2015 at 15:55

Posted on June 21, 2015 at 16:16

Not sure I see the value of single byte DMA.

In normal mode you'd need to reconfigure the DMA after each byte is sent or received. I don't see any code managing that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fslhusni
Associate II
Posted on June 21, 2015 at 20:38

Posted on June 22, 2015 at 01:43

Watch that you top post responses, and avoid using phone/tablet devices which don't' work well with this Microsoft ''forum'' software.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..