im using stm32f407.
i have a ublox GPS , i want gps give me specific data with specific update rate . so first i need to write some data with 9600 baudrate(UARTD2).
after sending these setting i should read gps in 38400 baudrate(UARTD2), 164 byte , 5 times in a second . and i parse it's data and then i send my desired data through another uart (UARTD6) with 115200 baudrate.
when i program the micro or reset it(i didn't unplug the micro) , it works well but when i unplug the micro and then plug it , the data is Nonsense.
at first i thought that the problem is in my parsing, but when i print data coming from gps (my gps buffer) straight to my output uart(UARTD6) i saw that the does data are nonsense.
uart driver using dma , so there is question , why when i unplug and then plug the micro, UART2 don't fill the buffer.
interesting point is after plug , when i reset the micro , the data is ok.
any idea why it shows this behavior ?
thanks in advance
here is code :
Code: Select all
uint8_t RecBuffer[164];
static UARTConfig uart_cfg_GPS_m = {
NULL,
NULL,
NULL,
NULL,
NULL,
38400,
0,
USART_CR2_LINEN,
0
};
static UARTConfig uart_cfg_GPS_4 = {
NULL,
NULL,
NULL,
NULL,
NULL,
9600,
0,
USART_CR2_LINEN,
0
};
void Gps_Configuration(void)
{
uartStart(&UARTD2, &uart_cfg_GPS_4);
uartStartSend(&UARTD2,14,buffer_NAV_RAte);
chThdSleepMilliseconds(15);
uartStartSend(&UARTD2,11,buffer_POSLLH);
chThdSleepMilliseconds(15);
uartStartSend(&UARTD2,11,buffer_STATUS);
chThdSleepMilliseconds(15);
uartStartSend(&UARTD2,11,buffer_SOL);
chThdSleepMilliseconds(15);
uartStartSend(&UARTD2,11,buffer_VELNED);
chThdSleepMilliseconds(15);
uartStartSend(&UARTD2,33,UBX);
chThdSleepMilliseconds(40);
uartStop(&UARTD2);
chThdSleepMilliseconds(200);
uartStart(&UARTD2, &uart_cfg_GPS_m);
}
void GPS_Start_Reading(void)
{
uartStartReceive(&UARTD2,164,RecBuffer);
}
void GPS_Stop_Reading(void)
{
uartStopReceive(&UARTD2);
}
int main(void) {
halInit();
chSysInit();
Gps_Configuration();
/*
* Prepares the UART6
*/
uartStart(&UARTD6, &uart_cfg_1);
palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(8));
palSetPadMode(GPIOC, 7, PAL_MODE_ALTERNATE(8));
while (TRUE) {
GPS_Start_Reading();
chThdSleepMilliseconds(200);
GPS_Stop_Reading();
uartStartSend(&UARTD6,36,RecBuffer);
}