Unexpected 0x00 on the UART bus when starting data exchange.
Moderators: TomKerekes, dynomotion
Unexpected 0x00 on the UART bus when starting data exchange.
Hi everyone!
I encountered strange behavior of UART when sending data from KFLOP.
I'm trying to send two doubles(double a=23.45006, b=9e6;) using the SendDouble.c program, 2ms before the start of the exchange, 0x00 flies over the bus and ends up in the receiver buffer, how can I fix this?
In this screenshot, exchange with STM32
I encountered strange behavior of UART when sending data from KFLOP.
I'm trying to send two doubles(double a=23.45006, b=9e6;) using the SendDouble.c program, 2ms before the start of the exchange, 0x00 flies over the bus and ends up in the receiver buffer, how can I fix this?
In this screenshot, exchange with STM32
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Unexpected 0x00 on the UART bus when starting data exchange.
Hi Alex,
That should only happen once when the UART is first initialized to flush the output buffer. It shouldn't be a problem if the receiver ignores data until a STARTCODE (0xAA) is received.
That should only happen once when the UART is first initialized to flush the output buffer. It shouldn't be a problem if the receiver ignores data until a STARTCODE (0xAA) is received.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Unexpected 0x00 on the UART bus when starting data exchange.
Thanks for the answer, I'll rewrite the code.
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Unexpected 0x00 on the UART bus when starting data exchange.
Hi Alex,
You might see the ReceiveDoubles.c example.
You might see the ReceiveDoubles.c example.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Unexpected 0x00 on the UART bus when starting data exchange.
Yes, I saw it. I rewrote the function, now everything works as it should.
Thanks!
Code: Select all
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if(huart == &huart1) {
if (RxData == 0xAA) {flag0 = 1;}
if (RxData == 0x01 && flag0) {flag1 = 1;}
if (flag0 && flag1)
{
RxData0[n] = RxData;
n++;
if(n==9)
{
n=0; flag0=0; flag1=0;
HAL_UART_Transmit_IT(&huart1, (uint8_t *)TxData, sizeof(TxData));
int i;
for (i=1;i<9;i++){
*(((unsigned char *)&a)+i-1) = RxData0[i] ;}
}
}
//------------------------------------------------------------------------------
if (RxData == 0x02 && flag0) {flag2 = 1;}
if (flag0 && flag2)
{
RxData0[n] = RxData;
n++;
if(n==9)
{
n=0; flag0=0; flag2=0;
HAL_UART_Transmit_IT(&huart1, (uint8_t *)TxData, sizeof(TxData));
int i;
for (i=1;i<9;i++){
*(((unsigned char *)&b)+i-1) = RxData0[i] ;}
}
}
HAL_UART_Receive_IT (&huart1, &RxData, sizeof(RxData));
}
}
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Unexpected 0x00 on the UART bus when starting data exchange.
I think that might have a flaw if the double data contains a command code 0x01 or 0x02.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Unexpected 0x00 on the UART bus when starting data exchange.
Possibly, but only if there is no 0x01 or 0x02 command code before it.
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Unexpected 0x00 on the UART bus when starting data exchange.
For example the sequence:
0xAA 0x01 0xDE 0x02
At this point all 3 flags are set causing double stores and so on.
I think once a command is received and receiving binary data it should not look for the other command until the first command is complete.
Such as:
HTH
0xAA 0x01 0xDE 0x02
At this point all 3 flags are set causing double stores and so on.
I think once a command is received and receiving binary data it should not look for the other command until the first command is complete.
Such as:
Code: Select all
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if(huart == &huart1) {
if (RxData == 0xAA) {flag0 = 1;}
if (RxData == 0x01 && flag0 && !flag2) {flag1 = 1;}
if (flag0 && flag1)
{
RxData0[n] = RxData;
n++;
if(n==9)
{
n=0; flag0=0; flag1=0;
HAL_UART_Transmit_IT(&huart1, (uint8_t *)TxData, sizeof(TxData));
int i;
for (i=1;i<9;i++){
*(((unsigned char *)&a)+i-1) = RxData0[i] ;}
}
}
//------------------------------------------------------------------------------
if (RxData == 0x02 && flag0 && !flag1) {flag2 = 1;}
if (flag0 && flag2)
{
RxData0[n] = RxData;
n++;
if(n==9)
{
n=0; flag0=0; flag2=0;
HAL_UART_Transmit_IT(&huart1, (uint8_t *)TxData, sizeof(TxData));
int i;
for (i=1;i<9;i++){
*(((unsigned char *)&b)+i-1) = RxData0[i] ;}
}
}
HAL_UART_Receive_IT (&huart1, &RxData, sizeof(RxData));
}
}
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Unexpected 0x00 on the UART bus when starting data exchange.
Thanks Tom, great point!