Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/07/08 17:37
Read: times


 
#158910 - The code
Responding to: ???'s previous message
Hi,
These are the codes. I changed these files only.

I am making another board with mcu and e2prom only. I'm going to try to communicate with e2prom.

// Global Var
static unsigned char status;
static unsigned char i2cVetor[30];
unsigned int IndexRx;
unsigned int IndexTx;

// callback.c
/***********************************************************************
MODULE:    I2C Callback
VERSION:   1.03
CONTAINS:  Routines for controlling the I2C Peripheral on the Philips
           P89LPC952
COPYRIGHT: Embedded Systems Academy, Inc. - www.esacademy.com
LICENSE:   May be freely used in commercial and non-commercial code
           without royalties provided this copyright notice remains
           in this file and unaltered
WARNING:   IF THIS FILE IS REGENERATED BY CODE ARCHITECT ANY CHANGES
           MADE WILL BE LOST. WHERE POSSIBLE USE ONLY CODE ARCHITECT
           TO CHANGE THE CONTENTS OF THIS FILE
GENERATED: On "Sep 26 2008" at "22:08:21" by Code Architect 2.12
***********************************************************************/

#include "i2c.h"
#include "i2c_callback.h"

// MASTER CALLBACK FUNCTIONS

/***********************************************************************
DESC:    gets the next byte to be transmitted when operating as
         a master
RETURNS: byte to transmit (byte a ser transmitido)
************************************************************************/
unsigned char i2c_master_getbyte(unsigned int bytenum)  // number of the byte in this transfer // (0 = first byte)
{
  // insert code here


  return i2cVetor[bytenum];
} // i2c_master_getbyte

/***********************************************************************
DESC:    processes the bytes received when operating as a master
RETURNS: Nothing
************************************************************************/
void i2c_master_receivedbyte(unsigned int rbytenum, unsigned char value)    // number of the byte in this transfer // (0 = first byte) // value of byte received
{
  // insert code here
  i2cVetor[rbytenum]=value;
} // i2c_master_receivedbyte

/***********************************************************************
DESC:    determines if a byte will be the last one to be
         transmitted when operating as a master
         called before i2c_master_getbyte for each byte
RETURNS: return 1 if the byte will be the last one to transmit
         return 0 if the byte will not be the last one to transmit
************************************************************************/
unsigned char i2c_master_islasttxbyte(unsigned int tbytenum)    // number of the byte in this transfer // (0 = first byte)
{
  // insert code here
  if(tbytenum==(IndexTx-1))
    return(1);
  else
    return(0);
    
} // i2c_master_islasttxbyte

/***********************************************************************
DESC:    determines if a byte will be the last one to be
         received when operating as a master
         called before i2c_master_receivedbyte for each byte
RETURNS: return 1 if the byte will be the last one to receive
         return 0 if the byte will not be the last one to receive
************************************************************************/
unsigned char i2c_master_islastrxbyte(unsigned int rlbytenum)    // number of the byte in this transfer  // (0 = first byte)
{
  // insert code here
  if(rlbytenum==(IndexRx-1))
    return(1);
  else
    return(0);
} // i2c_master_islastrxbyte


/***********************************************************************
DESC:    called when an I2C transfer is finished
         mi2cstatus may be read to determine if the transfer was
         successful (I2C_OK) or failed (I2C_ERROR)
RETURNS: Nothing
************************************************************************/
void i2c_transfer_finished(void)
{
  // insert code here
  IndexTx=0;
  IndexRx=0;
  uart_transmit(mi2cstatus);
} // i2c_transfer_finished

// main.c
#define AT24C256 0xA0
#define TRUE 1
#define FALSE 0
#include "P89LPC95x.h"
#include "variaveis.c"
#include "uart.c"
#include "i2c_callback.c"
#include "i2c.c"

void main(void)
{
  unsigned int index;
  uart_init();
  i2c_init(AT24C256, 0);
  EA=1;
  IndexRx=30;
/*  i2c_transmit(0x00);
  while (i2c_getstatus() & I2C_BUSY);
  if (i2c_getstatus() == I2C_OK)

  i2c_transmit(0x30);
  while (i2c_getstatus() & I2C_BUSY);
  if (i2c_getstatus() == I2C_OK)*/

  i2c_receive(AT24C256);
  while(1);
}



Thanks


List of 51 messages in thread
TopicAuthorDate
Question about I2C code from Code Architect            01/01/70 00:00      
   these functions are like...            01/01/70 00:00      
      Some functions are not necessary ...            01/01/70 00:00      
         yes            01/01/70 00:00      
            Question about I2C (again)            01/01/70 00:00      
               do not fiddle with the SFRs            01/01/70 00:00      
            I2C and code architect            01/01/70 00:00      
               problens with I2C            01/01/70 00:00      
                  what tools do you have?            01/01/70 00:00      
                     Tools            01/01/70 00:00      
                        try smaller resistors            01/01/70 00:00      
                           I2C Code            01/01/70 00:00      
                              Update            01/01/70 00:00      
                              I2C Code            01/01/70 00:00      
   Problens in I2C            01/01/70 00:00      
   The code            01/01/70 00:00      
      other board, same problem            01/01/70 00:00      
         I do not recall, but have a look            01/01/70 00:00      
            Shifted            01/01/70 00:00      
               Issues            01/01/70 00:00      
                  Ok..more questions.            01/01/70 00:00      
                     I2C            01/01/70 00:00      
                        How to write ?            01/01/70 00:00      
   Always get IDLE status in I2C bus            01/01/70 00:00      
   Always get IDLE status in I2C bus            01/01/70 00:00      
      I2C Interrupt doesn't work.            01/01/70 00:00      
   HOW CAN I TEST I2C INTERRUPT?            01/01/70 00:00      
      It seems to me that ....            01/01/70 00:00      
         ok, I removed spy from I2C int            01/01/70 00:00      
            some code            01/01/70 00:00      
               I need baby steps now. I 'm staying crazy with it.            01/01/70 00:00      
                  getting less crazy            01/01/70 00:00      
   where is            01/01/70 00:00      
      I couldn't understand            01/01/70 00:00      
         things            01/01/70 00:00      
         Misunderstanding            01/01/70 00:00      
            if you have ICE or ...            01/01/70 00:00      
         Code            01/01/70 00:00      
   Your note to me            01/01/70 00:00      
   Baby steps again - I2C, the return            01/01/70 00:00      
      Understanding            01/01/70 00:00      
         Because...            01/01/70 00:00      
            Hmmm            01/01/70 00:00      
                I can see something finally !!!            01/01/70 00:00      
                  Breadboard            01/01/70 00:00      
                     solder joints            01/01/70 00:00      
                        by checking EVERY solder joint twice.            01/01/70 00:00      
   I checked all solder joint            01/01/70 00:00      
      look in the datasheet and find out how to make ...            01/01/70 00:00      
         I didn't get yet            01/01/70 00:00      
            Anyone?            01/01/70 00:00      

Back to Subject List