cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 F4 Discovery USART1 Glitch

maharaj
Associate II
Posted on December 28, 2015 at 06:11

Hi there...

I have been trying to run USART1 od my stm32 f4 disco board...i have done all the basic setting and intialization of pins(PA9 and PA10) and baud rate calc for running usart...But i have not able to see any data on my DSO. Also if i connect my ble device(HC-05,9600 baud) with it, it doesnt show any data on my phone terminal.

My APB1 clock(fclk) is set at 84 Mhz and i have also set HSE value to 8 Mhz,since I am using PLL to upreach th basic clock to 84 mhz.

My code is below...pls have a look at it and suggest solutions for it....

//&sharpinclude ''stm32f4xx.h''

&sharpinclude ''stm32f429xx.h''

&sharpdefine USART_WAIT(USARTx)                  do { while (!((USARTx)->SR & USART_SR_TXE)); } while (0)

volatile uint32_t msTicks;                      /* counts 1ms timeTicks       */

volatile int SysTickFired;

void SysTick_Handler(void)

{

if(msTicks!=0)

{

msTicks--;

}

}

void Delay_ms (__IO uint32_t dlyTicks)

{

msTicks = dlyTicks;

while(msTicks!=0);

}

void usart1_set(void)

{

uint32_t pinpos;

//USART1       TX PA9    RX PA10    |PB6    PB7     |-      -

RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

GPIOA->MODER |= GPIO_MODER_MODER9_1 | GPIO_MODER_MODER10_1; //AF

GPIOG->OTYPER |= ((uint16_t)0x0000);

GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR9_1 | GPIO_OSPEEDER_OSPEEDR10_1;

GPIOA->PUPDR |= GPIO_PUPDR_PUPDR9_0 | GPIO_PUPDR_PUPDR10_0;

//GPIOA->AFR[1] |= 0x00000770;

for (pinpos = 0; pinpos < 0x10; pinpos++) {

/* Check pin */

if ( ((uint16_t)0x0600 & (1 << pinpos)) == 0) {

continue;

}

/* Set alternate function */

GPIOA->AFR[pinpos >> 0x03] = (GPIOA->AFR[pinpos >> 0x03] & ~(0x0F << (4 * (pinpos & 0x07)))) | (0x07 << (4 * (pinpos & 0x07)));

}

}

void usart1_init()

{

RCC->APB2ENR |= RCC_APB2ENR_USART1EN;

USART1->CR1 |= USART_CR1_UE | USART_CR1_RE | USART_CR1_TE;

//USART1->CR2 |= 0x0800;

USART1->BRR = 0x222E;  (9600 baud,Fclk = 84Mhz)

}

unsigned char USART1_receive()                        

{

unsigned int sr_read;

sr_read = USART1->SR;

while((sr_read & 0x0020) == 0);                       //wait until data is available for reading

return (USART1->DR);                                  //return read data

}

void USART1_send(char value) //void USART1_send(char* str)

{

//while (*str) 

{

/* Wait to be ready, buffer empty */

USART_WAIT(USART1);

/* Send data */

//USART1->DR = (uint16_t)(*str++ & 0x01FF);

USART1->DR = (value & 0x01FF);

//  while(((USART1->SR) & USART_SR_TXE) == 0);       

/* Wait to be ready, buffer empty */

//while(!(USART1)->SR & USART_SR_TXE == 0);                          //wait until data transmission is complete

                                              //transfer data to DR register

}

}    

int main()

{

SystemInit();

//SystemCoreClockUpdate();

SysTick_Config(SystemCoreClock/1000); //for 1ms delay

usart1_set();

usart1_init();

while(1)

{

USART1_send('A');

Delay_ms(500);

}

}

#stm32 #stm32f4 #discovery #usart #usart1
0 REPLIES 0