Hi guys .. i am not getting proper output on HT for transmission of character from STM32f4xx discovery board . please let me know where i am wrong. I am using Teraterm HT for Serial Communication on 9600 baudrate(8 bit char , 1 stop bit, no parity).
#include "stm32f4xx.h" #include "stm32f4xx_gpio.h" #include <stm32f4xx_usart.h> #include "stm32f4xx_rcc.h" #include "my_print.h" #include "misc.h"
void Delay(__IO uint32_t nCount) { while(nCount--) { } }
void init_USART1(uint32_t baudrate){
// USART1........................................................
GPIO_InitTypeDef GPIO_InitStruct; // this is for the GPIO pins used as TX and RX USART_InitTypeDef USART_InitStruct; // this is for the USART1 initilization USART_ClockInitTypeDef USART_ClockInitStruct; //NVIC_InitTypeDef NVIC_InitStructure;
/* enable APB2 peripheral clock for USART1 * note that only USART1 and USART6 are connected to APB2 * the other USARTs are connected to APB1 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE);
/* enable the peripheral clock for the pins used by * USART1, PB6 for TX and PB7 for RX */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* This sequence sets up the TX and RX pins * so they work correctly with the USART1 peripheral */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9 ; // Pins 9 (TX) are used GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; // the pins are configured as alternate function so the USART peripheral has access to them GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; // this defines the IO speed and has nothing to do with the baudrate! GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // this defines the output type as push pull mode (as opposed to open drain) GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; // this activates the pullup resistors on the IO pins GPIO_Init(GPIOA, &GPIO_InitStruct); // now all the values are passed to the GPIO_Init() function which sets the GPIO registers
/* The RX and TX pins are now connected to their AF * so that the USART1 can take over control of the * pins */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); // //GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
/* Now the USART_InitStruct is used to define the * properties of USART1 */ USART_InitStruct.USART_BaudRate = baudrate; // the baudrate is set to the value we passed into this init function USART_InitStruct.USART_WordLength = USART_WordLength_8b;// we want the data frame size to be 8 bits (standard) USART_InitStruct.USART_StopBits = USART_StopBits_1; // we want 1 stop bit (standard) USART_InitStruct.USART_Parity = USART_Parity_No; // we don't want a parity bit (standard) USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // we don't want flow control (standard) USART_InitStruct.USART_Mode = USART_Mode_Tx; // we want to enable the transmitter and the receiver
USART_Init(USART1, &USART_InitStruct); // again all the properties are passed to the USART_Init function which takes care of all the bit setting
// finally this enables the complete USART1 peripheral USART_Cmd(USART1, ENABLE);
}
void USART_puts(USART_TypeDef* USARTx, volatile char *s){
while(*s){ // wait until data register is empty while( !(USARTx->SR & 0x00000040) ); USART_SendData(USARTx, *s); s++; } }
//..........................
#include "main.h"
int main(void) { // SystemCoreClockUpdate(); init_USART1(9600); // initialize USART1 @ 9600 baud
USART_puts(USART1, "******A"); while (1){ /* * You can do whatever you want in here */ } }
Next time it might be an idea to actually post the source code using the proper tags. Unless you want everyone to ignore your post.
View all questions in Keil forum