Created
November 20, 2016 08:24
-
-
Save AlexanderSavochkin/179f2f150f270b6c718eeff0027d0a6e to your computer and use it in GitHub Desktop.
Example of sam3x8e UART initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setupUART() | |
{ | |
PIO_Configure(PIOA, PIO_PERIPH_A,PIO_PA8A_URXD|PIO_PA9A_UTXD, PIO_DEFAULT); | |
/* Enable the pull up on the Rx and Tx pin */ | |
PIOA->PIO_PUER = PIO_PA8A_URXD | PIO_PA9A_UTXD; | |
/*Включаем UART, подавая на него тактирование*/ | |
pmc_enable_periph_clk(ID_UART); | |
/* Отключаем DMA для приёма и для передачи */ | |
UART->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS; | |
// Reset and disable receiver and transmitter | |
UART->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS; | |
// Configure mode | |
uint32_t dwMode = US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_NO; | |
uint32_t modeReg = dwMode & 0x00000E00; | |
UART->UART_MR = modeReg; | |
// Configure baudrate (asynchronous, no oversampling) | |
uint32_t dwBaudRate = 9600; | |
UART->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4; | |
/*Конфигурируем прерывания*/ | |
/*Отключаем их*/ | |
UART->UART_IDR = 0xFFFFFFFF; | |
/*Включаем нужные нам прерывания. Если работаем с портом через поллинг, то | |
включать прерывания не нужно*/ | |
#ifndef USE_POLLING | |
UART->UART_IER = UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME; | |
#endif | |
NVIC_EnableIRQ(UART_IRQn); | |
/*Включаем передачу и приём*/ | |
UART->UART_CR = UART_CR_RXEN | UART_CR_TXEN; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[email protected]