This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

REGARDING USART COMMUNICATION

Dear Sir

we're using ur MCBSTM32E board for ARM cortex m3 controller.
we 're doing USART communication, we are able to transmit data from USART2, BUT IN RECEIVING WE'RE FACING PROBLEM THAT we did not get any data.

I'm writing code what we've made, please suggest us what's our mistake.

we 're not getting any thing.

please consider it as urgent.

int main (void)
{

RCC_Configuration(); NVIC_Configuration(); GPIO_Configuration(); USART_Configuration();

send_data(); recd_data(); send_data_2_pc();

}

void send_data() { unsigned char *x,k,i;

for(i=1;i<=9;i++) { x=&temp[i]; k=*x; sendchar(k); }

}

/*---------------------------------------------------------------------------- Write character to Serial Port *----------------------------------------------------------------------------*/
sendchar (int c) {

if (c == '\n') { while (!(USART2->SR & USART_FLAG_TXE)); USART2->DR = 0x0D; } while (!(USART2->SR & USART_FLAG_TXE)); USART2->DR = (c & 0x1FF); return (c); }

/***************************************************/

void recd_data() { unsigned char *z,y,i=0; for(i=1;i<=13;i++) {

getkey(); y=USART2->DR ; z=&temp1[i]; *z=y; } }

/*---------------------------------------------------------------------------- Read character from Serial Port (blocking read) *----------------------------------------------------------------------------*/
int getkey (void) { while (!(USART2->SR & USART_FLAG_RXNE)); return ((int)(USART2->DR & 0x1FF)); }

/*************************************************/

void send_data_2_pc() { unsigned char *a,b,i=0; for(i=1;i<=13;i++) { a=&temp1[i]; b=*a; sendchar_1(b);

} }

/*---------------------------------------------------------------------------- Write character to Serial Port *----------------------------------------------------------------------------*/
sendchar_1 (int c) {

if (c == '\n') { while (!(USART3->SR & USART_FLAG_TXE)); USART3->DR = 0x0D; } while (!(USART3->SR & USART_FLAG_TXE)); USART3->DR = (c & 0x1FF); return (c); }

/*********************************************/

void RCC_Configuration(void) { /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { }

/* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4|RCC_APB1Periph_TIM3, ENABLE); /* enable GPIOx CLOCK*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* enable USARTx CLOCK*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3, ENABLE); }

/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void) { #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif }

/******************************************************/

void USART_Configuration(void) { //RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE); USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_Mode = USART_Mode_Rx |USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /* Configure USART1 */ USART_Init(USART1, &USART_InitStructure); /* Configure USART2*/ USART_Init(USART2, &USART_InitStructure); /* Enable the USART1 */ USART_Cmd(USART1, ENABLE); /* Enable the USART2 */ USART_Cmd(USART2,ENABLE);

USART_Init(USART3, &USART_InitStructure); /* Enable the USART3 */ USART_Cmd(USART3, ENABLE);

}

void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure;

/* CONFIGURE USART2_Tx as alternate function push-pull*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA,&GPIO_InitStructure);

/* CONFIGURE USART2_Rx as input floating*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA,&GPIO_InitStructure);

/* CONFIGURE USART2_Tx as alternate function push-pull*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB,&GPIO_InitStructure);

/* CONFIGURE USART2_Rx as input floating*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB,&GPIO_InitStructure);

}

in above routine txansmit part is ok , but problem in receving data.

please help us out.

Ruchi Dua
rdua@awtxglobal.com