2013-10-24 08:54 PM
I'm trying to setup some communications between an STM32L152 series MCU with an ATMEGA The Atmega uses 5V logic high. I read the Datasheet and found that the UART1 RX pin is 5V tolerant on the STM32 so I should be able to take in 5V packets from the Atmega. Here is my GPIO and UART initializaton:
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); // Enable GPIO A bank clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); // Enable USART1 clock
/* Configure Alternate Function pin muxing fabric to escape USART1 Rx and Tx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
/* Configure USART1 pins: Rx and Tx */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 |
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 settings */
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1,ENABLE); // Enable USART1
/* USART1 GPIO Configuration:
PA9 ------> USART1_TX
PA10 ------> USART1_RX */
I just wanted to make sure I had everything setup correctly before I start sending 5V logic to the 3V3 STM
Thanks in advance for any help!
#uart-ft-serial-communications