STM32F4xx

 I new here and i needImplement a simple program that will print the state of the text keys
HIGH or LOW on the terminal. The UART is configured to 230400 Bauda on the PA2 GPIO pin and the key is
connected to GPIO pin PA0.

I Have done some work already but i dont now if it works.


int main(void)
{
initUSART2(USART2_BAUDRATE_230400);


RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
GPIOA->MODER &= ~0x00000003;
GPIOA->PUPDR |= 0x00000002

while(1)
{

if((GPIOA->IDR & 0x0001) == 0x0001)
printUSART2("HIGH");
else
printUSART2("LOW");   //the print function is for sure correct i have that tested

}
}

void initUSART2(uint32_t baudrate)
{

RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
GPIOA->MODER |= GPIO_MODER_MODER2_1;
GPIOA->AFR[0] |= 0x00000700;

GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR2_1;

USART2->BRR = baudrate;
USART2->CR1 = USART_CR1_UE|USART_CR1_TE;
}

Parents Reply Children
No data
More questions in this forum