2011-12-13 08:31 AM
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
2011-12-14 06:53 AM
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?2011-12-14 07:22 AM
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;
2011-12-14 05:09 PM
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.
2011-12-14 10:33 PM
hi clive 1
Much thanks for answering. O.K i try it with a 3V CMos solution.2011-12-15 02:16 AM
Ok
Solved it with a MAX232. Much thanks to Clive 12012-01-02 10:35 AM