2008-01-03 03:14 AM
2008-01-03 03:14 AM
Init UART
void init_UARTS_(38400){ UART_InitTypeDef UART_InitStruct; GPIO_InitTypeDef GPIO_InitStructure; /*Enable Clock for UART*/ CFG_PeripheralClockConfig(CFG_CLK_UART0 , ENABLE); CFG_PeripheralClockConfig(CFG_CLK_UART2 , ENABLE); CFG_PeripheralClockConfig(CFG_CLK_UART3 , ENABLE); /* Configure the GPIO Tx pins as alternate function push pull*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pins = RS485_Tx_Pin; GPIO_Init (GPIO6, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pins = UART2_Tx_Pin + UART3_Tx_Pin; GPIO_Init (GPIO5, &GPIO_InitStructure); // Configure UART RX pins as Tristate TTL GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_TRI_TTL; GPIO_InitStructure.GPIO_Pins = RS485_Rx_Pin; // + UART3_Rx_Pin ; GPIO_Init (GPIO6, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pins = UART2_Rx_Pin; GPIO_Init (GPIO5, &GPIO_InitStructure); /* UART Configuration */ UART_StructInit(&UART_InitStruct); //Initialize Structure with default values UART_InitStruct.UART_BaudRate = baudrate; // Baud rate value UART_InitStruct.UART_Mode = UART_Mode_8D ; //Set the UARTx Mode 8 bit Data UART_InitStruct.UART_Loop_Standard = UART_Standard; //Disable LoopBack UART_InitStruct.UART_StopBits = UART_StopBits_1; // STOP bits number/ UART_InitStruct.UART_FIFO = UART_FIFO_Enable; UART_InitStruct.UART_Rx = UART_Rx_Enable; /*enable receive*/ UART_Cmd(UART0, ENABLE); UART_Cmd(UART2, ENABLE); UART_Cmd(UART3, ENABLE); UART_Init(UART0, &UART_InitStruct); UART_Init(UART3, &UART_InitStruct); UART_Init(UART2, &UART_InitStruct); *************** read functionunsigned char read_input_function(){ retries++; while((UART_FlagStatus(UART0, UART_Flag_RxBufFull)==0) && (retries >0)) retries--; if (retries == 0){ error_flag = 1; return RESPONSE_TIMEOUT; }else{ return UART_ByteReceive(UART0); } } *********** main() char input[99]; for (i = 0; ((i input[i]=read_input(); } ********' Works fine, However after my first read, lets say 70bytes. I send a package again and start the read again but this time the read will only read 16 bytes, sometimes only 1 byte. But i if i stop, reset and run the project from start the read will be complete just like the first time. It seems illogical and intermittent. Do you have any ideas?