完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我目前正在做一个在两个PIC32 2048 EFH064(MPLABX 3.45,和谐1.062 02)之间的CAN通信。我用轮询模式下的CAN,传输和接收工作良好,但是管理收到的消息确实有问题。确实,在一些CAN帧到达之后,接收FIFO会充满它们。为了确保我不读两次消息,我希望FIFO在我打电话后被一条消息清空:但是这不会发生。因此,每次我读FIFO,都会得到相同的消息,因为我没有办法检查新消息是否已经替换了旧消息。那么,在读取了FIFO之后,我怎么才能清空FIFO呢?或者我怎样才能确保新消息取代了FIFO中的旧消息呢?非常感谢你对此事的任何建议。杰罗姆
以上来自于百度翻译 以下为原文 Hi, I am currently working on making a CAN communication between two pic32 2048EFH064 (MPLABX 3.45, HARMony 1.06.02). I use the CAN in polled mode. The transmission and reception work fine, however I do have a problem managing the received messages. Indeed, after some CAN frames have arrived, the receive FIFO gets filled with them. To make sure that I don't read a message twice, I was expecting the FIFO to be emptied by one message after I called DRV_CAN0_ChannelMessageReceive : for (k=0; k<=C1FIFOCON0bits.FSIZE; k++){ while (DRV_CAN0_ChannelMessageReceive(CAN_CHANNEL0, 0x33, 8, (uint8_t*)&RxMsg[k]) == false); } But this does not happen. As a consequence, every time I read the FIFO, I get the same messages, as I don't have a way to check that new messages have replaced the old ones. So how can I empty the FIFO after having read it ? Or How could I make sure that new messages have replaced the old ones in the FIFO? Thanks a lot for any advice on that matter. Jerome |
|
相关推荐
3个回答
|
|
有了这样的称呼,我觉得你一遍又一遍地读着同样的东西。
以上来自于百度翻译 以下为原文 with this kind of call it seems to me that you are reading the same thing over and over. try using this: k=C1FIFOCON0bits.FSIZE; uint8_t RxMsg[k]; while (DRV_CAN0_ChannelMessageReceive(CAN_CHANNEL0, 0x33, k, &RxMsg[0]) == false); |
|
|
|
嗨,艾利克斯,你的解决方案并没有给我存储在FIFO中的所有消息的值。它似乎给了第一个的值。我希望FIFO在我读了它之后从消息中被清空,所以我确信我不会读两次相同的消息。
以上来自于百度翻译 以下为原文 Hi allex, Your solution does not give me all the values of the messages stored in the FIFO. It just seem to give the value of the first one. What I would like is that the FIFO get emptied from the message after I have read it, so that I am sure that I won't be reading the same message twice. |
|
|
|
您是对的,我已经检查了DrviChan0xChhannMeasAgErrEVEVER()函数,它只读取一个消息中的字节,如果消息被正确处理,则返回true。因此,我认为您需要经历一个循环,该循环将读取多条消息,而不是单个消息的多个字节。也许这样的事情会起作用。或者你总是可以让一个缓冲区长一个消息,并使用RX事件来拾取它,这样你就可以在那个时候处理一个消息。我个人是这样做的:
以上来自于百度翻译 以下为原文 You are right, I've checked the DRV_CAN0_ChannelMessageReceive() function and it only reads bytes from one message and returns true if message is processed properly. So I think you need to go through a loop that will read multiple messages and not multiple bytes of a single message. Maybe something like this will work. k=C1FIFOCON0bits.FSIZE;//how many messages you've got uint8_t RxMsg[8];//8 bytes long message char i=0;//loop counterwhile(i<=k){ if(DRV_CAN0_ChannelMessageReceive(CAN_CHANNEL0, 0x33, k, &RxMsg[0]) == true)// 8 bytes of a message read //do something with the message on the spot i++;// increment the counter } Or you can always make CAN buffer one message long and use RX event for picking it up so you can process one message at the time. I am personally doing things that way :) |
|
|
|
只有小组成员才能发言,加入小组>>
5212 浏览 9 评论
2020 浏览 8 评论
1944 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3193 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2246 浏览 5 评论
763浏览 1评论
649浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
570浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
661浏览 0评论
558浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-13 00:34 , Processed in 1.757076 second(s), Total 80, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号