cancel
Showing results for 
Search instead for 
Did you mean: 

UART Windows problem.

wsevendays
Associate II
Posted on January 04, 2012 at 13:41

Hello. I have a stm32f103vet6. I see that data goes to PC, but I don't see anything on input in PC.My code for stm32:

&sharpinclude ''stm32F10x.h''

u8 SMS[]=''Hello, my name is STM32F100RB!'';

int main(void)

{

     u32 tmp=0;

     RCC->CR|=RCC_CR_HSEON; // ???????? ????????? HSE.

     while (!(RCC->CR & RCC_CR_HSERDY)) {} // ???????? ?????????? HSE.

     RCC->CFGR &=~RCC_CFGR_SW; // ???????? ???? SW0, SW1.

     RCC->CFGR |= RCC_CFGR_SW_HSE; // ??????? HSE ??? ???????????? SW0=1.

     RCC->APB2ENR|= RCC_APB2ENR_IOPAEN; // ????????? ???????????? ????? A.

     RCC->APB2ENR|= RCC_APB2ENR_AFIOEN; // ???????????? ?????????????? ??????? GPIO.

     RCC->APB2ENR|= RCC_APB2ENR_USART1EN; // ????????? ???????????? USART1.

     GPIOA->CRH |= GPIO_CRH_MODE9; // ????? TX PA.9 - ?? ?????.

     GPIOA->CRH &=~GPIO_CRH_CNF9; GPIOA->CRH |=GPIO_CRH_CNF9_1; // ?????????????? ?????.

     USART1->CR1 |=(USART_CR1_RE | USART_CR1_TE); // ????????? ?????? RX, TX - PA10, PA9.

     // ???????? 115.2 kbps. USARTDIV=FSYS/(16*baud) = 8e6/(16*115200) = 4,34.

     USART1->BRR=(4<<4); // ????? ????? ???????????? ??????? USART1.

     USART1->BRR|=5; // ??????? ?????*16 = 0,34*16 = 5 (???).

     USART1->CR1 |=USART_CR1_UE; // ????????? USART1.

     while (SMS[tmp]) // ???? ?? ????? ??????...

     {

          while (!(USART1->SR & USART_SR_TXE)) {} // ????? ???????????? ??????.

          USART1->DR=SMS[tmp]; tmp++; // ????????? ????.

     }

     int i=0;

     while (1)

     {

    delay(200000);

    while (SMS[tmp]) // ???? ?? ????? ??????...

        {

             while (!(USART1->SR & USART_SR_TXE)) {} // ????? ???????????? ??????.

             USART1->DR=SMS[tmp]; tmp++; // ????????? ????.

        }

    tmp=0;

     }

}

void delay(__IO uint32_t nCount)

{

  for(; nCount!= 0;nCount--);

}

#stm32 #serial #uart #stm32vet6
4 REPLIES 4
Posted on January 04, 2012 at 21:17

Instead of ''int i = 0;'' you need ''tmp = 0;''

You might consider using ''USART1->BRR = (8000000 / 115200);''

The code otherwise seems to work, so consider for a minute how you have the USART connected to the PC. The STM32 generates CMOS 3V Serial signalling, This is NOT compatible with RS232 signalling used by the PC. You need buffering circuitry.

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

Thanks for the reply. I'm use PL2303HX USB to TTL Converter Module. I tried to read data in PuTTY and Realterm, but a console has been empty when STM32 board sends data.

Posted on January 05, 2012 at 00:51

Then consider how you have it wired, that you have a ground, and the TX of the STM32 goes to the RXD of the receiving device.

Stick a scope on it if you need to confirm the bit/baud rate. If you suspect the 8MHz HSE, then skip that and use the 8MHz HSI which brings the STM32 up.

Code has been tested on a VL-Discovery with a CMOS Serial to USB converter, and works at 115200 8N1
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
wsevendays
Associate II
Posted on January 05, 2012 at 10:07

Thank you very much! You are help me as no one before! The problem is in how I wired it. I connected it GND->GND, TXD->TX, RXD->RX, 5v->VCC, but as you said I had to replace RXD with TXD.