start firmware: Function definitions for ADC
This commit is contained in:
44
stm-firmware/uart/uart.c
Normal file
44
stm-firmware/uart/uart.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* uart.c
|
||||
*
|
||||
* Created on: Dec 15, 2014
|
||||
* Author: shino-chan
|
||||
*/
|
||||
//USART2
|
||||
//PA2 => TX
|
||||
//PA3 => RX
|
||||
//Alternate Function 7
|
||||
#include <uart/uart.h>
|
||||
#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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user