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 6: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 9: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);
}