More Related Content
Similar to Lecture 3.pptx (20)
More from GautamDhargalkar1 (7)
Lecture 3.pptx
- 10. Fractional baud rate generation
Example:
• BAUDRATE = 19200
• APBx_FREQ = 42000000
//define APBx frequency
#define APBx_FREQ 42000000
//define UART Baudrate
#define BAUDRATE 19200
//In main function set UART baudrate
USARTx->BRR = APBx_FREQ/BAUDRATE
- 18. Enabling Interrupt
//Create USART2 Interrupt Handler
void USART2_IRQHandler(void)
{
//Some actions
}
int main()
{ RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
USART2->BRR = APB1/USART_BAUDRATE;
USART2->CR1 = USART_CR1_UE | //Enable UART
USART_CR1_TE | //Enable Transmitter
USART_CR1_RE | //Enable Receiver
USART_CR1_RXNEIE; //Enable interrupt in peripheral
NVIC_EnableIRQ(USART2_IRQn); //Enable Global interrupt
}