0% found this document useful (0 votes)
6 views3 pages

Uart Sppu

The document contains C code for initializing and using UART4 on an STM32F407 microcontroller. It includes functions for UART4 initialization, writing characters, and a delay function. The main loop continuously sends a message 'SPPU' over UART4 with a delay between transmissions.

Uploaded by

23112196
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Uart Sppu

The document contains C code for initializing and using UART4 on an STM32F407 microcontroller. It includes functions for UART4 initialization, writing characters, and a delay function. The main loop continuously sends a message 'SPPU' over UART4 with a delay between transmissions.

Uploaded by

23112196
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<stm32f407xx.

h>

#include<stdio.h>

void UART4 init(void);

void UART4 write(uint8_t ch);

void delay(unsigned int t);

int main(void)

char message[]= "SPPU\r\n";

int i;

UART4 init();

while(1)

for(i=0;i<7;i++)

UART4_write(message[i]);

delay(10); /* Leave Gap between Message */

/* Initialization of UART pins */

void UART4_init(void)

RCC->AHB1ENR |=1 //Enable GPIOA clock

RCC->APB1ENR |=0x80000; // Enable UART4 Clock

// configure PAO for UART4 TX

//GPIOA->AFR[0] &=~0x000F
GPIOA->AFR[0] = 0x0008, // alr8 for UART4

GPIOA->MODER &=~0x0003;

GPIOA->MODER |= 0x0002; // Enable alternate function for PAO

GPIOA->OSPEEDR |= 0;

UART4->BRR=0x0683, // 9600 Baud Rate at 16 MHz

UART4->CR1=0x0008; // Enable Tx 8 bit data

UART4->CR2 =0x0000; // 1 stop bit

UART4->CR3 = 0x0000 // no flow control

UART4->CR1 |=0x2000, // Enable UART4

void UART4 write(uint8tch)

UART4->DR = ch;

while(!(UART4->SR & 0x0080))

void delay(unsigned int t)

GPIOA->OSPEEDR |=0

unsigned int i,j;

for(i=0;i<t;i++)

for(j=0;j<2000;j++);

You might also like