2010-01-13 06:54 PM
USART1 configuration (register)
2011-05-17 04:37 AM
Hi,
i want to write my own USART1 initialization. The sourcecode is attached below:Code:
void usartSetup (void) { GPIO_InitTypeDef GPIO_InitStructure; RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // enable clock for GPIOA GPIOA->CRH |= (0x0BUL << 4); // Tx (PA9) alt. out push-pull GPIOA->CRH |= (0x04UL << 8); // Rx (PA10) in floating RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // enable clock for USART1 USART1->BRR = 8000000L/9600L; // set baudrate USART1->CR1 |= (USART_CR1_RE | USART_CR1_TE); // RX, TX enable USART1->CR1 |= USART_CR1_UE; // USART enable /* GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); */ } The USART1 initialization only works, if I uncomment the code-block at the end of the subroutine. However, I want to get completely rid off the ST-Library... Does anyone know what I am missing? Thanks, Bernhard2011-05-17 04:37 AM
Hi,
The main difference between your code and library code, is that they clear the configuration bits before doing the |= . So try first to clear GPIOA->CRH register (or at least the PA9 & PA10 configuration bits): GPIOA->CRH &= ~(0x00F0); /* Clear PA9 configuration bits */ GPIOA->CRH |= (0x00B0); /* Set AF Push Pull mode, 50 MHz for PA9 */ GPIOA->CRH &= ~(0x0F00); /* Clear PA10 configuration bits */ GPIOA->CRH |= (0x0400); /* Set Input floating mode for PA10 */ Good luck.2011-05-17 04:37 AM
Hi,
thanks a lot - it worked!2011-05-17 04:37 AM
I'm glad for you :)