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

FT245rl driver

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



Joined: 25 Jan 2010
Posts: 36

View user's profile Send private message

FT245rl driver
PostPosted: Fri Feb 05, 2010 3:39 am     Reply with quote

hi all

I've searched for a existing c driver for the ft245 but I didn't find something.


If you have comments to modify the driver so that you can ad this to the code library, only say it.
At the time, I have no possibility to make also a rx-interrupt routine because I have some problem with the sprut burner.


best regards
P51D

driver:
Code:

//*****************************************************************************
// Definitionen
#define TXE                PIN_D9                        // Transmitt-enabmle pin
#define WR                 PIN_D11                       // Write pin (high peak)
#define RX                 PIN_D8                        // Receive data Pin
#define RD                 PIN_D10                       // Read pin (during read low)
#define PWREN              PIN_F6                        // configurations-status
#define USART_DDR_out      set_tris_d(0x0000 | (1<<9) | (1<<8))
#define USART_DDR_in       set_tris_d(0x00FF | (1<<9) | (1<<8))

#define D0                 PIN_D0                        // Data-Pins
#define D1                 PIN_D1
#define D2                 PIN_D2
#define D3                 PIN_D3
#define D4                 PIN_D4
#define D5                 PIN_D5
#define D6                 PIN_D6
#define D7                 PIN_D7

#define rxBuf_max          100                           // buffer size
static int8 index_rxBuf_R = 0;                           // Index to write RX-Buffer
static int8 index_rxBuf_W = 0;                           // Index to read RX-Buffer
int8 rxBuf[rxBuf_max + 1];                               // RX-Buffer
#define txBuf_max          10                            // buffer size
static int8 index_txBuf_R = 0;                           // Index to write TX-Buffer
static int8 index_txBuf_W = 0;                           // Index to read TX-Buffer
int8 txBuf[txBuf_max + 1];                               // TX-Buffer
//*****************************************************************************
// Functions
//=========== INIT ====================================
void ft245_init(void){
   int8 i = 0;
   USART_DDR_in;                                         // Default DDR = input
   output_high(RD);                                      // set control-pins
   output_low(WR);
   for(i=0;i<=txBuf_max;i++){                            // clear buffers
      txBuf[i] = 0;
   }
   i = 0;
   for(i=0;i<=rxBuf_max;i++){
      rxBuf[i] = 0;
   }
   while(input_state(PWREN) == 1);                       // wait until the USB FTDI-configuration
}
//=========== TX ====================================
// if no new data, return / need to calls in the main
void usart_tx(void){                                     // send-function
   if(input_state(TXE) == 0){                            // if sending possible
      if(index_txBuf_R == index_txBuf_W){                // no new data => return
         return;
      }
      if(index_txBuf_R == txBuf_max){                    // ringbuffer
         index_txBuf_R = 0;
      }
      else{
         index_txBuf_R ++;
      }
      USART_DDR_out;                                     // change ddr from input to output
      output_bit(D0,(txBuf[index_txBuf_R] & 0x01));      // write datas to the ftdi
      output_bit(D1,(txBuf[index_txBuf_R] & 0x02));
      output_bit(D2,(txBuf[index_txBuf_R] & 0x04));
      output_bit(D3,(txBuf[index_txBuf_R] & 0x08));
      output_bit(D4,(txBuf[index_txBuf_R] & 0x10));
      output_bit(D5,(txBuf[index_txBuf_R] & 0x20));
      output_bit(D6,(txBuf[index_txBuf_R] & 0x40));
      output_bit(D7,(txBuf[index_txBuf_R] & 0x80));
      output_high(WR);                                   // new data available
      output_low(WR);
      USART_DDR_in;                                      // set ddr to input
   }
}
void txBuf_write(int8 parameter){                        // TX buffer handling
   if(index_txBuf_W == txBuf_max){                       // ringbuffer
      index_txBuf_W = 0;
   }
   else{
      index_txBuf_W ++;
   }
   txBuf[index_txBuf_W] = parameter;
}
//=========== RX ====================================
// need to calls in the main
void usart_rx(void){                                     // read function (polling)
   int8 data = 0;                                        // data
   if(input_state(RX) == 0){                             // if new data in the FTDI buffer
      if(index_rxBuf_W == rxBuf_max){                    // ringbuffer
         index_rxBuf_W = 0;
      }
      else{
         index_rxBuf_W ++;
      }
// take datas and set it dynamic in the buffer
      output_low(RD);                                    // read data
      delay_cycles(1);
      if(input_state(D0) == 1) data |= (1 << 0);
      if(input_state(D1) == 1) data |= (1 << 1);
      if(input_state(D2) == 1) data |= (1 << 2);
      if(input_state(D3) == 1) data |= (1 << 3);
      if(input_state(D4) == 1) data |= (1 << 4);
      if(input_state(D5) == 1) data |= (1 << 5);
      if(input_state(D6) == 1) data |= (1 << 6);
      if(input_state(D7) == 1) data |= (1 << 7);
      rxBuf[index_rxBuf_W] = data;                       // store data
      output_high(RD);                                   // read finished
   }
}
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