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 support@ccsinfo.com

How to transfer text files between pic18f2620 & ftp ser

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
haseeb



Joined: 27 Apr 2011
Posts: 19

View user's profile Send private message

How to transfer text files between pic18f2620 & ftp ser
PostPosted: Thu Jun 16, 2011 5:50 am     Reply with quote

hello

I'm planning on a new project.

I want to setup a simple ftp communication from the pic to an ftp server.
Data to be sent will be simple txt files and no picture.
The pic is a PIC18F2620. I plan on using a GPRS modem that can support ftp protocol such as the Cinterion BG2 wireless module.
I will be using the CCS compiler.

Please can someone point me in the right direction on how to achieve
this task?

Haseeb
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 16, 2011 7:36 am     Reply with quote

google !
haseeb



Joined: 27 Apr 2011
Posts: 19

View user's profile Send private message

PostPosted: Thu Jun 16, 2011 8:36 am     Reply with quote

I have googled it and could not find a 'point in the direction' sort
of link.

Can anyone please help me?

Haseeb
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 16, 2011 9:36 am     Reply with quote

googled 'PIC C code ftp server program' and came up with 900,000 + hits

several in the top 50 are GREAT resources for you..

others might be as well...

Since I have no real idea as to what you really want or need , I suggest you look at some of the 900,000 hits from above as what I think you want has been done a zillion times before,maybe not with your exact hardware but it's not 'rocket science' as the saying goes.
haseeb



Joined: 27 Apr 2011
Posts: 19

View user's profile Send private message

PostPosted: Thu Jun 16, 2011 9:59 am     Reply with quote

ok thank you so much, i will do what you have said and if needed
will get back to....thanks ever so much with your help.

Haseeb
haseeb



Joined: 27 Apr 2011
Posts: 19

View user's profile Send private message

PostPosted: Thu Sep 08, 2011 5:51 am     Reply with quote

Hello


I have now managed to read in 'OK' replies from the modem successfully and I have confirmed this with the texting
mode as that works brilliantly. I can read in modem replies successfully via hyper terminal.


Anyway my main problem is with ftp and I’m enclosing in the program code for you all to have a look at.


Basically I just want to send some data (byte or a string) from my PIC to my ftp site and would like to have that
appear in the ftp root directory as a standard txt file.


From my source code, going all the way down and just before ‘problem 1’, I’m getting OK replies from the modem.
But from ‘Problem 1 ’ and ‘Problem 2’ I’m getting ERROR messages. I’m using CCS compiler and PIC18F2620 with internal
OSC @ 4MHz. The modem im using is the Cinterion BG2 modem and it supports ftp.


Please can you help me to achieve this ftp task.


Thank you
Haseeb


Code:

#include <18F2620.h>


#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOPUT, NOPBADEN 

// Set Speed to 4Mhz
#use delay(clock=4000000)

// RS232 to Modem
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_B5, STREAM=Modem)
// RTS232 to User Port
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_C7, STREAM=User)
 




void Main (void)
{


 char char1;  //variable to store the modem ASCII incoming byte



 //configure I/O directions
  set_tris_A(0b00000001);
    set_tris_B(0b00100111);     
    set_tris_C(0b11011000);

 

 disable_interrupts(GLOBAL);  // disable all interupts


 
 delay_ms(100); //startup delay



 //turning off all LEDs
 output_low(pin_A1);
 output_low(pin_A2);
 output_low(pin_A3);
 output_low(pin_A4);



 //Powering up modem...
 output_high(pin_C1);    // Turn on Regulator
 output_high(pin_C5);   // Turn on Pwrkey
 Delay_ms(1000);     // wait 3 sec
 output_low(pin_C5);    // Turn off Pwrkey
 Delay_ms(3000);     // wait 3 sec
 output_high(pin_C5);   // Turn on Pwrkey 
 delay_ms(30000);    // wait for modem to establish connection




 //modem power up indicator
 output_high(pin_A1);
 delay_ms(500);
 output_low(pin_A1);
 



 
 
 




 
 // configure apn.......


 fprintf(Modem,"AT^SICS=0,conType,GPRS0\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));     //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen   

   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SICS=0,apn,\"greeninternet\"\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));     //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }
 
 fprintf(Modem,"AT^SICS=0,user,userid\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SICS=0,passwd,2110\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }











 // configure internet sevice..........

 fprintf(Modem,"AT^SISS=0,srvType,none\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }
 
 fprintf(Modem,"AT^SISS=0,srvType,ftp\r\n");
 
 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SISS=0,alphabet,1\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SISS=0,conId,0\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SISS=0,tcpMR,3\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }
 
 fprintf(Modem,"AT^SISS=0,tcpOT,3000\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SISS=0,address,\"ftp://232.127.159.192;type=d\"\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }



 // connnect to service...........

 fprintf(Modem,"AT^SISO=0\r\n"); 

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(5000);

   break;
 
  }           

 }








//problem 1


 fprintf(Modem,"AT^SISS=0,address,\"ftp://232.127.159.192/haseeb;type=a\"\r\n");
 
 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  //if(char1 == 'K') 
  //{
 
   fprintf(User,"%c",char1); // print to screen
   
  // delay_ms(100);

  // break;
 
  //}           

 }




//problem 2

 
 // wait for urc then receive some data.........

 fprintf(Modem,"at^sisr=0,1500\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
     
  //if(char1 == 'K')
  //{
 
   fprintf(User,"%c",char1); // print to screen
   
  // delay_ms(100);

  // break;
 
  //}           

 }

 












 // close connection.........
 //at^sisc=0







 while(TRUE); //stay here forever






}

temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Sep 08, 2011 6:47 am     Reply with quote

a few comments...

get rid of the set_tris().. code ! Unless you're an experienced programmer, those commands will 'get you' sooner or later. Let the compiler automatically handle it !!

you need ISRs WITH ring buffers to make real progress. CCS supplies working examples in the example folder.

be aware that during all delay_ms(nnn) functions the PIC will do NOTHING but waste time,so you need to have ISRs for the serial ports else you will miss data.

also always add ERRORS to the use rs232(options), else the UART will 'hang' after 2 characters come in.

be sure to have current limiting resistors for all LEDs. 'Funny' things can happen without them !!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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