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

verification of typemod and fram

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



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

verification of typemod and fram
PostPosted: Fri Feb 24, 2006 3:10 pm     Reply with quote

Could someone with fram on there system check this. It seems when I use typemod and local (to main) vars the system works. When I change the to globals, the last entry of the list presents an incorrect value
Code:
#include <18F452.H>
#case
#use delay(clock=40000000)
#fuses h4,nowdt,noprotect,nolvp
#use rs232(baud=19200,xmit=PIN_C0,invert,stream=DEBUG,disable_ints) // stderr(same as debug)
#zero_ram
int8 ERRORS;
#define FRAM_CHIPS 4
//#include "FM24C256.C"
#include <74595.C>
//----------prototypes--------
void init_fram();
multi_read_fram(int32 address,int8 *data,int8 size);
multi_write_fram(int32 address,int8 *data,int8 size);
//----//
typemod <,multi_read_fram, multi_write_fram,0,131071> fram;
//place int8 fram here for global variable
//======================= MAIN ============================//
void main(void)
{

  int8 fram f_1,fram f_2,fram f_3,fram f_4,fram f_5;
  int16 cnt;
  setup_adc_ports(NO_ANALOGS);
  set_tris_a(0);set_tris_b(0);set_tris_c(0);set_tris_d(0);set_tris_e(0);
  output_low(PIN_C5);//tx enable
  output_high(PIN_C6);
  fprintf(DEBUG,"Start!\n\r");
  init_fram();
  f_1=1;
  f_2=2;
  f_3=3;
  f_4=4;
  f_5=5;
  for(cnt=0;cnt<12;cnt++);
  fprintf(DEBUG,"%u %u %u %u %u\n\r",f_1,f_2,f_3,f_4,f_5);
  fprintf(DEBUG,"DONE !\n\r");
  while(1)
  {
  }
}
#ifndef FRAM_SDA
#define FRAM_SDA  PIN_C4
#define FRAM_SCL  PIN_C3
#endif
#use I2C(MASTER,SDA=FRAM_SDA,SCL=FRAM_SCL,FORCE_HW,FAST=1000000,RESTART_WDT)
#define FRAM_ADDRESS int32
#define FRAM_SIZE    32768
#ifndef FRAM_CHIPS
#define FRAM_CHIPS   1
#endif
#define FRAM_MAX_ADDRESS (FRAM_SIZE*FRAM_CHIPS)-1 //4 chips 0,1,2,3
#define hi(x)  (*(&x+1))  //data held at addr of x + 1
#define lo(x)  (*(&x))    //data held at addr of x

//======================init_fram===========================//
void init_fram(){
  output_float(FRAM_SCL);
  output_float(FRAM_SDA);
}
//======================multi_read_fram===========================//
//start addr 0,32768,65536,98304,131072,163840,196608,229376
multi_read_fram(int32 address,int8 *data,int8 size){
  int8 start_size;
  //fprintf(DEBUG,"-mr-");
  start_size=size;
  for(;size;data++,size--,address++)
  {
    if(address>FRAM_MAX_ADDRESS){
      bit_set(ERRORS,4);
      //fprintf(DEBUG,"ERROR address too big!\n\r%lu\n\r",address);
    }
    if(address%FRAM_SIZE==0 || size==start_size){
      //fprintf(DEBUG,"sending slave address=%lu\n\r",address);
      i2c_start();
      i2c_write((0xA0|(int8)(address>>14))&0xFE);//&0xFE forces to write
      i2c_write(hi(address));
      i2c_write(lo(address));
      i2c_start();
      i2c_write((0xA0|(int8)(address>>14))|1);//|1 forces to read
    }
    if((address+1)%FRAM_SIZE && size!=1)
    {
      *data=i2c_read(1);//The ack will put next data on bus
      //fprintf(DEBUG,"read with ack %lu=%u\n\r",address,*data);
    }
    else
    {
      *data=i2c_read(0);//No ack on last read of chip
      //fprintf(DEBUG,"read without ack %lu=%u\n\r",address,*data);
      //fprintf(DEBUG,"I2c stop\n\r");
      i2c_stop();
    }
  }
  //fprintf(DEBUG,"-mr- done!\n\r");
  //return(TRUE);
}
//======================multi_write_fram===========================//
multi_write_fram(int32 address,int8 *data,int8 size)
{
  int8 start_size;
  start_size=size;
  //fprintf(DEBUG,"-mw- %lu %lu\n\r",address,size);
  for(;size;data++,size--,address++){
    if(address>FRAM_MAX_ADDRESS){
      bit_set(ERRORS,4);
      //fprintf(DEBUG,"ERROR address too big!\n\r%lu\n\r",address);
    }
    if(address%FRAM_SIZE==0 || size==start_size){

      //fprintf(DEBUG,"I2c stop\n\r");
      i2c_stop();
      //fprintf(DEBUG,"I2c start\n\r");
      i2c_start();
      //fprintf(DEBUG,"sending slave address=%lu\n\r",address);
      i2c_write((0xA0|(int8)(address>>14))&0xFE);
      i2c_write(hi(address));
      i2c_write(lo(address));
    }
    i2c_write(*data);
    //fprintf(DEBUG,"wrote %u\n\r",*data);
  }
  i2c_stop();
  //fprintf(DEBUG,"dmw\n\r");
  //return(TRUE);
}
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