Hi All,
I am developing some code on the STM32F030R8 Nucleo dev board. I am having trouble getting my USART transmit to clock out. I am sending values to the comm port every 1s, and I am seeing nothing. I am also monitoring the pin on a scope and I see nothing.
After the code goes through the 'PrintRS232(Tx)' function I get a transmit complete flag and transmit empty flag in the ISR(TC and TXE), which is very confusing since I don't see any data transmitting.
I am using a watch window to monitor each bit getting transmitted and they are correct according to the ascii table.
I typically use Cortex M3 or M4 and never had an issue with USART. This is my first M0 project. I think I need some fresh eyes to go through this code.
#include <stm32f0xx.h> #include "UART.h" // USART Files char UART_RX[50]; char *pRx; void InitUART(void){ // Enable Clocks RCC->APB1ENR |= RCC_APB1ENR_USART2EN; // Enable USART1 peripheral clk RCC->AHBENR |= RCC_AHBENR_GPIOAEN; // Enable Port A Clk for USART1 // Configure PA2 (Tx) and PA3 (Rx) GPIOA->AFR[0] |= 0x01 << (2 * 4); //AFRL, PA2, UART1 GPIOA->AFR[0] |= 0x01 << (3 * 4); //AFRL, PA3, UART1 GPIOA->MODER &= ~0x000000F0; //Clear PA2 & PA3 GPIOA->MODER |= GPIO_MODER_MODER2_1; //Alternate Fxn mode GPIOA->MODER |= GPIO_MODER_MODER3_1; //Alternate Fxn mode GPIOA->OTYPER &= ~GPIO_OTYPER_OT_2; //Output Push/Pull GPIOA->OTYPER &= ~GPIO_OTYPER_OT_3; //Output Push/Pull GPIOA->OSPEEDR |= GPIO_OSPEEDR_OSPEEDR2; //PA2 high speed GPIOA->OSPEEDR |= GPIO_OSPEEDR_OSPEEDR3; //PA3 high speed GPIOA->PUPDR |= GPIO_PUPDR_PUPDR2_0; //PA2 Pull up GPIOA->PUPDR |= GPIO_PUPDR_PUPDR3_0; //PA3 Pull up // Configure UART USART2->CR1 &= ~USART_CR1_UE; //Disable UART for configuring USART2->CR1 &= ~USART_CR1_M; //Data length = 8bits NVIC_EnableIRQ(USART1_IRQn); //Enable USART1 IRQ USART2->CR1 |= USART_CR1_RXNEIE; //Rx interrupt enable USART2->CR1 &= ~USART_CR1_PCE; //No parity control USART2->CR1 &= ~USART_CR2_STOP; //1 stop bit USART2->CR1 &= ~USART_CR3_CTSE; //No hardware flow control USART2->CR1 &= ~USART_CR3_RTSE; //No hardware flow control USART2->BRR = (SystemCoreClock/115200); //Baud Rate of 115.2Kbps USART2->CR1 |= USART_CR1_RE; //Recieve enable USART2->CR1 |= USART_CR1_TE; //Transmit enable USART2->CR1 |= USART_CR1_UE; //USART enable pRx = &UART_RX[0]; //pRx is pointed at first pos of buffer //This function prints to the comm port via rs232 void PrintRS232(char* pString){ USART1->CR1 |= USART_CR1_TE; // Set transmit enable bit while(*pString){ // Print char's as long as not a null char USART1->TDR = *pString; // Put char into the data register while(!(USART1->ISR & USART_ISR_TXE)); // xfer to shift register pString++; // Increment ptr in memory } }
Thanks, - JMP