2019-05-23 09:34 PM
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);
}
*/
Solved! Go to Solution.
2019-05-25 08:42 AM
>>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");
}
//****************************************************************************
2019-05-23 11:37 PM
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
2019-05-23 11:54 PM
Thanks 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
2019-05-24 01:29 AM
Please Help me friends
2019-05-24 08:50 PM
@Community member
Hello Clive, I already done it with HSI. But there is no output, If you don't mind could you guide me to resolve the issue
2019-05-25 07:09 AM
2019-05-25 08:42 AM
>>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");
}
//****************************************************************************
2019-05-25 03:35 PM
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);
}
}
2019-05-30 10:10 PM
@Community member . Thanks for your valuable time