CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Vdrive2 and 16f1824
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

Vdrive2 and 16f1824
PostPosted: Tue Feb 26, 2013 7:07 am     Reply with quote

I would like to store some data on a 64MB flash drive and I think that a Vdrive2 is an easy solution for that.

I've based my software on the software in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=43446&highlight=vdrive2

Here is my (shortened) code:
Code:

#use rs232(baud=9600, xmit=PIN_A0)

int data = 42;

delay_ms(8000);

// create file and open it
printf("OPW test.txt");

// write to file
printf("WRF ");

putc(0x00); // number of bytes of data
putc(0x00);
putc(0x00);
putc(0x02); // two bytes (1) data (2) carriage return

putc(0x0d); // carriage return

printf("%u\t", data); // send data to the text.txt file
putc(0x0d); // carriage return

// close the file
printf("CLF test.txt");
putc(0x0d); // carriage return

while(1);


When I put the oscilloscope on my pin 13 I see data coming out after 8 seconds. So the hardware seems to be fine. I have Uart/SPI pin pulled up to 3V3 for Uart mode.

I've also tried to burn the new firmware in the Vdrive2. And I choose the following mode:

Code:

Firmware Settings

Firmware Version: 03.69-001 (Modified)

Firmware Type: VDAP FTD Upgrader File for Main Code

Default Monitor Settings: 9600 baud, 8 bits, 1 stop bit, no parity, no flow control

Initial Mode: ECS, IPA, LED Flash at Power-on

Options: Allow Firmware Upgrades, Allow Data Mode,
Show Prompt, Show Device Connects/Removals, Show Version Report at Startup.



The Led of the Vdrive turns green when I apply power and flashed one time after 8 seconds, but there is no test.txt on my flash drive.

VCC = 5V, but my micro is running at 3V3 so my tx is at 3V3.

Is there anyone who knows what I did wrong?

CCS 4.132
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 26, 2013 8:56 am     Reply with quote

I've changed my VCC of my micro from 3V3 to 5V and now I get a test.txt on my flash disk. It's only empty. Anyone?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Feb 26, 2013 10:36 am     Reply with quote

You are not sending the size correctly. The size is hex not binary. _Text_.

So:
Code:

int16 size=2;
//This is what you need if size is going to vary in the future
printf("WRF %04x\r",size);

//or for the fixed value
printf(WRF 0002\r");


Beware also your data size. You are sending more than two characters.....

Best Wishes
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 3:02 am     Reply with quote

I tried some different things with the printf function, but stil no data in the text file.

Code:
int data = 42;

// create file and open it
printf("OPW test.txt");

// write to file
printf("WRF 2\r");

printf("%u\r", data); // send data to the text.txt file

// close the file
printf("CLF test.txt");

while(1);


I've put the carriage return values also in the printf function. Maybe the data must be in binary instead of ASCII (which it is now I think). But how can that be done?

Quote:
Data to write to the file is taken directly from the Monitor input and written to the file. There is no conversion from ASCII to binary in IPA mode nor is a carriage return required after writing the data to the Monitor port.
In this example, the command is given in ECS mode, the data size in ASCII mode and the data is represented in binary values.

WRF 10
01 02 03 04 05 06 07 08 09 0a
<prompt>

In SCS mode and IPH mode (values in Binary Mode are sent MSB first):
08 20 00 00 00 0A 0d
01 02 03 04 05 06 07 08 09 0a
<prompt>
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 3:44 am     Reply with quote

The WRF command _requires four hex digits for size_.
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 4:02 am     Reply with quote

I also tried your suggestion

Code:
printf("WRF 0002\r");


and

Code:
int16 size=2;
//This is what you need if size is going to vary in the future
printf("WRF %04x\r",size);


But with this printf functions it also don't work.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 4:40 am     Reply with quote

See the other part of my comment. Your data size is _wrong_.

Best Wishes
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 5:29 am     Reply with quote

Sorry Ttelmah....I don't get it...and thank you for your patience.

Code:
int data = 42


Is this wrong, or is the number of ascii values which I send to the flash disk?

Code:
printf("WRF 0002\r");
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 6:08 am     Reply with quote

Number of bytes you send.

Seriously, try printing the value to a string, and looking at how big it is. Remember also that things like a tab and a line feed are also characters.....
Far better, to sprintf the data to a string, then use strlen, to specify the size you are going to write to the drive, which will calculate the value for you.

Best Wishes
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 8:37 am     Reply with quote

I've tried some things:

Code:
int data = 42;
char strData[20];
char sData[20];
char Line[] = "\r";
int16 size=0;

delay_ms(8000);

// create file and open it
printf("OPW test.txt\r");

sprintf(sData,"%u", data);
strcat(sData, Line);
size = strlen(sData);

// write to file
printf("WRF %04x\r",size);

// send data to the text.txt file
printf("%u\r", data);

// close the file
printf("CLF test.txt\r");

while(1);


This was the output with a hyperterminal kind of program:

Code:
OPW test.txt
WRF 0003
42
CLF test.txt


But I did one stupid thing...connecting the Vdrive with the power on my controller. Now the led of the Vdrive keeps blinking when I write to it. I tried to flash new firmware in it, but it doesn't help.
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 9:39 am     Reply with quote

The Vdrive is running again...something strange with the C code. But still no data in the text file.
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 5:24 am     Reply with quote

I finally got it working (still without a string, but that's for later)!

But now another question:

is:

putc(0x06);

a different value then:

putc(6);

or

putc('6'); //this is 0x36 I think, so this is a different value.

For the length of the bytes who are transmitted, you must specify the number of bytes. But the first is working and the second not.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 8:50 am     Reply with quote

6, 0x6, 0b0110 are all the same. Just different representations of the same binary number.
'6' is the text (ASCII) character.

Best Wishes
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Mar 04, 2013 4:44 am     Reply with quote

Why I asked this:

this is working:
Code:
printf("WRF ");
putc(0x00); // number of bytes of data
putc(0x00);
putc(0x00);
putc(size);
putc('\r');


and this not:
Code:

printf("WRF %04x\r",size);


size is in both situations int16.

I can't see the difference, but maybe anyone else...
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Mar 04, 2013 8:32 am     Reply with quote

putc sends a binary value, not a hex digit.
However I'm surprised the latter works, since this 'disagrees' with what the Vdrive manual says....
However the command with printf, would be something like:
Code:

printf("WRF \0\0%c%c\r"size/256,size);
//That will handle sizes up to 65535, rather than the 256 you were using
//Or with putc
putc(0);
putc(0);
putc(size/256);
putc(size);


Syntactically, I'd slightly prefer to use make8, to fetch the bytes, but the compiler will automatically optimise /256 to a high byte fetch, so it is 'acceptable ish'.
Putting '0x' into a putc, says 'treat the number as hex', but 0x0, 0, '\0', '0b0', etc., are all the same number. It doesn't affect what is sent at all.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group