完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,这是我在论坛上发表的第一篇文章,所以让我知道如果我选择要发布的部分或者格式有什么问题。我试图使用PIC18F4585微控制器http://bit.ly/2iV4Y08连接到CAN网络,但是我遇到了很多麻烦让它起作用。我正在尝试从CAN网络接收消息,该消息将应用于汽车(运行500kbit/sec波特率),并且我正在物理层http://bit.ly/2iW7cOJAs中使用该收发器,因为我可以告诉收发器工作正常,并且我正在正确地将其连接到控制器,所以墨水问题是专门为它设置配置代码工作的。我试着跟随数据表中的所有信息,以便为CAN模块设置配置位,因此我需要有人检查它,并告诉我是否遗漏了简单的东西,这就是我迄今为止所拥有的:现在,我设置了所有的连接,并尝试读取一条消息。G在2个CAN节点之间传输,带有我设置的标识符。不幸的是,好像控制器根本看不到消息。RXFUL寄存器从来没有设置过,而且,如果我为RXERRCNT寄存器设置了一个表(它应该显示接收错误),那么它甚至不会从0改变,所以它似乎与传播延迟或定时无关。我想我只是没能正确地设置CAN模块的配置位,而且确实有一些明显的地方我遗漏了,有人能帮忙吗?
以上来自于百度翻译 以下为原文 Hello all, This is my first post in the forums so let me know if there's anything wrong with my choice of section to post in or the format or anything like that. I am trying to use a PIC18F4585 microcontroller http://bit.ly/2iV4Y08 in order to connect to a CAN network but I am having a lot of trouble getting it to work. I am trying to receive messages from a CAN network that will be applied in a car (running 500kbits/sec baud rate) and I am using this transceiver in the physical layer http://bit.ly/2iW7cOJ As far as I can tell the transceiver is working fine and I'm connecting it to the controller correctly, so I think the issue is specifically in setting up the configuration code for it to work. I tried following all the information in the datasheet in order to set up the configuration bits for the CAN module so I need someone to look it over and tell me if I'm missing something simple, this is what I have so far: #include #include #include "config.h" #include /* * */ #define _XTAL_FREQ 20000000 int main(int argc, char** argv) { OSCCON = 0b01110000; // Set internal clock to 8 MHz // Set RX pin as input TRISB3 = 1; // Set up registers for CAN receiving CANCON = 0b10000000; // request configuration mode CANSTAT = 0b10000000; // not using interupts _delay(50); // wait for mode to change BRGCON1 = 0b01000000; // Set TQ and propagation delay BRGCON2 = 0b00001001; BRGCON3 = 0b10000000; CIOCON = 0b00000000; // Don't use the capture feature RXB0CON = 0b00101110; // Set status register RXB0SIDH = 0b11000110; // Set identification RXB0SIDL = 0b01000000; RXB0DLC = 0b00000001; // Last 4 bits determine data length (# of bytes), for testing I'm using 1 byte // Data should appear in RXB0D[0,1,2,3,4,5,6,7] // Set into listen-only mode for testing purposes CANCON = 0b01100000; CANSTAT = 0b10000000; // wait for mode to change _delay(50); // these are just here for testing purposes RXB0D0 = 0b00000010; int x = 0; while(1){ x = 1; _delay(20); if(RXB0CONbits.RXFUL == 1){ x = 3; RXB0CONbits.RXFUL = 0; // if I'm the program is in here a message was received } x = 2; _delay(20); } return (EXIT_SUCCESS); } Now I set up all of the connections and tried reading a message that was being transmitted between 2 CAN nodes with the identifier I set up. Unfortunately, it doesn't seem like the controller is seeing the messages at all. The RXFUL register never gets set and what's more, if I set up a watch for the RXERRCNT register (which is supposed to show receive errors) then it doesn't even change from 0, so it doesn't seem to be an issue with the propagation delay or timing specifically. I think I'm just failing to set up the configuration bits for the CAN module correctly and there is something really obvious that I'm missing, can anyone help? |
|
相关推荐
1个回答
|
|
第一次,这个问题似乎与你的波特率设置有关。您已经:BRGCON1设置了2/FOSC的TQ,或.25uS,BRGCON2将相位段1和传播段设置为2X TQ,并将相位段2设置为等于相位段1。由此,我们有一个比特定时,TQ为.25uS,这将给出总比特时间为1.75uS,或者波特率为571.428kbit/秒。这里您似乎犯了一个非常常见的错误:同步段总是由CAN规范固定1TQ,BRGCON1的SJW位控制同步跳变宽度,而不是同步段宽度。将传播段更改为3TQ(BRGCON2=0b00001010)应该会使消息开始在总线上显示。一些额外的注释供将来的CAN参考:由于您处于只侦听模式,错误计数器被重置和禁用,因此监视RXERRCNT不是有效的de方法如果有消息在那个模式中通过,就要侦听。CANSTAT寄存器是只读的,所以您试图通过向它写入来实现的任何功能都不会生效。你对此有什么打算?我可以帮您指出正确的寄存器。代替等待模式改变的静态延迟,轮询与当前操作模式相关联的CANSTAT位(CANSTAT的7-5位)可能更有用,因为这样可以确保CAN模式具有适当的ch盎格鲁人的
以上来自于百度翻译 以下为原文 On first pass, the issue appears to be with your baud rate setup. You have: BRGCON1=0b01000000 BRGCON2=0b00001001 BRGCON3=0b10000000 BRGCON1 sets up a TQ of 2/FOSC, or .25uS, BRGCON2 sets Phase segment 1 and propagation segment to 2 X TQ, and sets Phase Segment 2 to be equal to Phase segment 1. From this, we have a bit timing of Synchronization Segment (Fixed at 1 TQ) + Propagation Segment (2 TQ) + Phase Segment 1 (2 TQ) + Phase Segment 2 (2 TQ) = 7 TQ. With a TQ of .25uS, this will give a total bit time of 1.75uS, or a baud rate of 571.428 kbits/second. It appears that you made a very common mistake here: the sync segment is always fixed 1 TQ by the CAN spec, the SJW bits of BRGCON1 control the synchronization jump width, not the sync segment width. Changing the propagation segment to 3 TQ (BRGCON2= 0b00001010) should make the messages start to show up on your bus. A few additional notes for future CAN reference:
|
|
|
|
只有小组成员才能发言,加入小组>>
4844 浏览 9 评论
1846 浏览 8 评论
1762 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
2971 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2074 浏览 5 评论
472浏览 1评论
1123浏览 1评论
313浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
375浏览 0评论
270浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-5-14 17:28 , Processed in 1.032576 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号