2020-01-26 15:27:06 +01:00
|
|
|
/*
|
|
|
|
* uart.c
|
|
|
|
*
|
|
|
|
* Created on: Dec 15, 2014
|
|
|
|
* Author: shino-chan
|
|
|
|
*/
|
|
|
|
//USART2
|
|
|
|
//PA2 => TX
|
|
|
|
//PA3 => RX
|
|
|
|
//Alternate Function 7
|
2020-02-02 00:01:08 +01:00
|
|
|
#include <uart/uart.h>
|
2020-01-26 15:27:06 +01: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);
|
|
|
|
}
|
|
|
|
}
|