Skip to main content
JS.13
Associate
May 24, 2019
Solved

Hello friends, I am trying to get UART1 output from STM32F767 using Keil, There is no output showing in the Serial monitor. I am adding my code with this Please help me out

  • May 24, 2019
  • 3 replies
  • 1894 views

Details

STM32F767Zi

Keil

HSI =16Mhz

PLL=72 Mhz

UART1

PLL source = HSI

APB2 = 72Mhz

Baudrate = 9600;

/*

void _PLL()

{

//RCC->CR|=1<<24;

RCC->PLLCFGR&=0;

RCC->PLLCFGR|=(2<<28)|(6<<24)|(216<<6)|(1<<3)|(1<<17);

FLASH->ACR&=0;

FLASH->ACR|=1<<11|1<<9|1<<8|1<<1|1<<0;

RCC->CFGR|=4<<10|1<<1;//

RCC->CIR|=1<<12;

RCC->CIR|=1<<20;

RCC->CR|=1<<24;

//while(((RCC->CIR)&1<<4)==0);

//RCC->CIR|=1<<20;

// GPIOA->BSRR=(1<<5);

}

void uart1_init()

{

RCC->AHB1ENR|=1<<1;

RCC->APB2ENR|=1<<4 | 1<<14; // UART1 clock enable

//RCC->APB2LPENR|=1<<4 | 1<<14;

RCC->DCKCFGR2|=1<<0; 

GPIOB->MODER|=(1<<29)|(1<<31); // PB15 and PB14 are set for ALTERNATE FUNTION

GPIOB->AFR[0]=1<<18; // AZlternate function for Transmission

GPIOB->OSPEEDR|=1<<28|1<<29; // Set High speeed

USART1->BRR&=0;

USART1->BRR|= ((72000000)/9600);   // Baud rate for 9600 0X57E4;  //

USART1->GTPR&=0;

//RCC->CFGR&=0;

USART1->CR1&=0;

USART1->CR1|=1<<0|1<<7|1<<6;//|1<<1;  //UART Enabled (UE)

//USART1->CR1|=1<<3;  // Transmission Enabled (TE)

}

void main()

{

_PLL();

uart1_init();

while(!((USART1->ISR)&(1<<7))); // Checking the flag setting TXE

USART1->TDR='A'; // Data to be transmitted

while(!((USART1->ISR)&(1<<6)));

delay(5);

}

*/

This topic has been closed for replies.
Best answer by Tesla DeLorean

>>If you don't mind could you guide me to resolve the issue

When you go free climbing you don't expect people to run ropes for you. Consider more normative programing styles.

Remember the USART output at CMOS Levels, not RS232 Levels

//****************************************************************************
 
void usart1_init(void) // USART1 PB14/PB15
{
 RCC->AHB1ENR |= 1<<1; // GPIOB
 RCC->APB2ENR |= 1<<4; // USART1
 
 GPIOB->MODER = (GPIOB->MODER & 0x0FFFFFFF) | 0xA0000000; // PB15/PB14 AF
 GPIOB->OSPEEDR = (GPIOB->OSPEEDR & 0x0FFFFFFF); // PB15/PB14 9.6KHZ BELOW 2MHZ
 GPIOB->OTYPER = (GPIOB->OTYPER & 0x3FFF); // PB15/PB14 OUTPUT-PP AF OVERRIDES
 GPIOB->PUPDR = (GPIOB->PUPDR & 0x0FFFFFFF); // PB15/PB14 NO PULL
 GPIOB->AFR[1] = (GPIOB->AFR[1] & 0x00FFFFFF) | 0x44000000; // PB15/PB14 AF4
 
 USART1->CR1 = (1 << 3) | (1 << 2); // TE RE
 USART1->BRR = ((16000000)/9600); // Baud rate for 9600 from HSI
 USART1->CR2 = 0;
 USART1->CR3 = 0;
 USART1->GTPR = 0;
 USART1->CR1 |= (1 << 0); // UE
}
 
 
void usart1_outchar(char c)
{
 while((USART1->ISR & (1<<7)) == 0);
 USART1->TDR = c;
}
 
void usart1_outstring(char *s)
{
 while(*s)
 usart1_outchar(*s++);
}
 
void usart1_test(void)
{
 usart1_init();
 usart1_outstring("Hello World!\r\n");
}
 
//****************************************************************************
 
void usart3_init(void) // USART3 PD8/PD9 - NUCLEO-144
{
 RCC->AHB1ENR |= 1<<3; // GPIOD
 RCC->APB1ENR |= 1<<18; // USART3
 
 GPIOD->MODER = (GPIOD->MODER & 0xFFF0FFFF) | 0x000A0000; // PD9/PD8 AF
 GPIOD->OSPEEDR = (GPIOD->OSPEEDR & 0xFFF0FFFF); // PD9/PD8 9.6KHZ BELOW 2MHZ
 GPIOD->OTYPER = (GPIOD->OTYPER & 0xFFCF); // PD9/PD8 OUTPUT-PP AF OVERRIDES
 GPIOD->PUPDR = (GPIOD->PUPDR & 0xFFF0FFFF); // PD9/PD8 NO PULL
 GPIOD->AFR[1] = (GPIOD->AFR[1] & 0xFFFFFF00) | 0x00000077; // PD9/PB8 AF7
 
 USART3->CR1 = (1 << 3) | (1 << 2); // TE RE
 USART3->BRR = ((16000000)/9600); // Baud rate for 9600 from HSI
 USART3->CR2 = 0;
 USART3->CR3 = 0;
 USART3->GTPR = 0;
 USART3->CR1 |= (1 << 0); // UE
}
 
 
void usart3_outchar(char c)
{
 while((USART3->ISR & (1<<7)) == 0);
 USART3->TDR = c;
}
 
void usart3_outstring(char *s)
{
 while(*s)
 usart3_outchar(*s++);
}
 
void usart3_test(void)
{
 usart3_init();
 usart3_outstring("Hello World!\r\n");
}
 
//****************************************************************************

3 replies

Tesla DeLorean
Guru
May 24, 2019

Looks like hours of fun..

I don't think PB14/PB15 are going to be covered by AFR[0]

AFR[1] &= 0x00FFFFFF;

AFR[1] |= 0x44000000;

I would suggest first get the USART outputting from the HSI clock source, then move the the PLL

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
JS.13
JS.13Author
Associate
May 24, 2019

0690X000008wLuHQAU.jpg0690X000008wLuCQAU.jpgThanks for your suggestion.

the manual says for UARTTx, Alternate function is 4 , AF4, Since AF4 is in AFR[0] ,( I think so, Sorry if I am wrong)

I tried with HSI also but there is no proper output

Tesla DeLorean
Guru
May 25, 2019

0690X000008wPGkQAM.jpg

0690X000008wPGpQAM.jpg

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
JS.13
JS.13Author
Associate
May 24, 2019

Please Help me friends

T J
Senior III
May 25, 2019

Hi, in you code, you dont have a loop.

if it is working you will only get one byte.

void main()

{

_PLL();

uart1_init();

while(1){

while(!((USART1->ISR)&(1<<7))); // Checking the flag setting TXE

USART1->TDR='A'; // Data to be transmitted

while(!((USART1->ISR)&(1<<6)));

delay(5);

}

}