cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 USART synchronous Mode

adeli_mohsen
Associate
Posted on February 20, 2013 at 11:31

hello

I want to use synchronous mode Usart But I'm totally confused When I activate the clock I can not determine if Master or Slave? Please help Me

USART_InitTypeDef USART_InitStruct; 
GPIO_InitTypeDef GPIO_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
//----------------------------------------------------------------------- 
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA ,ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2 , ENABLE );
//---------Configure USART1 Tx (PA.09) as alternate function push-pull
// GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_KeyBoard_TXD ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_KeyBoard, &GPIO_InitStructure);
//------------------------------------------------------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_KeyBoard_SCK ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_KeyBoard, &GPIO_InitStructure);
//------------------------------------------------------------------------ 
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_KeyBoard_RXD;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_KeyBoard, &GPIO_InitStructure);
// ---------------------------------------------------------------------- 
/* USART_InitStruct members default value */
USART_InitStruct.USART_BaudRate = 9600;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity =USART_Parity_No ;//USART_Parity_No;// USART_Parity_Odd ;
USART_InitStruct.USART_Mode = USART_Mode_Tx ;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_ClockStructInit(&USART_ClockInitStructure);
//------------------------------------------------------------------------- 
USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
//-------------------------------------------------------------------------
USART_ClockInit(USART2, &USART_ClockInitStructure);
USART_Init(USART2, &USART_InitStruct);/* Configure the USART2 */
USART_Cmd(USART2,ENABLE); /* Enable the USART2 */
USART_ITConfig(USART2, USART_IT_RXNE , ENABLE);/* Enable USART2 interrupt */
NVIC_Configuration_Usart2();

3 REPLIES 3
Posted on February 20, 2013 at 12:09

The USART in synchronous mode is master only.

You don't mention which part, so e.g. RM0090 for 'F4 says in 26.3.9:

The USART allows the user to control a bidirectional synchronous serial communications in

master mode. The SCLK pin is the output of the USART transmitter clock.

JW
adeli_mohsen
Associate
Posted on February 20, 2013 at 12:35

 0690X00000602ndQAA.jpg

I want to connect Ps2 keyboard To STM32F103

From which protocol should I use?

Posted on February 20, 2013 at 16:17

Doesn't look compatible with any STM32 peripheral.

Bit bang, use Google?

http://hackaday.com/2010/11/08/czech-discovery-ressurects-ps2-keyboard/

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