2015-04-26 17:54:51 +02:00
|
|
|
/*
|
|
|
|
* uart.c
|
|
|
|
*
|
|
|
|
* Created on: Dec 15, 2014
|
2015-07-26 07:16:57 +02:00
|
|
|
* Author: Mario Huettel
|
2015-04-26 17:54:51 +02:00
|
|
|
*/
|
|
|
|
//USART2
|
|
|
|
//PA2 => TX
|
|
|
|
//PA3 => RX
|
|
|
|
//Alternate Function 7
|
2017-03-31 13:25:42 +02:00
|
|
|
#include <uart/uart.h>
|
2015-04-26 17:54:51 +02:00
|
|
|
#include <stm32f4xx.h>
|
|
|
|
|
|
|
|
void initUART() {
|
|
|
|
__DSB();
|
|
|
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
|
|
|
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
|
|
|
|
__DSB();
|
|
|
|
|
|
|
|
GPIOA->MODER |= (1<<5);
|
|
|
|
GPIOA->AFR[0] |= (7<<8); //Enable Clock
|
|
|
|
GPIOA->MODER |= (1<<5);
|
|
|
|
GPIOA->AFR[0] |= (7<<8);
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
USART2->BRR = 0x1117; //Baudrate 273.4375=>0x1117 9600baud bei 42MHz Periph
|
|
|
|
USART2->CR1 = USART_CR1_UE | USART_CR1_TE;
|
|
|
|
|
|
|
|
}
|
|
|
|
void sendChar(char c) {
|
|
|
|
while(!(USART2->SR & USART_SR_TXE));
|
|
|
|
USART2->DR = c;
|
|
|
|
|
|
|
|
}
|
|
|
|
void sendString(char* s, int count) {
|
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < count; i++,s++)
|
|
|
|
{
|
|
|
|
if (!(*s))
|
|
|
|
break;
|
|
|
|
sendChar(*s);
|
|
|
|
}
|
|
|
|
}
|