完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我已经移植了FATFS的PIC24示例,使用DSSPICEP256MU806。我正在尝试实现一个数据记录器,它将CAN总线消息写入SD卡。我可以打开和写入文件,但是在程序运行了几分钟之后(通常为6/7分钟),我得到了堆栈或地址错误陷阱。在我的程序开始时,我调用fyStand和fxOnter。在我的一段时间内(1),我接收CAN消息,把它们写入缓冲区,当我有2048字节时,我用FX写这些文件。每5秒我调用FY-Syc来把数据冲刷到卡上。IED注释FXWrand和FySalc部分,只留下初始FiStand和FyOnt,问题仍然存在。我已经单独测试了CAN代码,它没有问题。下面是代码:
以上来自于百度翻译 以下为原文 I've ported FatFs' pic24 example to use with dspic33ep256mu806. I'm trying to implement a data logger, that writes CAN bus messages to an SD card. I can open and write files, but I'm getting either stack or address error traps after my program as been running for a few minutes (typically 6/7 minutes). I'm doing the following: I call f_mount and f_open at the beginning of my program. On a while(1) in my main I receive CAN messages, write them to a buffer, and when I have 2048 bytes, I write those to the file, using f_write. Every 5 seconds I call f_sync to flush the data to the card. I've already tried to comment the f_write and f_sync parts, leaving only the initial f_mount and f_open, and the problem persists. I've tested the CAN code alone and it works without a problem. Here's the code: volatile uint8_t SDbuf[2100]; volatile int16_t pos = 0; uint16_t flush_count = 0; uint16_t sync_flag = 0; uint32_t time_ms = 0; FATFS FatFs; /* File system object */ FIL Fil2; void timer1_callback(){ disk_timerproc(); time_ms ++; flush_count ++; if(flush_count == 5000){ sync_flag = 1; flush_count = 0; } else return; } int main (void) { int can_line=0; int prev_priority; //variable used to check how many bytes were written to the sd card uint16_t bw; config_can(); int prev_priority = set_CPU_priority(7); f_open(&Fil2, "log_test.txt", FA_WRITE | FA_CREATE_ALWAYS); set_CPU_priority(prev_priority); //config 1ms timer for disk_timer_proc config_timer1(1, 4); enable_timer1(); while(1){ if (sync_flag == 1){ prev_priority = set_CPU_priority(7); f_sync(&Fil2); set_CPU_priority(prev_priority); sync_flag = 0; } if (!check_can()) { aux = pop_can(); sd_write(aux); } i = (i+1) % NUM_OF_CAN_LINES; ClrWdt(); } return 0; } int sd_digestCAN(CANdata CANmessage){ CANdata msg; SDbuf[pos] = CANmessage.sid >> 8; SDbuf[pos + 1] = CANmessage.sid; SDbuf[pos + 2] = CANmessage.dlc; SDbuf[pos + 3] = 0; SDbuf[pos + 4] = 0; SDbuf[pos + 5] = 0; SDbuf[pos + 6] = 0; SDbuf[pos + 7] = 0; SDbuf[pos + 8] = 0; SDbuf[pos + 9] = 0; SDbuf[pos + 10] = 0; //do NOT break! //set only the relevant values switch(CANmessage.dlc){ case 8: SDbuf[pos + 10] = CANmessage.data[3]; case 7: SDbuf[pos + 9] = CANmessage.data[3] >> 8; case 6: SDbuf[pos + 8] = CANmessage.data[2]; case 5: SDbuf[pos + 7] = CANmessage.data[2] >> 8; case 4: SDbuf[pos + 6] = CANmessage.data[1]; case 3: SDbuf[pos + 5] = CANmessage.data[1] >> 8; case 2: SDbuf[pos + 4] = CANmessage.data[0]; case 1: SDbuf[pos + 3] = CANmessage.data[0] >> 8; case 0: //nothing to do default: break; } /*Add the time stamp to the message*/ SDbuf[pos + 11] = time_ms&0xFF SDbuf[pos + 12] = time_ms >> 8; SDbuf[pos + 13] = time_ms >> 16; pos = pos + 14; return 15; } void sd_write(CANdata CANmessage){ sd_digestCAN(CANmessage); if(pos >= 2048){ /*since the optimal write size is multiples of 512, if pos is more than 2048, we write 2048 and save the excess bytes for the next write*/ int aux_pos = pos - 2048; int i = 0; while (i != aux_pos){ SDbuf = SDbuf[2048+i]; i++; } int prev_priority = set_CPU_priority(7); f_write(&Fil2,SDbuf,2048,&numread); set_CPU_priority(prev_priority); pos = 0; } else return; } |
|
相关推荐
3个回答
|
|
|
你看到陷阱在哪里了吗?要么用MPLAB,要么从陷阱中返回?
以上来自于百度翻译 以下为原文 Did you see where the Traps are happening? either with MPLab, or returning from the Trap? |
|
|
|
|
|
抱歉,迟了几天,没有互联网,我激活了陷阱。当前,在代码运行了10分钟后,我会收到地址错误。
以上来自于百度翻译 以下为原文 Sorry for the late response, been without internet for some days. I have traps activated. Currently I'm getting address error after the code has been running for like 10 minutes. |
|
|
|
|
|
如果你处理陷阱,你可以得到引起陷阱的地址。
以上来自于百度翻译 以下为原文 If you handle the traps you can get the address that caused the trap. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
508 浏览 0 评论
5813 浏览 9 评论
2351 浏览 8 评论
2238 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3545 浏览 3 评论
1163浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1122浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
890浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
508浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-15 12:32 , Processed in 1.102308 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1384