2016-03-06 12:01 PM
volatile char c; volatilechar RF_Buffer_IN[50]; int main(void) {
/* Initialize system */
SystemInit(); /* Initialize USART */ MY_USART_initilize(19200) while (1) {/* Transferring Some data via TX Line */
USART_SendData(USART2, c); } } /*---------------------------------------------------------------------------------------------*/ void MY_USART_initilize(float Buadrate) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStruct; /*-----------------------------USART2 For Sending data to PC----------------------------*/ // clocks RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE); /* Configure USART2 Tx/RX (PA2/PA3) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // Map USART2 to A2,A3 GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); // Initialize USART2 USART_InitStructure.USART_BaudRate = Buadrate; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; /* Configure USART */ USART_Init(USART2, &USART_InitStructure); /* Enable the USART */ USART_Cmd(USART2, ENABLE); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); NVIC_InitStruct.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0; NVIC_Init(&NVIC_InitStruct); } /* USART IRQ handler */ void USART2_IRQHandler(void) { static int rx_index = 0; if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) // Received characters modify string { GPIO_SetBits(GPIOD, GPIO_Pin_15); RF_Buffer_IN[rx_index++] = USART_ReceiveData(USART2); if (rx_index >= (sizeof(RF_Buffer_IN) - 1)) { rx_index = 0; } /******* Decoding is done here ********/ }2016-03-07 06:34 AM
static int rx_index = 0;
void USART2_IRQHandler(void) {
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) // Received characters modify string { GPIO_SetBits(GPIOD, GPIO_Pin_15); RF_Buffer_IN[rx_index++] = USART_ReceiveData(USART2); if (rx_index >= (sizeof(RF_Buffer_IN) - 1)) { rx_index = 0; }/******* Decoding is done here ********/
}
2016-03-07 09:01 AM
The baud rate shouldn't be a float, and when sending characters you should wait for TXE to be true before jamming characters into the register.
2016-03-08 11:18 AM
2016-03-08 12:16 PM
I'm objecting too
while (1) {
/* Transferring Some data via TX Line */
USART_SendData(USART2, c);
}
Perhaps you need to ponder how you are debugging this?
Is the part actually receiving anything? Does polling work?
Can you loop back the data being sent (properly) and see that being received?
If you transmit a 'U' character repetitively, can you see that on a scope, and confirm the bit timing?
Are you using C++ or .cpp files? If so consider name mangling.
If the baud rate or bit timing is wrong, then confirm that HSE_VALUE reflects the frequency of your external oscillator.
The STM32 is not compatible with RS232 levels, it is using a 3V CMOS levels.
Make sure you have the TX/RX sense correct, ie DCE vs DTE
What else are you doing in the IRQHandler? Perhaps the problem is not with the code being presented.