2021-10-06 09:55 AM
Hello everyone!
My setup uses a STM32407VG. I have been using for some time now and have gotten used to how to read the datasheet and use some of features. Today I am trying to get UART4 transmitting some data.
Here is how I went about getting it all setup:
I did step through the debugger (via STLINK) and it appears I am setting all of the correct bits. But when I land on that UE bit, I get the error (in the console) Target is not responding, retrying… until it times out. Below is a code snippet.
/* UART Functions */
void UART4_Config()
{
// Enable GPIO C
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
// Enable the UART (PC10=TX PC11=RX)
RCC->APB1ENR |= DKO_UART4_ENABLE;
// UART4 TX PIN
GPIOC->MODER &= ~(GPIO_MODER_MODE10); // Clear pin mode field
GPIOC->MODER |= GPIO_MODER_MODER10_1; // Set pin mode field as alternate
GPIOC->OTYPER &= ~(GPIO_OTYPER_OT10); // Clear output type field (push-pull by default)
GPIOC->OSPEEDR &= ~(GPIO_OTYPER_OT10); // Clear output speed field (low by default)
GPIOC->OSPEEDR |= GPIO_OSPEEDR_OSPEED10_0; // Set to medium speed
GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPD10); // Clear pullup/ pulldown mode field (none as default)
GPIOC->AFR[1] &= ~(1U << 8); // Set alternate function to be AF8, bit 8
GPIOC->AFR[1] &= ~(1U << 9); // Set alternate function to be AF8, bit 9
GPIOC->AFR[1] &= ~(1U << 10); // Set alternate function to be AF8, bit 10
GPIOC->AFR[1] |= (1U << 11); // Set alternate function to be AF8, bit 11
// UART4 SPECIFIC CONFIG
UART4->BRR = 2188; // Set baudrate to be 19200; formula is BRR = [pclk + (baud/2)] / baud
UART4->CR1 = (1U << 3); // Set the TE bit (transmitter enable bit)
UART4->CR1 |= (1U << 13); // Set the UE bit (uart enable bit)
}
I never used a UART other than on things like BASIC STAMP, PICAXE, and ARDUINO. It is a little more setup with bare metal STM32F407 but it looked pretty doable. Any hints would be greatly appreciated! Thanks for your time!
Solved! Go to Solution.
2021-10-08 08:43 AM
As an update, I got the RX portion working as well. Though I do have another question about UART in general but I will create a new thread for this.