Need Some Serious Help (SD CARD)
Need Some Serious Help (SD CARD)
Hey Guys,
So I am a college student taking an introductory to robotics class. The beginning of the year we all had to purchase Netburner 5270. The end of the year has now come and we have a final project due and I am having some issues with my code (If this is not the right forum to post in my direct me towards the right one)
My code should be pretty simple (again this is my first time coding). All I want it to do is check the status of the pushbutton wired to J2{43} if it is pushed check the status of dipswitch 1. If it is on turn Led1 on, open the servo arm (OPEN DOOR), and create a text file on my sd write to the file and close the file.
My only problem is with the sd card. Randomly, say every 10th time I hit the pushbutton I will get an error closing my text file. This is my code with should create, write, and close the SD.
void f_open_PrintError(char* pFileName);
void f_close_PrintError(char* pFileName);
void Enter_Door(char * FileName) {
iprintf("\r\nCreating file: %s\r\n", FileName);
int i = 0;
F_FILE* fp;
do {
fp = f_open( FileName, "a+" ); // Creating and Opening File
i++;
if (fp == 0) { /// Does NOT open
OSTimeDly(TICKS_PER_SECOND / 2);
}
} while (fp == 0 && i < 5);
if (fp == 0) {
iprintf("\r\n Error in Opening:%s\r\n", FileName);
} else {
const unsigned int write_buffer_size = 100;
char write_buf[write_buffer_size];
sniprintf(write_buf, write_buffer_size, "Person Entered %d\r\n", Secs);
int n = f_write( write_buf, 1, strlen( write_buf ), fp );
iprintf("Wrote %d bytes: %s", n, write_buf);
iprintf("Closing file %s\r\n\r\n", FileName);
int rv = f_close( fp ); // Close a previously opened file of type F_FILE
do {
i++;
if (rv != 0) { // Does NOT close
OSTimeDly(TICKS_PER_SECOND / 2);
}
} while (rv != 0 && i > 10);
if (rv != 0) {
f_close_PrintError(FileName);
DisplayEffsErrorCode(rv);
}
}
The parts in red are what I most recently added. I did those parts because I thought if for some reason the file didnt close the first time through it would close the second time or something to that effect.
There are 3 errors that will sporadically appear on MTTY.
***Error in f_close(Enter.txt) during task(Main)
F_ERR_NOTOPEN
***Error in f_close(Enter.txt) during task(Main)
F_ERR_NOTFORMATED
***Error in f_close(Enter.txt) during task(Main)
F_ERR_WRITE
What really confuses me is I can push the pushbutton 15 times and it will write to the SD every time, but then the 16th time I will get an error, but then the 17th I wont have an error. Sometimes I will get two errors in a row too but then it will work again. I really have no clue how to fix this.
I am sorry that this is such a long post. If anyone has any ideas I would really appricaite it I am very stressed out about this problem. I didnt include my entire code this is just the function which is supposed to do all of this, but I can send the rest of my code if anyone thinks it would help them.
Also as I said I am completely new to coding so if there is another forum anyone would suggest to help me with my issue I would love to hear about it.
(This is being written on NBeclipse)
Thanks
Ben
So I am a college student taking an introductory to robotics class. The beginning of the year we all had to purchase Netburner 5270. The end of the year has now come and we have a final project due and I am having some issues with my code (If this is not the right forum to post in my direct me towards the right one)
My code should be pretty simple (again this is my first time coding). All I want it to do is check the status of the pushbutton wired to J2{43} if it is pushed check the status of dipswitch 1. If it is on turn Led1 on, open the servo arm (OPEN DOOR), and create a text file on my sd write to the file and close the file.
My only problem is with the sd card. Randomly, say every 10th time I hit the pushbutton I will get an error closing my text file. This is my code with should create, write, and close the SD.
void f_open_PrintError(char* pFileName);
void f_close_PrintError(char* pFileName);
void Enter_Door(char * FileName) {
iprintf("\r\nCreating file: %s\r\n", FileName);
int i = 0;
F_FILE* fp;
do {
fp = f_open( FileName, "a+" ); // Creating and Opening File
i++;
if (fp == 0) { /// Does NOT open
OSTimeDly(TICKS_PER_SECOND / 2);
}
} while (fp == 0 && i < 5);
if (fp == 0) {
iprintf("\r\n Error in Opening:%s\r\n", FileName);
} else {
const unsigned int write_buffer_size = 100;
char write_buf[write_buffer_size];
sniprintf(write_buf, write_buffer_size, "Person Entered %d\r\n", Secs);
int n = f_write( write_buf, 1, strlen( write_buf ), fp );
iprintf("Wrote %d bytes: %s", n, write_buf);
iprintf("Closing file %s\r\n\r\n", FileName);
int rv = f_close( fp ); // Close a previously opened file of type F_FILE
do {
i++;
if (rv != 0) { // Does NOT close
OSTimeDly(TICKS_PER_SECOND / 2);
}
} while (rv != 0 && i > 10);
if (rv != 0) {
f_close_PrintError(FileName);
DisplayEffsErrorCode(rv);
}
}
The parts in red are what I most recently added. I did those parts because I thought if for some reason the file didnt close the first time through it would close the second time or something to that effect.
There are 3 errors that will sporadically appear on MTTY.
***Error in f_close(Enter.txt) during task(Main)
F_ERR_NOTOPEN
***Error in f_close(Enter.txt) during task(Main)
F_ERR_NOTFORMATED
***Error in f_close(Enter.txt) during task(Main)
F_ERR_WRITE
What really confuses me is I can push the pushbutton 15 times and it will write to the SD every time, but then the 16th time I will get an error, but then the 17th I wont have an error. Sometimes I will get two errors in a row too but then it will work again. I really have no clue how to fix this.
I am sorry that this is such a long post. If anyone has any ideas I would really appricaite it I am very stressed out about this problem. I didnt include my entire code this is just the function which is supposed to do all of this, but I can send the rest of my code if anyone thinks it would help them.
Also as I said I am completely new to coding so if there is another forum anyone would suggest to help me with my issue I would love to hear about it.
(This is being written on NBeclipse)
Thanks
Ben
Re: Need Some Serious Help (SD CARD)
Are you using a development board? J2[43] (IRQ1) is connected to the RTC on the Dev 70 board.
Re: Need Some Serious Help (SD CARD)
The SD card driver uses the SPI port on the MOD5270. You're not using any of those pins for other things are you? The F_ERR_NOTFORMATTED can crop up when the card's been detected but the device receives a garbled/nonsense/zeroed response when trying to read the File Table on the card.
Also, what NNDK version are you using? There's a minor issue in the FAT_File library on build 2.6.0 that's pending a full release/beta. If you're using that, pm me / open a support ticket, and I can send you the patch.
Also, we're really going to need more info on this program/device of yours in order to help further.
Also, what NNDK version are you using? There's a minor issue in the FAT_File library on build 2.6.0 that's pending a full release/beta. If you're using that, pm me / open a support ticket, and I can send you the patch.
Also, we're really going to need more info on this program/device of yours in order to help further.
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc
Re: Need Some Serious Help (SD CARD)
Hey Guys,
Thanks for your help. I will try to give you as much information as I can, just let me know what you need (again I am very new to this so hardly know what alot of this stuff even means/does). Most of the code I have written has been me altering examples that my professor has given in class to work for my own unique project. Again any tips or suggestions would be awesome
I have a NetBurner 5270
MOD-DEV-70
REV 1.7
NBeclipseIDE release 2.6
The pushbutton is hooked up to J2[43].
The servo is hooked up to J2[36]
This is my SD card function
_____________________________________________________________
I call it in my Control.cpp with my Control_Enter Function
}
}
_______________________________________________________________
I call that in my user main.cpp
_________________________________________________________________
Thanks for your help. I will try to give you as much information as I can, just let me know what you need (again I am very new to this so hardly know what alot of this stuff even means/does). Most of the code I have written has been me altering examples that my professor has given in class to work for my own unique project. Again any tips or suggestions would be awesome
I have a NetBurner 5270
MOD-DEV-70
REV 1.7
NBeclipseIDE release 2.6
The pushbutton is hooked up to J2[43].
The servo is hooked up to J2[36]
This is my SD card function
Code: Select all
void Enter_Door(char * FileName) {
iprintf("\r\nCreating file: %s\r\n", FileName);
int i = 0;
F_FILE* fp;
do {
fp = f_open( FileName, "a+" ); // Creating and Opening File
i++;
if (fp == 0) { /// Does NOT open
OSTimeDly(TICKS_PER_SECOND / 20);
}
} while (fp == 0 && i < 5);
if (fp == 0) {
iprintf("\r\n Error in Opening:%s\r\n", FileName);
} else {
const unsigned int write_buffer_size = 100;
char write_buf[write_buffer_size];
sniprintf(write_buf, write_buffer_size,
"Person Entered at %ld seconds\r\n", Secs);
int n = f_write( write_buf, 1, strlen( write_buf ), fp );
iprintf("Wrote %d bytes: %s", n, write_buf);
iprintf("Closing file %s\r\n\r\n", FileName);
// Close a previously opened file of type F_FILE
int rv;
do {
rv = f_close( fp );
int i = 0;
i++;
if (rv != 0) { /// Does NOT close
OSTimeDly(TICKS_PER_SECOND / 20);
}
} while (rv != 0 && i < 5);
if (rv != 0) {
f_close_PrintError(FileName);
DisplayEffsErrorCode(rv);
}
}
}
I call it in my Control.cpp with my Control_Enter Function
Code: Select all
void Control_Enter (void){
if(getdipsw() == DIPSWITCH_0){
LEDmask = LED0_ON;
putleds(LEDmask);
SetServoChannel(0,147456);
Enter_Door();
iprintf("Person Entered at time =%d\n\r",Secs);
}
_______________________________________________________________
I call that in my user main.cpp
Code: Select all
#define UCOS_STACKCHECK
#include <ucos.h>
#include "predef.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <taskmon.h>
#include <smarttrap.h>
#include "cardtype.h"
#include <effs_fat/fat.h>
#ifdef USE_MMC
#include <effs_fat/mmc_mcf.h>
#endif
#ifdef USE_CFC
#include <effs_fat/cfc_mcf.h>
#endif
#include <ftpd.h>
#include "ftp_f.h"
#include "effs_time.h"
#include "FileSystemUtils.h"
#include <myreadwritetest.h>
// me
#include <pins.h>
#include "Control.h"
#include "Servo.h"
# define BUTTON_IS_PUSHED (J2[43]==0)
# define BUTTON_IS_RELEASED (J2[43]==1)
extern "C"
{
void UserMain( void* pd );
}
#ifdef USE_MMC
const char* AppName = "Final Project";
#endif
#ifdef USE_CFC
const char* AppName = "EFFS FTP CFC";
#endif
#define FTP_PRIO ( MAIN_PRIO - 2 )
/*-------------------------------------------------------------------
UserMain()
-------------------------------------------------------------------*/
void UserMain( void* pd )
{
InitializeStack();
OSChangePrio( MAIN_PRIO );
EnableAutoUpdate();
EnableTaskMonitor();
EnableSmartTraps();
iprintf( "\r\n===== Starting %s Program =====\r\n", AppName );
f_enterFS();
// We now must also enter the file system for the FTP task
OSChangePrio( FTP_PRIO );
f_enterFS();
OSChangePrio( MAIN_PRIO );
InitExtFlash(); // Initialize the CFC or SD/MMC external flash drive
int status = FTPDStart( 21, FTP_PRIO );
if ( status == FTPD_OK )
{
iprintf("You can use Internet Explorer to drag and drop files to url \"ftp://");
ShowIP(EthernetIP);
iprintf("\"\r\n");
}
CalcServoRefValuesForPeriodMinZeroMax(0.02, 0.001, 0.0015, 0.002);
InitDToutServos(RefTicksInServoMin,
RefTicksInServoZero,
RefTicksInServoMax,
RefTicksInServoMax );
while ( 1 )
{
if(BUTTON_IS_PUSHED){
//OSDumpTasks();
Control_Enter();
Control_Alert();
OSTimeDly( TICKS_PER_SECOND *5);
//pause for 5 sec
}
else if (BUTTON_IS_RELEASED){
Control_LetBe();
}
}
}
Re: Need Some Serious Help (SD CARD)
Actually, mirroring what ecasey said, pin J2[43] is hooked up to IRQ1 on the MOD5270. If you really want to use it as a polled GPIO, you'll want to add the line
This will set the pin as GPIO. It's possible that it's in interrupt mode, but you're still able to read it and you're having issues because it's triggering an interrupt mid read/write from the SD card.
Code: Select all
J2[43]=PINJ2_43_GPIO;
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc
Re: Need Some Serious Help (SD CARD)
shouldn't that be
?
Code: Select all
J2[43].function(PINJ2_43_GPIO);
Re: Need Some Serious Help (SD CARD)
I think roland.ames is correct.
Ben,
The problem you describe does look like it's hardware related. Some suggestions:
1. Make sure you have nothing connected to J2[25], J2[27] or J2[28] - as Dan points out, those are used by the SD driver and any signal on them will definately cause the errors you describe, which could be totally random. Look for inadvertant sources such as dust, something on the bench under the board, etc. that might be shorting those pins. If you are using cabling that connects to those pins, check for shorts and possibly noise.
2. I would use a non-IRQ pin for the push-button, but in any case, I wouldn't use J2[43] (IRQ1) because it is conntected to the real time clock with a 10k pull-up resistor and could cause problems (perhaps not now, but if you ever wanted to use the RTC...)
3. Regardless of what pin you use, it is good practice to condition the pin explicitly using the PINIO class function call that roland.ames described, even if GPIO is the default for the pin.
4. I would try a differnt SD card, it could be faulty.
Hope this is helpful
Ed
Ben,
The problem you describe does look like it's hardware related. Some suggestions:
1. Make sure you have nothing connected to J2[25], J2[27] or J2[28] - as Dan points out, those are used by the SD driver and any signal on them will definately cause the errors you describe, which could be totally random. Look for inadvertant sources such as dust, something on the bench under the board, etc. that might be shorting those pins. If you are using cabling that connects to those pins, check for shorts and possibly noise.
2. I would use a non-IRQ pin for the push-button, but in any case, I wouldn't use J2[43] (IRQ1) because it is conntected to the real time clock with a 10k pull-up resistor and could cause problems (perhaps not now, but if you ever wanted to use the RTC...)
3. Regardless of what pin you use, it is good practice to condition the pin explicitly using the PINIO class function call that roland.ames described, even if GPIO is the default for the pin.
4. I would try a differnt SD card, it could be faulty.
Hope this is helpful
Ed
Re: Need Some Serious Help (SD CARD)
roland.ames is correct. My mistake.
To answer the issue, and spread the word a bit, the problem lies in the fact that the hardware is utilizing all 4 DMA timers, in conjunction with the SD card.
Specifically the issue is with DTOUT2, the output of DMA timer 2. If you take a look at the schematic for the dev board, you'll see that the chip select pin for the SD card socket is
J2[35]. You'll also notice that this is the same pin as... DTOUT2. So what happens is that while the timer creates the PWM for the servo it's also toggling the CS for the SD card. It's asserted enough of the time to give the appearance of the SD card working, but it actuality that CS has been taken over by the timer.
Long story short, if you want to use DMA timer 2 to toggle a pin and an SD card, you need to move the SD card's CS pin away from the default.
To answer the issue, and spread the word a bit, the problem lies in the fact that the hardware is utilizing all 4 DMA timers, in conjunction with the SD card.
Specifically the issue is with DTOUT2, the output of DMA timer 2. If you take a look at the schematic for the dev board, you'll see that the chip select pin for the SD card socket is
J2[35]. You'll also notice that this is the same pin as... DTOUT2. So what happens is that while the timer creates the PWM for the servo it's also toggling the CS for the SD card. It's asserted enough of the time to give the appearance of the SD card working, but it actuality that CS has been taken over by the timer.
Long story short, if you want to use DMA timer 2 to toggle a pin and an SD card, you need to move the SD card's CS pin away from the default.
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc
Re: Need Some Serious Help (SD CARD)
But
, or did I miss something?The servo is hooked up to J2[36]
Re: Need Some Serious Help (SD CARD)
Sorry, there was some out of channel communications, which has the source code was running all 4 DMA Timers.
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc