Skip to content
Snippets Groups Projects
Commit 2f5604f9 authored by Jake Read's avatar Jake Read
Browse files

UART Basics

parent 37852b60
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -35,6 +35,8 @@ pin_t stlb;
pin_t stlr;
pin_t button;
pin_t p3lr;
int main (void)
{
/* Insert system clock initialization code here (sysclk_init()). */
......@@ -45,6 +47,9 @@ int main (void)
PMC->PMC_PCER0 = 1 << ID_PIOA;
PMC->PMC_PCER0 = 1 << ID_PIOD;
p3lr = pin_new(PIOD, PIO_PER_P10);
pin_output(p3lr);
stlb = pin_new(PIOA, PIO_PER_P1);
pin_output(stlb);
......@@ -54,13 +59,33 @@ int main (void)
button = pin_new(PIOA, PIO_PER_P15);
pin_input(button);
PMC->PMC_PCER1 = 1 << 14; // UART4 go clock go
PIOD->PIO_PDR = PIO_PER_P18;
PIOD->PIO_PDR = PIO_PER_P19;
PIOD->PIO_ABCDSR[0] = ~PIO_PER_P18;
PIOD->PIO_ABCDSR[0] = ~PIO_PER_P19;
PIOD->PIO_ABCDSR[1] = PIO_PER_P18;
PIOD->PIO_ABCDSR[1] = PIO_PER_P19;
UART4->UART_MR = UART_MR_BRSRCCK_PERIPH_CLK | UART_MR_CHMODE_NORMAL;
UART4->UART_BRGR = 32; // clock / this value * 16
UART4->UART_CR = UART_CR_TXEN | UART_CR_RXEN;
while(1){
if(pin_get_state(button)){
if(pin_get_state(button)){ // hi, button is not pressed
pin_clear(stlb);
pin_set(stlr);
while(!(UART4->UART_SR & UART_SR_TXRDY)){ // wait for ready
pin_clear(p3lr);
}
pin_set(p3lr);
UART4->UART_THR = 85;
} else {
pin_set(stlb);
pin_clear(stlr);
pin_set(p3lr);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment