公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Jony1211
Level 2
Level 2
10 replies posted 25 sign-ins 5 replies posted

我在使用TC275单片机进行串口收发的时候,使用上位机给单片机发信息,debug界面显示的数据乱码,第一次用TC275,不知道什么问题,哪位大神可以给解决一下,万分感谢!
void Receive_UART_Message(void)
{

Ifx_SizeT rx_count = 13;

IfxAsclin_Asc_read(&g_ascHandle, g_rxData, &rx_count, TIME_INFINITE);

IfxAsclin_Asc_clearRx(&g_ascHandle);//清除接收缓存

}

Snipaste_2023-10-18_10-31-37.png

0 点赞
1 解答
Kunqiao_L
Moderator
Moderator
Moderator
First comment on blog First like given 25 likes received

Hi.

I didn't get your point " g_ Count is only read when it is full"? Could you explain it more details?

You demo code seems different from here. From the demo code, your g_count is size value of the g_txData, your rx_count is size of the g_rxData. When you use IfxAsclin_Asc_Read, you have to make sure your count and your data are match.

You can have larger rx_count value than the tx_count, but make sure your timeout is not infinte. Otherwise you are waiting forever.

 

IFX_likunqiao_0-1697706689123.png

Below is a one example: my gcount is 13 and my g_rx_count is 20. After reading the correct string "hello world", the value of the g_rx_count will change to 13

IFX_likunqiao_1-1697708547788.png

 

在原帖中查看解决方案

0 点赞
8 回复数
Kunqiao_L
Moderator
Moderator
Moderator
First comment on blog First like given 25 likes received

Hi Jony1211,

How about your g_rxData size? Did you run the exactly the same code example as this:

ASCLIN_UART_1_KIT_TC275_LK 

Thanks

0 点赞
lock attach
Attachments are accessible only for community members.
Jony1211
Level 2
Level 2
10 replies posted 25 sign-ins 5 replies posted

Thank you for your reply. I am currently using the official routine, TC275 Lite Kit, for the experimental board. Below is my complete serial port configuration section

0 点赞
Kunqiao_L
Moderator
Moderator
Moderator
First comment on blog First like given 25 likes received

Hi Jony1211,

I will take a look your code, by first glance, it looks fine. BTW, running the example code I provided above works fine, right?

0 点赞
Jony1211
Level 2
Level 2
10 replies posted 25 sign-ins 5 replies posted

There is no problem with the sample code, but the sample codes TX and RX are short circuited. After modifying the pins, I used the upper computer to send data to TC275, and the data would be partially garbled

0 点赞
Jony1211
Level 2
Level 2
10 replies posted 25 sign-ins 5 replies posted

I have found the problem. My USB-TTL module is broken and I just replaced it, but there is still one problem
IfxAsclin_ Asc_ Read (&g_ascHandle, g_rxData,&g_count, TIME_INFINITE);
This function only works when g_ Count is only read when it is full. If I send data of different lengths, it will cause data confusion. How can I solve this problem?

0 点赞
Kunqiao_L
Moderator
Moderator
Moderator
First comment on blog First like given 25 likes received

Hi.

I didn't get your point " g_ Count is only read when it is full"? Could you explain it more details?

You demo code seems different from here. From the demo code, your g_count is size value of the g_txData, your rx_count is size of the g_rxData. When you use IfxAsclin_Asc_Read, you have to make sure your count and your data are match.

You can have larger rx_count value than the tx_count, but make sure your timeout is not infinte. Otherwise you are waiting forever.

 

IFX_likunqiao_0-1697706689123.png

Below is a one example: my gcount is 13 and my g_rx_count is 20. After reading the correct string "hello world", the value of the g_rx_count will change to 13

IFX_likunqiao_1-1697708547788.png

 

0 点赞
Jony1211
Level 2
Level 2
10 replies posted 25 sign-ins 5 replies posted

FIFO will only trigger data reading after g_rx_count is filled, for example, my g_rx_count=5, if I send aaa, then it will not trigger data reading, debug can not see the data in rx_Data, but I send bbb again, then rx_Data="aaabb", The remaining "b" will be sent the next time g_rx_count is full. How do I solve this problem?

0 点赞
Kunqiao_L
Moderator
Moderator
Moderator
First comment on blog First like given 25 likes received

Hi Jony1211,

Please take a look at my previous picture, my g_rx_count is also larger than sending tx size, what I do is don't use TIME_INFINTE for timeout.

0 点赞