cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8 USART3 problems

booster3000
Associate II
Posted on August 17, 2011 at 04:27

Hello there, i am having problems setting up USART3 on my STM32f103c8t6 chip. there seems to be nothing wrong with the code, but the tx pin does not seem to be functioning at all.

I have tried my code on a STM32f103rb chip on a development board using the exact same settings (except selecting ''STM32f103RB'' as device as oppose to using ''STM32f103C8'') and using a oscilliscope to check if anything is happening on the Tx pin. 

So far, on the STM32f103RB chip, i am able to see signals being generated, however i can't see any changes on the STM32f103C8 chip.  I know that the C8 chip is working and that the USART3 is working (on a precompiled hex file, so i don't have the source code) and i have tried on a few of the same boards with same chips.

any feedback would be appreciated. thanks

Specs are:

-programming using Keil uVision 4.14

-using ST-Link utility to communicate

-Windows 7

Source Code:

================================

/* Includes ------------------------------------------------------------------*/

#include ''stm32f10x_lib.h''

#include ''platform_config.h''

typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;

USART_InitTypeDef USART_InitStructure;

TestStatus TransferStatus = FAILED;  

ErrorStatus HSEStartUpStatus;

void RCC_Configuration(void);

void GPIO_Configuration(void);

void NVIC_Configuration(void);

  

int main(void)

{

  RCC_Configuration();

  NVIC_Configuration();

  GPIO_Configuration();

  USART_InitStructure.USART_BaudRate = 1200;

  USART_InitStructure.USART_WordLength = USART_WordLength_8b;

  USART_InitStructure.USART_StopBits = USART_StopBits_1;

  USART_InitStructure.USART_Parity = USART_Parity_Odd;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  USART_Init(USART3, &USART_InitStructure);

  USART_Cmd(USART3, ENABLE);

  while(1)

  {   

    USART_SendData(USART3, 0xDD);

    

  }

  

}

void RCC_Configuration(void)

{

  RCC_DeInit();

  RCC_HSEConfig(RCC_HSE_ON);

  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if(HSEStartUpStatus == SUCCESS)

  {

    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    FLASH_SetLatency(FLASH_Latency_2);

    RCC_HCLKConfig(RCC_SYSCLK_Div1); 

    RCC_PCLK2Config(RCC_HCLK_Div1); 

    RCC_PCLK1Config(RCC_HCLK_Div2);

    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    RCC_PLLCmd(ENABLE);

    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)

    {

    }

    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    while(RCC_GetSYSCLKSource() != 0x08)

    {

    }

  }

   

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

}

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

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

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

}

void NVIC_Configuration(void)

{  

  NVIC_InitTypeDef NVIC_InitStructure;

#ifdef  VECT_TAB_RAM  

  /* Set the Vector Table base location at 0x20000000 */ 

  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 

#else  /* VECT_TAB_FLASH  */

  /* Set the Vector Table base location at 0x08000000 */ 

  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   

#endif

    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

}

10 REPLIES 10
John F.
Senior
Posted on August 17, 2011 at 09:19

Do you have a line,

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

after USART_SendData?

Otherwise you are not allowing time for the data to be sent before reloading the USART data register.

booster3000
Associate II
Posted on August 17, 2011 at 10:35

thanks for that, but my problem isn't actually with the data not getting through, more like the Tx pin isn't going to 'high'. I checked it out with a osciliscope on the RB chip and the output provides a repeated pattern of waves, but on the C8 chip my output remained 0 regardless of the infinite loop of senddata

John F.
Senior
Posted on August 17, 2011 at 11:45

Hardware fault? Test if the pin state can be changed using it as an ordinary GPIO pin.

booster3000
Associate II
Posted on August 17, 2011 at 11:58

I thought that too, the board is a custom board and with the firmware it is able to work fine, so the pin itself doesn't seem to be faulty. however i have tried to set it to a general push-pull output and setting it to 'high' but that doesn't seem to work either.

Posted on August 17, 2011 at 14:17

So this specific chip/board, and USART3, works with different software loaded?

What hardware is attached to the serial port pins, could it be conflicting with the serial port pin drivers? Or wired backward. Try the previous suggestion of using it as a GPIO, and toggle it up/down. If that doesn't work, observe the current drawn, and remove downstream circuitry, or lift the pin/pad.

You might also want to confirm the memory sizes in the device, you can look in the back-end of the ROM. There are variants of the STM32F103 family with only TWO USARTs, the part could be mis-marked.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
booster3000
Associate II
Posted on August 18, 2011 at 00:53

yes, the USART3 works with a software that was made for this board

at the moment i am just testing the pin, so the only hardware would be either a multimeter or a osciliscope at times, so there isnt any downstream circuitry at the moment

I have tried a modified code code (see below) and I have set both GPIOB 10 and 11 to be push-pull outputs, only pin 11 seems to respond and change to 'high', and im connecting to the pin directly with the multimeter pin so i don't think raising the pin will change anything

and im almost positive that the chip is correct, USART3 does work with the software that came with (sadly, no source code, only a compiled binary file)

code:

================

/* Includes ------------------------------------------------------------------*/

#include ''stm32f10x_lib.h''

#include ''platform_config.h''

typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;

USART_InitTypeDef USART_InitStructure;

TestStatus TransferStatus = FAILED;  

ErrorStatus HSEStartUpStatus;

void RCC_Configuration(void);

void GPIO_Configuration(void);

void NVIC_Configuration(void);

int main(void)

{

  RCC_Configuration();

  NVIC_Configuration();

  GPIO_Configuration();

  while(1)

  {   

 GPIOB->BSRR = 1<<10;

 GPIOB->BSRR = 1<<11;

     // GPIOB->ODR = 0xFFFF;

  }

  

}

void RCC_Configuration(void)

{

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

}

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

}

void NVIC_Configuration(void)

{  

#ifdef  VECT_TAB_RAM  

  /* Set the Vector Table base location at 0x20000000 */ 

  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 

#else  /* VECT_TAB_FLASH  */

  /* Set the Vector Table base location at 0x08000000 */ 

  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   

#endif

}

John F.
Senior
Posted on August 18, 2011 at 09:16

John F.
Senior
Posted on August 18, 2011 at 09:24

Device is a 48 pin LQFP.

USART2 is on pins 10 11

You are looking at the wrong pins or the wrong USART.

raptorhal2
Lead
Posted on August 18, 2011 at 15:44

I have USART3 working on a 103C8 using PB10 and PB11. Perhaps the Init Structures aren't initialized like you assumed. Try adding the following:

USART_InitStructure.USART_Clock = USART_Clock_Disable;

USART_InitStructure.USART_CPOL = USART_CPOL_Low;

USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;

USART_InitStructure.USART_LastBit = USART_LastBit_Disable;

Also, try setting the NVIC Preemption Priority to 0.

If none of this works, get the most nit-picking, critical colleague you can find and get him or her to review the code and board setup.

Cheers, Hal