完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我已经包含了用于我的PIC32 MZ的CAN总线代码,运行在100MHz,同样适用于外围总线。我使用的是来自微芯片的CAN总线分析仪来测试它。但是我不能得到PIC32 MZ来接收或发送数据。硬件似乎工作良好,因为其他人以前使用过它。如果有人用这个代码指出这个问题,那就太棒了。谢谢,Omkar J.。
以上来自于百度翻译 以下为原文 I have included the CAN bus code Im using for my PIC32mz, running at 100MHz, same for peripheral bus. I am using the CAN BUS analyzer from microchip trying to test it. But I cant get the the PIC32mz to either receive or transmit data. The hardware seems to be working fine as someone else has used it before. If someone could point out the issue with the code that would be awesome. Thanks, Omkar J. void can2_init() { //CAN2_RX TRISEbits.TRISE9 = 1; ANSELEbits.ANSE9 = 0; C2RXR = 0b1100; //CAN2_TX TRISEbits.TRISE8 = 0; ANSELEbits.ANSE8 = 0; RPE8R = 0b1111; CAN_BIT_CONFIG canBitConfig; CANEnableModule(CAN2, TRUE); //C2CONbits.ON = 1; CANSetOperatingMode(CAN2, CAN_CONFIGURATION); // C2CONbits.REQOP = 0b100; while (CANGetOperatingMode(CAN2) != CAN_CONFIGURATION); //while(C2CONbits.OPMOD != 0b100); canBitConfig.phaseSeg1Tq = CAN_BIT_3TQ; canBitConfig.phaseSeg2TimeSelect = TRUE; canBitConfig.phaseSeg2Tq = CAN_BIT_3TQ; canBitConfig.propagationSegTq = CAN_BIT_1TQ; canBitConfig.sample3Time = TRUE; canBitConfig.syncJumpWidth = CAN_BIT_1TQ; CANSetSpeed(CAN2, &canBitConfig, 100000000L , 125000L); CANAssignMemoryBuffer(CAN2, CanFifoMessageBuffers, 2 * 2 * CAN_TX_RX_MESSAGE_SIZE_BYTES); //CANEnableFeature(CAN2, CAN_STOP_IN_IDLE | CAN_RX_TIMESTAMP | CAN_WAKEUP_BUS_FILTER, FALSE); CANConfigureChannelForTx(CAN2, CAN_CHANNEL1, 2, CAN_TX_RTR_DISABLED, CAN_HIGHEST_PRIORITY); //Channel_1 is TX buffer CANConfigureChannelForRx(CAN2, CAN_CHANNEL0, 2, CAN_RX_FULL_RECEIVE); //Channel_0 is RX buffer CANConfigureFilter(CAN2, CAN_FILTER0, 0, CAN_SID); CANConfigureFilterMask (CAN2, CAN_FILTER_MASK0, 0x0, CAN_EID, CAN_FILTER_MASK_IDE_TYPE); //accept all messages CANLinkFilterToChannel(CAN2, CAN_FILTER0, CAN_FILTER_MASK0, CAN_CHANNEL0); CANEnableFilter (CAN2, CAN_FILTER0, TRUE); CANEnableChannelEvent (CAN2, CAN_CHANNEL0, (CAN_RX_CHANNEL_NOT_EMPTY|CAN_RX_CHANNEL_FULL), TRUE); CANEnableModuleEvent (CAN2, CAN_RX_EVENT, TRUE); // set interrupts C2INTbits.RBIF = 0; // clear level 2 interrupt flag C2INTbits.RBIE = 1; // enable level 2 interrupt IFS4bits.CAN2IF = 0; // clear level 1 interrupt flag IEC4bits.CAN2IE = 1; // enable level 1 interrupt IPC38bits.CAN2IP = 0b111; // priority 7 IPC38bits.CAN2IS = 0b00; // sub-priority 0 C2FIFOINT0bits.RXNEMPTYIF = 0; // clear level 3 interrupt flag C2FIFOINT0bits.RXNEMPTYIE = 1; // enable level 3 interrupt CANSetOperatingMode(CAN2, CAN_NORMAL_OPERATION); while (CANGetOperatingMode(CAN2) != CAN_NORMAL_OPERATION); serial_transmit("CAN Setup Donern"); }void send_can2() { CANTxMessageBuffer* buffer; buffer = CANGetTxMessageBuffer(CAN2, CAN_CHANNEL1); ; if (buffer != NULL) // NULL indicates Channel Full { /* Clear the message buffer. */ buffer->messageWord[0] = 0; buffer->messageWord[1] = 0; buffer->messageWord[2] = 0; buffer->messageWord[3] = 0; buffer->msgSID.SID = 0x100;/* Message SID */ message->msgEID.IDE = 0; buffer->msgEID.DLC = 7;/* Data Length is 2 */ message->msgEID.DLC = 2; message->msgEID.RTR = 0; message->msgEID.SRR = 0; message->data[0] = 0x13; message->data[1] = 0x00; message->data[2] = 0x15; message->data[3] = 0x01; message->data[4] = 0x01; message->data[5] = 0xF4; message->data[6] = 0x01; CANUpdateChannel(CAN2,CAN_CHANNEL1); CANFlushTxChannel(CAN2,CAN_CHANNEL1); } }void __attribute__((vector(_CAN2_VECTOR), interrupt(IPL7AUTO))) CAN2InterruptHandler(void) { serial_transmit("CAN_ISR"); if((CANGetModuleEvent(CAN2) & CAN_RX_EVENT) != 0) { if((CANGetPendingEventCode(CAN2) == CAN_CHANNEL0_EVENT)/* && (CANGetPendingEventCode(CAN1) == CAN_CHANNEL2_EVENT)*/) { CANEnableChannelEvent(CAN2, CAN_CHANNEL0, CAN_RX_CHANNEL_NOT_EMPTY, FALSE); } } IFS4bits.CAN2IF = 0; // clear level 1 interrupt flag } |
|
相关推荐
2个回答
|
|
1。确保IOLoCK(CFGCON & LT;13和GT)在您为CAN Tx和RX引脚配置PPS时不锁定。否则,你需要通过解锁序列。2。确保PBCK5被设置和启用。MZ有8个外围时钟,3个。如果项目从MX转换为PLIB支持,请确保更改MZ的CAN1/2基地址。它们应该是4。利用MZ的影子寄存器集(SRS)。启用所有它们,并相应地使用ISR 7级的所有5级。当你编写PIC32代码时,你不应该像这样清除任何中断标志,而是使用相应的CLR寄存器,例如,
以上来自于百度翻译 以下为原文 1. Make sure IOLOCK (CFGCON<13>) is not locked when you configure PPS for the CAN Tx and RX pins. Otherwise you need to go through unlocking sequence. 2. Make sure PBCLK5 is set and enabled. MZ has 8 peripheral clocks. 3. If the project was converted from the MX with PLIB support, make sure you change the CAN1/2 base addresses for the MZ. They should be #define _CAN1_BASE_ADDRESS 0xBF880000 #define _CAN2_BASE_ADDRESS 0xBF881000 4. Take advantage of the MZ's shadow register set (SRS). Enable all of them and use them accordingly for all 7 levels of ISRs. 5. When you write PIC32 code, you shouldn't clear any interrupt flag like this IFS4bits.CAN2IF = 0; // clear level 1 interrupt flag Instead, use the corresponding CLR register, e.g., IFS4CLR = _IFS4_CAN2IF_MASK; |
|
|
|
谢谢:我会做出建议的改变,让你知道它是否有效,我没有想到PPS的东西,但是时钟肯定是为所有外设启用的。代码已经被移植了,我想出了大部分。我以前没有用过,而且配置比O还难。我已经用过了。
以上来自于百度翻译 以下为原文 Thanks :) Ill make the suggested changes and let you know if it works, I did not think of the PPS thing, but the clocks is certainly enabled for all peripherals. The code hasent been ported and I came up with most of it. I havent used CAN before and the configuration is pretty tough compared to the others I have used. |
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
778浏览 1评论
671浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
597浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
679浏览 0评论
577浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 12:01 , Processed in 1.475808 second(s), Total 80, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号