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

Any help on I2C Interrupt?

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



Joined: 07 Sep 2003
Posts: 51

View user's profile Send private message Yahoo Messenger

Any help on I2C Interrupt?
PostPosted: Mon Oct 06, 2003 12:35 am     Reply with quote

Mabuhay!

Anybody in this forum who can provide help such that the code below will be converted to... using I2C interrupt.

I have an 8 chips network using I2C protocol and I want to use the interrupt during the writing and reading of the FM24C256 from Ramtron?

Anyone who can help... a sample code is a good start for me...

My code is below:

Quote:

/***************
* Include File *
***************/

#include <18F452.H> // type of PIC use in this project


/*************************************************
* Compiler Directives and Hardware Configuration *
*************************************************/

//#device ICD=TRUE // with an ICD debugger
#fuses HS,NOLVP,NOWDT,PUT // high speed, no watch dog timer
#use delay (clock=20000000) // 20MHz clock

/* use serial port monitor for debugging */
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)

/* I2C Configuration */
#ifndef F_RAM_SDA

// for software I2C
//#define F_RAM_SDA PIN_B1
//#define F_RAM_SCL PIN_B0

/* for hardware I2C */
#define F_RAM_SDA PIN_C4 // i2c data
#define F_RAM_SCL PIN_C3 // i2c clock
#define F_RAM_WP PIN_C5 // write protect

#endif

/* use I2C protocol using hardware */
#use i2c(master,sda=F_RAM_SDA, scl=F_RAM_SCL, FORCE_HW, FAST)

//#zero_ram // optional pre-processor declaration


/****************
* Include Files *
****************/

#include <GET_FUNCTION.C> // get function driver
#include <LCD.C> // lcd display driver


/************************
* Defines and Constants *
************************/

/* memory page length in bytes */
#define FRAM_PAGE_LENGTH 32 // page length in bytes

/* memory PAGE COUNT IN NUMBER OF PAGES */
#define FRAM_PAGE_ONE 1024 // number of pages for 1 chip
#define FRAM_PAGE_COUNT 8192 // number of pages for 8 chips

/* total number of chips */
#define FRAM_CHIP_COUNT 8 // total number of chips

/* define a byte to write at F-RAM for R/W test */
#define DATA_TEST_x55 0x55
#define DATA_TEST_xAA 0xAA

/* define F-RAM address and size */
//#define F_RAM_ADDRESS long int
//#define F_RAM_SIZE 32768
#define F_RAM_ADDRESS int32
#define F_RAM_SIZE 262144

/* define I2C read/write address */
#define F_WR_ADDRESS 0xA0 // initial F-RAM write address at 1st chip
#define F_RD_ADDRESS 0xA1 // initial F-RAM read address at 1st chip

/* F-RAM Initialization */
void init_ext_f_ram()
{
output_float(F_RAM_SCL);
output_float(F_RAM_SDA);
}


/* memory write by address routine */
void memory_write_by_addr(int32 i32Address, byte bData)
{
int8 iChipselect;

// Determine which chip to address
iChipselect = (F_WR_ADDRESS | make8(i32Address<<2,2)) & 0xFE;

output_low(F_RAM_WP); // set write protect low

while (TRUE)
{
i2c_start();
// look for the ACK from the device to ensure the
// devide is ready
if (i2c_write(iChipselect ) == 0) break;
}

// Max of 32K of address. The MSB is handled in the iChipselect
i2c_write((make8(i32Address,1)) & 0x7F);
i2c_write(make8(i32Address,0));
i2c_write(bData);
i2c_stop();

output_high(F_RAM_WP); // set write protect high
}


/* memory read by address routine */
byte memory_read_by_addr(int32 i32Address)
{
byte bData;
int8 iChipselect;

// Determine which chip to address
iChipselect = (0xA0 | make8(i32Address<<2,2)) & 0xFE;

while (TRUE)
{
i2c_start();
// look for the ACK from the device to ensure the
// devide is redy
if (i2c_write(iChipselect) == 0) break;
}

// Max of 32K of address. The MSB is handled in the iChipselect
i2c_write((make8(i32Address,1)) & 0x7F);
i2c_write(make8(i32Address,0));
i2c_start();

// set the LSB for reading
i2c_write(iChipselect | 0x01);
bData=i2c_read(0);
i2c_stop();
return(bData);
}


/* write memory byte routine */
void write_memory_byte(long int liAddress,byte bData,int iNew_wr_addr)
{
short int siStatus;

output_low(F_RAM_WP); // set write protect low

while (TRUE) {

i2c_start();
// look for the ACK from the device to ensure the
// devide is redy
if (i2c_write(iNew_wr_addr) == 0) break;
}

i2c_write(liAddress>>8);
i2c_write(liAddress);
i2c_write(bData);
i2c_stop();

output_high(F_RAM_WP); // set write protect high
}


/* read memory byte routine */
byte read_memory_byte(long int liAddress,int iNew_wr_addr)
{
byte bData;

while (TRUE)
{
i2c_start();
// look for the ACK from the device to ensure the
// devide is redy
if (i2c_write(iNew_wr_addr) == 0) break;
}

i2c_write(liAddress>>8);
i2c_write(liAddress);
i2c_start();
i2c_write((iNew_wr_addr | 0x01));
bData=i2c_read(0);
i2c_stop();
return(bData);
}



I appreciate any help on how can I convert this code such that it will utilize the I2C interrupt (#INT_SSP)...

I really need help here... a sample code will be great!!! as a start for me..

BTW, the PIC18F452 will act as the master.... my application is just write, read and read/write testing to FRAM chip using I2C interrupt..

Note I have the 8 chip wired to have their own addresses....

Thnx[/quote]
Guest








PostPosted: Mon Oct 06, 2003 7:44 pm     Reply with quote

Hello !!!

I need ur help on I2C interrupt for writing and reading to external memory of 32K size... PIC controller is a master...

Thnx
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