cancel
Showing results for 
Search instead for 
Did you mean: 

SMT32VL-Discovery UART

bandido1
Associate II
Posted on December 13, 2011 at 17:31

Hi all

I try to success a connection between PC and SMT32VL-Discovery Board via USART. The Data receive but are not correct. I tryed everything, but the data i receive onPC are still wrong. Has anyone any idea?


GPIO_InitTypeDef GPIO_InitStructure; 

USART_InitTypeDef USART_InitStructure; 

USART_ClockInitTypeDef USART_ClockInitStructure; 

//enable bus clocks 

SystemInit(); 

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); 

//Set USART1 Tx (PA.09) as AF push-pull 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; 

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 

GPIO_Init(GPIOA, &GPIO_InitStructure); 

//Set USART1 Rx (PA.10) as input floating 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; 

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 

GPIO_Init(GPIOA, &GPIO_InitStructure); 

USART_ClockStructInit(&USART_ClockInitStructure); 

USART_ClockInit(USART1, &USART_ClockInitStructure); 

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_Mode = USART_Mode_Rx | USART_Mode_Tx; 

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 

//Write USART1 parameters 

USART_Init(USART1, &USART_InitStructure); 

//Enable USART1 

uint8_t ch = 0x53; 

USART_Cmd(USART1, ENABLE); 

uint16_t test = 0x0000; 

for
(i = 0; i < 100; i++) 

{ 

USART_SendData(USART1, ch); 

while
(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) 

{ 

} 

}

#uart #smt32vl-discovery
6 REPLIES 6
Posted on December 14, 2011 at 15:53

Looks reasonable enough, wouldn't bother with the ClockInit stuff. The SystemInit() function should be called prior to main() in the start up code, no need to call it again.

How's it not working? You get some characters, none, the wrong ones?

Check the data signal with a scope, measure the bit times.

How is it wired up?

What clock speeds are set up for the CPU, AHB, APB1, APB2?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bandido1
Associate II
Posted on December 14, 2011 at 16:22

Hi clive 1

Thank you for answer.

I send 0x53 (hex) and receive 0x25 (hex).

I connected the PC over uart (GND, TX and RX without handshake and without flowcontroll).

The function setSystemClockTo24() sets:

/* HCLK = SYSCLK */

RCC->

CFGR

|= (

uint32_t

)RCC_CFGR_HPRE_DIV1;

/* PCLK2 = HCLK */

RCC->

CFGR

|= (

uint32_t

)RCC_CFGR_PPRE2_DIV1;

/* PCLK1 = HCLK */

RCC->

CFGR

|= (

uint32_t

)RCC_CFGR_PPRE1_DIV1;

Posted on December 15, 2011 at 02:09

I connected the PC over uart (GND, TX and RX without handshake and without flowcontroll).

 

Sorry, that's still a bit vague, you'd need to connect it to something that is expecting 3V CMOS signalling, which RS232 is not. So hooking it up directly to a DB9 won't work. You'd either need an RS232 conversion buffer, or hook it up to a USB-to-USART type device expecting CMOS/TTL type signalling.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bandido1
Associate II
Posted on December 15, 2011 at 07:33

hi clive 1

Much thanks for answering.

O.K i try it with a 3V CMos solution. 

bandido1
Associate II
Posted on December 15, 2011 at 11:16

Ok

Solved it with a MAX232.

Much thanks to Clive 1

hernandez_nava_itt
Associate II
Posted on January 02, 2012 at 19:35

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6hv&d=%2Fa%2F0X0000000bth%2FD7mdW8p6E4KL4YK1mx2YIr7a9cjW7d68WfjSbi2HMJc&asPdf=false