STM32F407 UART problems. PuTTY, FTDI USB to TTL converter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-21 10:52 AM
EDIT: For crying out loud. Why is half of my code chopped off?
#if !defined(__SOFT_FP__) && defined(__ARM_FP)
#warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
#include "stm32f4xx.h"
// UART1 is used. Sits on APB2 bus
// GPIOA sits on AHB1 bus. USART1 is AF7 for PA9 and PA10
// PA9: USART1_TX
// PA10: USART1_RX
// Baudrate: 9600
void funcGPIOInit();
void funcUARTInit();
void funcUARTSend();
int main(void)
{
funcGPIOInit();
funcUARTInit();
funcUARTSend();
for(;;)
{
}
}
void funcGPIOInit()
{
// Enable AHB1 bus. Set PA9 and PA10 to AF,
RCC->AHB1ENR |= (1MODER |= (2MODER |= (2OTYPER &= ~(1OTYPER &= ~(1OSPEEDR &= ~(3OSPEEDR &= ~(3PUPDR &= ~(3PUPDR &= ~(3AFR[1] |= (7AFR[1] |= (7APB2ENR |= (1BRR = 0xD03;
USART1->CR1 |= (1CR1 &= ~(1CR1 &= ~(1CR1 |= (1CR2 &= ~(3CR1 |= (1DR = 120;
}
- Labels:
-
STM32F4 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-21 10:54 AM
#if !defined(__SOFT_FP__) && defined(__ARM_FP)
#warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
#include "stm32f4xx.h"
// UART1 is used. Sits on APB2 bus
// GPIOA sits on AHB1 bus. USART1 is AF7 for PA9 and PA10
// PA9: USART1_TX
// PA10: USART1_RX
// Baudrate: 9600
void funcGPIOInit();
void funcUARTInit();
void funcUARTSend();
int main(void)
{
funcGPIOInit();
funcUARTInit();
funcUARTSend();
for(;;)
{
}
}
void funcGPIOInit()
{
// Enable AHB1 bus. Set PA9 and PA10 to AF,
RCC->AHB1ENR |= (1MODER |= (2MODER |= (2OTYPER &= ~(1OTYPER &= ~(1OSPEEDR &= ~(3OSPEEDR &= ~(3PUPDR &= ~(3PUPDR &= ~(3AFR[1] |= (7AFR[1] |= (7APB2ENR |= (1BRR = 0xD03;
USART1->CR1 |= (1CR1 &= ~(1CR1 &= ~(1CR1 |= (1CR2 &= ~(3CR1 |= (1DR = 120;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-21 10:56 AM
I just noticed that the forum software alters my code snipped. LOL guys, seriously? You seem to have a bug in your software.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-21 11:07 AM
It is more likely what you're pasting. On a Mac?
​
Just attach as a buildable .C​ rather than inlining the code.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-21 11:13 AM
Hi clive1, I paste my code in from a windows machine. WIN10 as I did before in my other posts as well. I can also see that the software modifies my code. I set every register bit in its own line of code. However, the code shown above collected all register manipulations with an OR.
Anyway, let me attach the main.c file which contains the source code.
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-21 1:25 PM
I'd use 16 over-sampling, USART1->BRR = 0x683;
And loop on TXE before sending
void funcUARTSend()
{
int i;
for(i=0; i<10; i++)
{
while((USART1->SR & 0x80) == 0); // wait for TXE to assert
USART1->DR = 0x55;
}
}
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-21 11:05 PM
Hi clive1
I forgot to mention that I am using the discovery board, so you may already have known the issue upfront without going through my code. Sorry for that.
I eventually found the problem. PA9 and PA10 on the discovery board are already used for other hardware purposes, so there is a conflict when using PA9 as a TX for UART. I configured USART1 using PB6 and PB7 which are not used on the discovery board. I get the proper transmission now and everything works as expected.
Thank you,
