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

I2c between 18F452(Master) and 16F877 (Slave)

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



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

I2c between 18F452(Master) and 16F877 (Slave)
PostPosted: Sun Aug 05, 2007 6:38 am     Reply with quote

I have used the code suggested by PCM Programmer in old posts, which is given below:

Code:
#include "18F452.h"
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_D0, scl=PIN_D1)

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
//!#use fast_io(D)
#use fast_io(E)
//====================================
void main()
{
   int8 data;
   SET_TRIS_A(0);
   SET_TRIS_B(0);
   SET_TRIS_C(0);
   SET_TRIS_E(0); 

   PORTA=0;
   PORTB=0;

   PORTC=0xFF;
   PORTD=0;
   PORTE=0;
   delay_ms(500);
   
   // Write the letter 'B' to the slave board.
   i2c_start();
   i2c_write(0xA0);
   i2c_write(0x00);
   i2c_write('B');
   i2c_stop();
   // Read from the slave board and display the data.
   i2c_start();
   i2c_write(0xA0);
   i2c_write(0x00);
   i2c_start();
   i2c_write(0xA1);
   data = i2c_read(0);
   i2c_stop();
  PORTC='B';
  PORTB=data;
   while(TRUE);     
}     

The slave code is EX_SLAVE.C with the modification for Pins for SDA and SCL as per the master code.

The Pin connections are:
1. Have SDA on the Slave connected to SDA on the master.
2. Have SCL on the Slave connected to SCL on the master.
3. SDA and SCL pulled up.

The problem is that the data shown on PORTC & B are different.
Need help...
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Aug 05, 2007 7:01 am     Reply with quote

Quote:
The slave code is EX_SLAVE.C with the modification for Pins for SDA and SCL as per the master code.
Sorry, but I can't follow you here. Your slave is a PIC16F877, right? Than why do you change the pin settings for the slave? ex_slave.c was designed for a PIC16F877, changing the pins means you can't use the hardware I2C unit anymore and the interrupt won't work. I'm confused...
AdamkT1



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Sun Aug 05, 2007 7:31 am     Reply with quote

Can I put it like this That:
For I2c to work on 16F877(Slave), the only pins that can be used for communications are PIN_C4(SDA) & PIN_C3(SCL) and these pins cannot be changed.

Thank you.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Aug 05, 2007 5:07 pm     Reply with quote

AdamkT1 wrote:
Can I put it like this That:
For I2c to work on 16F877(Slave), the only pins that can be used for communications are PIN_C4(SDA) & PIN_C3(SCL) and these pins cannot be changed.
-- Assuming this is a question. -- In short, yes. Save yourself a lot of troubles and use the mentioned hardware pins for an I2C slave.

An I2C master is relative easy to implement and if you don't want to use the designated hardware than the CCS compiler will generate the code for you.
An I2C slave is a whole different story and a lot more difficult. I don't know if the CCS compiler will generate the code for you, at least it can not use interrupts so the given example code is not going to work. The efficient I2C hardware is there in your chip, why not use it?
AdamkT1



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Sun Aug 05, 2007 8:28 pm     Reply with quote

Thank you
AdamkT1



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Mon Aug 06, 2007 6:44 am     Reply with quote

This is an SOS call.
I could'nt make the code to work despite countless tries with the code and the readings of posts in this forum for I2C comm.
As per Ckielstra's suggestion, I have changed the slave code to ex_Slave.c but still no good.
For the master, I have done some minor changes in the code, which are:
1) Put the IO directions statements except for PORTC & Put known values on all PORTS.
2) I’ve put the statements inside a while loop.
3) Display the data being sent & received on PORTD & B respectively.
I am pasting both of the codes for help and to ensure that I have not done any mistakes.
In the slave code the changes are:
1) Put the IO directions statements except for PORTC & Put known values on all PORTS.
Master code:
Code:
#include "18F452.h"
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3,SLOW)

#use fast_io(A)
#use fast_io(B)
#use fast_io(D)
#use fast_io(E)
//====================================
void main()
{
int8 data;
SET_TRIS_A(0);
SET_TRIS_B(0);
SET_TRIS_D(0);
SET_TRIS_E(0); 
PORTA=0;
PORTB=0;

PORTC=0;
PORTD=0;
PORTE=0;
delay_ms(500);
while(TRUE)
{

      // Write the letter 'B' to the slave board.
      i2c_start();
      i2c_write(0xA0); //device address
      i2c_write(0); //address of the eeprom byte
      i2c_write('B'); //the letter to write
      i2c_stop();
DELAY_MS(500);       
      // Read from the slave board and display the data.
      i2c_start();
      i2c_write(0xA0);
      i2c_write(0x00);
      i2c_start();
      i2c_write(0xA1);
      data = i2c_read(0);
      i2c_stop();
DELAY_MS(500);       
   PORTD='B';
   PORTB=data;
   delay_ms(100);
   PORTA=~PORTA;
   }   
}     

Slave code:
Code:
#include "16F877.h"
#use delay(clock=4000000)
#fuses XT,NOWDT
 
#use i2c(SLAVE,address=0XA0,sda=PIN_C4,scl=PIN_C3,slow)
#use fast_io(A)
#use fast_io(B)
#use fast_io(D)
#use fast_io(E)

BYTE address, buffer[0x10];

#INT_SSP
void ssp_interupt ()
{
   BYTE incoming, state;

   state = i2c_isr_state();

   if(state < 0x80)                     //Master is sending data
   {
      incoming = i2c_read();
      if(state == 1)                     //First received byte is address
         address = incoming;
      if(state == 2)                     //Second received byte is data
         buffer[address] = incoming;
   }
   if(state == 0x80)                     //Master is requesting data
   {
      i2c_write(buffer[address]);
   }
}


void main()
{
SET_TRIS_A(0);
SET_TRIS_B(0);
SET_TRIS_D(0);
SET_TRIS_E(0); 
PORTA=0;
PORTB=0xFF;
PORTC=0;
PORTD=0;
PORTE=0;
delay_ms(200);
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
WHILE(TRUE)
{
   PORTB=Buffer[0];
} //end while

}


Connection:
I have connected master's SDA & SCL with slave's SDA & SCL respectively and also have pulled them up by 4.7K resistors.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 06, 2007 7:30 am     Reply with quote

- Your code is not complete; where are the definitions for PORTA, PORTB, etc. ?
- What is your compiler version?
- Add NOLVP to your slave code or the PIC will stall with a voltage spike on the LVP input pin.

Try only to implement optimizations when you do have a working program, for example get rid of the FASTIO commands, these might conflict with compiler settings for the I2C ports.

Side note: from a quick glance it looks like your program should be ok, but when things are not working try to stay as close as possible to the original code. You made many more changes than mentioned. Maybe your changes make the code smaller but I don't have the time to compare every line to the original.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 06, 2007 12:43 pm     Reply with quote

I just did some testing between two 18F452's, with the Ex_Slave.c code
in one, and my Master test code in the other.

The Slave has to run at a minimum of 8 MHz for it to work.

The CCS file, Ex_Slave.c has the slave running at 20 MHz.
You've reduce it to 4 MHz. So, I think that's the problem.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Aug 06, 2007 2:45 pm     Reply with quote

The slave needs a certain amount of time to respond to the I2C bus commands. It's most likely that the master is sending each command faster than the slave can react to them. Try placing delays after each command, in the master code, and see if that gets things talking.

If you have a scope, very helpful in this type of situation, monitor the I2C bus and an unused pin of the slave. Have that pin pulsed while inside of the ISR of the slave. This will let you know how the slave's timing corresponds with the master's commands. I had a similar problem and needed to slow the master down enough for the slave to have time to process the ISR.

Ronald
AdamkT1



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 2:55 am     Reply with quote

I appreciate your help and the pains you people have to take for me.
Thank you all.
The conditions are the same here and no change in the output so far.

On PIN_C7 I get two types of pulse trains, I shall try to describe them with respect to SCL :
1)-5V at PIN_C7 at t=40ms (relative to SCL) and remains low for 80ms and the go up at t=120ms
2)-5V at PIN_C7 at t=40ms (relative to SCL) and remains low for 40ms and go up at t=80ms
SCL =-5v at t=0 and remains for 40ms,0v at t=0+40ms,-5v at t=0+40 and remains there until t=0+40ms+40ms,0V at t=0+40ms+40ms,-5v at t=0+40ms+40ms and remains there until t=0+40ms+40ms+40ms and then transitions to 0V.

The Slave Code:

#
Code:
include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
//!#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xa0)

BYTE address, buffer[0x10];
int8 Flg;

#INT_SSP
void ssp_interupt ()
{
   BYTE incoming, state;

   state = i2c_isr_state();

   if(state < 0x80)                     //Master is sending data
   {
      incoming = i2c_read();
      if(state == 1)                     //First received byte is address
         address = incoming;
      if(state == 2)                     //Second received byte is data
         buffer[address] = incoming;
   }
   if(state == 0x80)                     //Master is requesting data
   {
      i2c_write(buffer[address]);
   }
   if (Flg==0)
   {
   output_low(PIN_C7); 
   }
   else   
   output_high(PIN_C7);
   Flg=~Flg;
}

void main ()
{
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_SSP);

   while (TRUE) ;
}


Master code is:
Code:
#include "18F452.h"
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3,slow)

#use fast_io(A)
#use fast_io(B)
//!#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
//====================================
void main()
{
   int8 data;
   SET_TRIS_A(0);
   SET_TRIS_B(0);
   SET_TRIS_D(0);   
   SET_TRIS_E(0); 

   PORTA=0;
   PORTB=0;

   PORTC=0;
   PORTD=0;
   PORTE=0;
   delay_ms(500);
   while(TRUE)
   {
   // Write the letter 'B' to the slave board.
   i2c_start();
   i2c_write(0xA0);
   i2c_write(0x00);
   i2c_write('B');
   i2c_stop();
   // Read from the slave board and display the data.
   i2c_start();
   i2c_write(0xA0);
   i2c_write(0x00);
   i2c_start();
   i2c_write(0xA1);
   data = i2c_read(0);
   i2c_stop();
  PORTD='B';
  PORTB=data;
   }     
}


The 18F452 header file:
Code:
#define PIN_A0  31744
#define PIN_A1  31745
#define PIN_A2  31746
#define PIN_A3  31747
#define PIN_A4  31748
#define PIN_A5  31749
#define PIN_A6  31750

#define PIN_B0  31752
#define PIN_B1  31753
#define PIN_B2  31754
#define PIN_B3  31755
#define PIN_B4  31756
#define PIN_B5  31757
#define PIN_B6  31758
#define PIN_B7  31759

#define PIN_C0  31760
#define PIN_C1  31761
#define PIN_C2  31762
#define PIN_C3  31763
#define PIN_C4  31764
#define PIN_C5  31765
#define PIN_C6  31766
#define PIN_C7  31767

#define PIN_D0  31768
#define PIN_D1  31769
#define PIN_D2  31770
#define PIN_D3  31771
#define PIN_D4  31772
#define PIN_D5  31773
#define PIN_D6  31774
#define PIN_D7  31775

#define PIN_E0  31776
#define PIN_E1  31777
#define PIN_E2  31778

////////////////////////////////////////////////////////////////// Useful defines
#define FALSE 0
#define TRUE 1

#define BYTE int
#define BOOLEAN short int

#define getc getch
#define fgetc getch
#define getchar getch
#define putc putchar
#define fputc putchar
#define fgets gets
#define fputs puts

////////////////////////////////////////////////////////////////// Control
// Control Functions:  RESET_CPU(), SLEEP(), RESTART_CAUSE()
// Constants returned from RESTART_CAUSE() are:

#define WDT_TIMEOUT       7   
#define MCLR_FROM_SLEEP  11   
#define MCLR_FROM_RUN    15   
#define NORMAL_POWER_UP  12   
#define BROWNOUT_RESTART 14   
#define WDT_FROM_SLEEP   3     
#define RESET_INSTRUCTION 0   

////////////////////////////////////////////////////////////////// Timer 0
// Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER_0(),
//                              SET_TIMER0() or SET_RTCC(),
//                              GET_TIMER0() or GET_RTCC()
// Constants used for SETUP_TIMER_0() are:
#define RTCC_INTERNAL   0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48

#define RTCC_DIV_1      8
#define RTCC_DIV_2      0
#define RTCC_DIV_4      1
#define RTCC_DIV_8      2
#define RTCC_DIV_16     3
#define RTCC_DIV_32     4
#define RTCC_DIV_64     5
#define RTCC_DIV_128    6
#define RTCC_DIV_256    7

#define RTCC_OFF        0x80 

#define RTCC_8_BIT      0x40 

// Constants used for SETUP_COUNTERS() are the above
// constants for the 1st param and the following for
// the 2nd param:

////////////////////////////////////////////////////////////////// WDT
// Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
//                            RESTART_WDT()
//
#define WDT_ON      0x100   
#define WDT_OFF     0       

////////////////////////////////////////////////////////////////// Timer 1
// Timer 1 Functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1
// Constants used for SETUP_TIMER_1() are:
//      (or (via |) together constants from each group)
#define T1_DISABLED         0
#define T1_INTERNAL         0x85
#define T1_EXTERNAL         0x87
#define T1_EXTERNAL_SYNC    0x83

#define T1_CLK_OUT          8

#define T1_DIV_BY_1         0
#define T1_DIV_BY_2         0x10
#define T1_DIV_BY_4         0x20
#define T1_DIV_BY_8         0x30

////////////////////////////////////////////////////////////////// Timer 2
// Timer 2 Functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2
// Constants used for SETUP_TIMER_2() are:
#define T2_DISABLED         0
#define T2_DIV_BY_1         4
#define T2_DIV_BY_4         5
#define T2_DIV_BY_16        6

////////////////////////////////////////////////////////////////// Timer 3
// Timer 3 Functions: SETUP_TIMER_3, GET_TIMER3, SET_TIMER3
// Constants used for SETUP_TIMER_3() are:
//      (or (via |) together constants from each group)
#define T3_DISABLED         0
#define T3_INTERNAL         0x85
#define T3_EXTERNAL         0x87
#define T3_EXTERNAL_SYNC    0x83

#define T3_DIV_BY_1         0
#define T3_DIV_BY_2         0x10
#define T3_DIV_BY_4         0x20
#define T3_DIV_BY_8         0x30

////////////////////////////////////////////////////////////////// CCP
// CCP Functions: SETUP_CCPx, SET_PWMx_DUTY
// CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
// Constants used for SETUP_CCPx() are:
#define CCP_OFF                         0
#define CCP_CAPTURE_FE                  4
#define CCP_CAPTURE_RE                  5
#define CCP_CAPTURE_DIV_4               6
#define CCP_CAPTURE_DIV_16              7
#define CCP_COMPARE_SET_ON_MATCH        8
#define CCP_COMPARE_CLR_ON_MATCH        9
#define CCP_COMPARE_INT                 0xA
#define CCP_COMPARE_INT_AND_TOGGLE      0x2       
#define CCP_COMPARE_RESET_TIMER         0xB
#define CCP_PWM                         0xC
#define CCP_PWM_PLUS_1                  0x1c
#define CCP_PWM_PLUS_2                  0x2c
#define CCP_PWM_PLUS_3                  0x3c
#define CCP_USE_TIMER3                  0x100       
long CCP_1;
#byte   CCP_1    =                      0xfbe       
#byte   CCP_1_LOW=                      0xfbe       
#byte   CCP_1_HIGH=                     0xfbf       
long CCP_2;
#byte   CCP_2    =                      0xfbb       
#byte   CCP_2_LOW=                      0xfbb       
#byte   CCP_2_HIGH=                     0xfbc       
////////////////////////////////////////////////////////////////// PSP
// PSP Functions: SETUP_PSP, PSP_INPUT_FULL(), PSP_OUTPUT_FULL(),
//                PSP_OVERFLOW(), INPUT_D(), OUTPUT_D()
// PSP Variables: PSP_DATA
// Constants used in SETUP_PSP() are:
#define PSP_ENABLED                     0x10
#define PSP_DISABLED                    0

#byte  PSP_DATA=    0xF83               

////////////////////////////////////////////////////////////////// SPI
// SPI Functions: SETUP_SPI, SPI_WRITE, SPI_READ, SPI_DATA_IN
// Constants used in SETUP_SPI() are:
#define SPI_MASTER       0x20
#define SPI_SLAVE        0x24
#define SPI_L_TO_H       0
#define SPI_H_TO_L       0x10
#define SPI_CLK_DIV_4    0
#define SPI_CLK_DIV_16   1
#define SPI_CLK_DIV_64   2
#define SPI_CLK_T2       3
#define SPI_SS_DISABLED  1

#define SPI_SAMPLE_AT_END 0x8000
#define SPI_XMIT_L_TO_H  0x4000

////////////////////////////////////////////////////////////////// UART
// Constants used in setup_uart() are:
// FALSE - Turn UART off
// TRUE  - Turn UART on
#define UART_ADDRESS           2
#define UART_DATA              4
////////////////////////////////////////////////////////////////// VREF
// Constants used in setup_low_volt_detect() are:
//
#define LVD_LVDIN   0x1F
#define LVD_46 0x1E
#define LVD_43 0x1D
#define LVD_41 0x1C
#define LVD_40 0x1B
#define LVD_37 0x1A
#define LVD_36 0x19
#define LVD_34 0x18
#define LVD_31 0x17
#define LVD_29 0x16
#define LVD_28 0x15
#define LVD_26 0x14
#define LVD_25 0x13
#define LVD_23 0x12
#define LVD_21 0x11



////////////////////////////////////////////////////////////////// INTERNAL RC
// Constants used in setup_oscillator() are:
#define OSC_TIMER1  1
#define OSC_NORMAL  0


////////////////////////////////////////////////////////////////// ADC
// ADC Functions: SETUP_ADC(), SETUP_ADC_PORTS() (aka SETUP_PORT_A),
//                SET_ADC_CHANNEL(), READ_ADC()
// Constants used for SETUP_ADC() are:
#define ADC_OFF                 0              // ADC Off
#define ADC_CLOCK_DIV_2   0x10000
#define ADC_CLOCK_DIV_4    0x4000
#define ADC_CLOCK_DIV_8    0x0040
#define ADC_CLOCK_DIV_16   0x4040
#define ADC_CLOCK_DIV_32   0x0080
#define ADC_CLOCK_DIV_64   0x4080
#define ADC_CLOCK_INTERNAL 0x00c0              // Internal 2-6us

// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS                           7    // None
#define ALL_ANALOG                           0    // A0 A1 A2 A3 A5 E0 E1 E2
#define AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF 1    // A0 A1 A2 A5 E0 E1 E2 VRefh=A3     
#define AN0_AN1_AN2_AN3_AN4                  2    // A0 A1 A2 A3 A5         
#define AN0_AN1_AN2_AN4_VSS_VREF             3    // A0 A1 A2 A5 VRefh=A3             
#define AN0_AN1_AN3                          4    // A0 A1 A3
#define AN0_AN1_VSS_VREF                     5    // A0 A1 VRefh=A3
#define AN0_AN1_AN4_AN5_AN6_AN7_VREF_VREF 0x08    // A0 A1 A5 E0 E1 E2 VRefh=A3 VRefl=A2     
#define AN0_AN1_AN2_AN3_AN4_AN5           0x09    // A0 A1 A2 A3 A5 E0       
#define AN0_AN1_AN2_AN4_AN5_VSS_VREF      0x0A    // A0 A1 A2 A5 E0 VRefh=A3           
#define AN0_AN1_AN4_AN5_VREF_VREF         0x0B    // A0 A1 A5 E0 VRefh=A3 VRefl=A2           
#define AN0_AN1_AN4_VREF_VREF             0x0C    // A0 A1 A5 VRefh=A3 VRefl=A2             
#define AN0_AN1_VREF_VREF                 0x0D    // A0 A1 VRefh=A3 VRefl=A2
#define AN0                               0x0E    // A0
#define AN0_VREF_VREF                     0x0F    // A0 VRefh=A3 VRefl=A2
#define ANALOG_RA3_REF         0x1         //!old only provided for compatibility
#define A_ANALOG               0x2         //!old only provided for compatibility 
#define A_ANALOG_RA3_REF       0x3         //!old only provided for compatibility 
#define RA0_RA1_RA3_ANALOG     0x4         //!old only provided for compatibility
#define RA0_RA1_ANALOG_RA3_REF 0x5         //!old only provided for compatibility
#define ANALOG_RA3_RA2_REF              0x8   //!old only provided for compatibility
#define ANALOG_NOT_RE1_RE2              0x9   //!old only provided for compatibility 
#define ANALOG_NOT_RE1_RE2_REF_RA3      0xA   //!old only provided for compatibility 
#define ANALOG_NOT_RE1_RE2_REF_RA3_RA2  0xB   //!old only provided for compatibility 
#define A_ANALOG_RA3_RA2_REF            0xC   //!old only provided for compatibility 
#define RA0_RA1_ANALOG_RA3_RA2_REF      0xD   //!old only provided for compatibility
#define RA0_ANALOG                      0xE   //!old only provided for compatibility
#define RA0_ANALOG_RA3_RA2_REF          0xF   //!old only provided for compatibility


// Constants used in READ_ADC() are:
#define ADC_START_AND_READ     7   // This is the default if nothing is specified
#define ADC_START_ONLY         1
#define ADC_READ_ONLY          6



////////////////////////////////////////////////////////////////// INT
// Interrupt Functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(),
//                      EXT_INT_EDGE()
//
// Constants used in EXT_INT_EDGE() are:
#define L_TO_H              0x40
#define H_TO_L                 0
// Constants used in ENABLE/DISABLE_INTERRUPTS() are:
#define GLOBAL                    0xF2C0
#define INT_RTCC                  0xF220
#define INT_TIMER0                0xF220
#define INT_TIMER1                0x9D01
#define INT_TIMER2                0x9D02
#define INT_TIMER3                0xA002
#define INT_EXT                   0xF210
#define INT_EXT1                  0xF008
#define INT_EXT2                  0xF010
#define INT_RB                    0xFFF208
#define INT_PSP                   0x9D80
#define INT_AD                    0x9D40
#define INT_RDA                   0x9D20
#define INT_TBE                   0x9D10
#define INT_SSP                   0x9D08
#define INT_CCP1                  0x9D04
#define INT_CCP2                  0xA001
#define INT_BUSCOL                0xA008
#define INT_LOWVOLT               0xA004
#define INT_EEPROM                0xA010

#byte TMR0 = 0x01
#byte PCL = 0x02
#byte STATUS = 0x03
#byte FSR = 0x04

#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#byte PCLATH= 0x0a

#byte INTCON3= 0xFF0
#byte INTCON2= 0xFF1
#byte INTCON = 0xFF2


#byte TRISA = 0xF92
#byte TRISB = 0xF93

#byte TRISC = 0xF94
#byte TRISD = 0xF95
#byte TRISE = 0xF96


#list


I have tried delays between the write functions but get the same result, that is PORTB remains at 0x00 all the time
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 6:49 am     Reply with quote

- Again, what is your compiler version?
- In the master code you have fuse XT for 8MHz. For stable operation change this to the HS fuse.
- One important difference between your code and extee.c is that the example code is testing the slave to be ready before transmitting new commands to the slave. You don't do this test.
- It is bad programming practice to modify the processor include file as supplied with your compiler. In the situation where you ever would upgrade to another compiler version there is a good chance that the include file changes as well, now you are going to miss these changes with undefined behavior as a result.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 1:45 pm     Reply with quote

1. Are you testing this in hardware, or is this being done in Proteus ?


2. The lines shown in bold below are incorrect for the 18F452.
Quote:
#byte TMR0 = 0x01
#byte PCL = 0x02
#byte STATUS = 0x03
#byte FSR = 0x04

#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#byte PCLATH= 0x0a

#byte INTCON3= 0xFF0
#byte INTCON2= 0xFF1
#byte INTCON = 0xFF2


#byte TRISA = 0xF92
#byte TRISB = 0xF93

#byte TRISC = 0xF94
#byte TRISD = 0xF95
#byte TRISE = 0xF96
AdamkT1



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 6:25 pm     Reply with quote

I am testing it in PROTEUS. I am sorry for not mentioning.
Thank you very much.
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