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 CCS Technical Support

PIC 16F677 I2C ssp isr not working...

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



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

PIC 16F677 I2C ssp isr not working...
PostPosted: Thu May 03, 2007 2:08 pm     Reply with quote

Hello all,

I'm using the following setup:
an 18F65J10 as the I2C master,
18F44J10 as one I2c slave (addr 0x40)

and a 16F677 as an I2c slave (addr 0x20)


The 18F65J10 & 18F44J10 are working properly with test code where the 65j10 sends out data to 0x20, then to 0x40 like so:


******************************
Master pic code:

Code:

#include "C:\temp\i2Cattempt2-logic-exp\master\main.h"
#include<stdio.h>
//#int_TIMER0
//void  TIMER0_isr(void)
//{

//}

/*#int_SSP
void  SSP_isr(void)
{

}
*/


void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
  // enable_interrupts(INT_TIMER0);
  // enable_interrupts(INT_SSP);
   //enable_interrupts(GLOBAL);
   setup_oscillator(False);

   // TODO: USER CODE!!


   while(1)
   {
   int slaveaddress1;
   int slavetestdata1;
   int slaveaddress2;
   int slavetestdata2;
   int slavetestdata3;

   slaveaddress1 = 0x40;
   slaveaddress2 = 0x20;
   slavetestdata1 = 5;
   slavetestdata2 = 7;   
   slavetestdata3 = 9;

     delay_ms(1000); 
      i2c_start();
      i2c_write(slaveaddress1);
     delay_ms(10);   
     i2c_write(slavetestdata1);
      i2c_stop();
   printf("\n\r I2C Comms 1 complete"); 
    
     delay_ms(1000); 
      i2c_start();
      i2c_write(slaveaddress2);
     delay_ms(10);   
     i2c_write(slavetestdata2);
      i2c_stop();
   printf("\n\r I2C Comms 2 complete");


     delay_ms(1000); 
      i2c_start();
      i2c_write(slaveaddress1);
     delay_ms(10);   
     i2c_write(slavetestdata3);
      i2c_stop();
    printf("\n\r I2C Comms 3 complete");
    printf("\n\r");

/*
   printf("\n\r slave address %d", slaveaddress1);
   printf("\n\r slave data %d", slavetestdata2);
   printf("\n\r");
*/   
   
   }

}







The working pic 44j10 slave code is here with header:

*********************
slave header:
Code:

#include <18F44J10.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOXINST                    //Extended set extension and Indexed Addressing mode enabled
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES PRIMARY                  //Primary clock is system clock when scs=00
#FUSES RESERVED                 //Used to set the reserved FUSE bits

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Slave,Slow,sda=PIN_C4,scl=PIN_C3,address=0x40, FORCE_HW)


********************************
Working slave code .c file:
Code:
#include "C:\temp\i2Cattempt2-logic-exp\slave-44j10-uart\main.h"
#include <stdio.h>

enum {address, data};
int mode;
int i2cdat;

#int_SSP
void  SSP_isr()
{
   
   output_bit(PIN_C0, 0);
   if (i2c_poll())
   {
      //output_bit(PIN_C0, 0);
   //   if (mode == address)
      {   
         i2cdat = i2c_read();
         printf("\n\r isc-data == %d", i2cdat);
   //      printf("\n\r mode == %d", mode);
         printf("\n\r");
   //      mode = data;
         //1st pass, ignore address data
         //output_bit(PIN_C1, 0);
      }




/*      else
      {
         if (mode == data)
         {   
            
            i2cdat = i2c_read();
            printf("\n\r i2cdata == %d", i2cdat);
            printf("\n\r mode == %d", mode);
            printf("\n\r");
            mode = address;
            if (i2cdat == 5)
            {
               //printf("\n\r I can't believe its not butter");
            }      
               

         }
      
         else
         {
            printf("\n\r NOT ADDRESS OR DATA MODE!!!");

         }
      }*/
   }



   
}



void main()
{
   
   
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_SSP);
   enable_interrupts(GLOBAL);
   setup_oscillator(False);
   

////initialize variables
   mode = address;      //init i2c mode to address, since we haven't yet received i2c data

   while(1)
   {
     
     
   }
}




The NON-WORKING 16F677 header:
Code:
#include <16F677.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled

#use delay(clock=4000000)
#use i2c(Slave,Slow,sda=PIN_B4,scl=PIN_B6,address=0x20, FORCE_HW)



The Non-working 16F677 Slave main.c:
Code:
#include "C:\temp\i2Cattempt2-logic-exp\PSUBOARD\main.h"
#int_SSP

enum {address, data};

void  SSP_isr(void)
{
   int ch;
   int mode;
   output_bit(PIN_C1, 0);
/* if (i2c_poll());
   { 
      ch = i2c_read();
      if (mode == address)
      {
         mode = data;   //if we've gotten this far, our address was chosen
                        //and we're ready for the next byte, which is data
      }
     
      else
      { 
         mode == address;  // the next I2C byte will be an address so be ready for it
     
      if (ch == 7)
      {
           output_bit(PIN_C0, 0);     
         
        }


      //}
   
   //}


*/
}


void main()
{
   output_bit(PIN_C7, 1);     // turn on logic board. 
   
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
// enable_interrupts(INT_SSP);
// enable_interrupts(GLOBAL);
   setup_oscillator(False);

   output_bit(PIN_C0, 1);
   output_bit(PIN_C1, 1);
   output_bit(PIN_C2, 0);
   output_bit(PIN_C5, 0);     
     
   while(1)
   {
     output_bit(PIN_C0, 1);
     delay_ms(100);
     output_bit(PIN_C0, 0);
     delay_ms(100);
     
   }


}




The output bits are tied to LEDs. I can turn them on or off at will in the While loop, so the hardware is ok. The LED's are turned on by setting the output pins low (the LED cathode is tied to the pic output pin, along with series current limiting resistor to 5V.)

I cannot however get C0 to light up when I put output_bit(PIN_C0, 0); in the ssp_isr().

it's almost as though the pic is NEVER seeing the I2C data.

Note that the pullups in this I2C network are 10kohm resistors, pulled to 3.3V.



Please help me trouble shoot this PIC16F677 with I2C. It supposedly has an SSP module that supports I2C in slave mode.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 03, 2007 2:17 pm     Reply with quote

Quote:
Please help me trouble shoot this PIC16F677 with I2C

Post your compiler version.
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

PostPosted: Thu May 03, 2007 2:24 pm     Reply with quote

PCM programmer wrote:
Quote:
Please help me trouble shoot this PIC16F677 with I2C

Post your compiler version.



all are 4.029.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 03, 2007 2:32 pm     Reply with quote

Quote:

I cannot however get C0 to light up when I put output_bit(PIN_C0, 0);
in the ssp_isr().

Quote:

#include "C:\temp\i2Cattempt2-logic-exp\PSUBOARD\main.h"
#int_SSP

enum {address, data};

void SSP_isr(void)
{
int ch;
int mode;

You have an enum statement in between the #int_ssp declaration and
the actual function. As a result, the compiler will generate no code
for the isr.
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

PostPosted: Thu May 03, 2007 2:38 pm     Reply with quote

PCM programmer wrote:
Quote:

I cannot however get C0 to light up when I put output_bit(PIN_C0, 0);
in the ssp_isr().

Quote:

#include "C:\temp\i2Cattempt2-logic-exp\PSUBOARD\main.h"
#int_SSP

enum {address, data};

void SSP_isr(void)
{
int ch;
int mode;

You have an enum statement in between the #int_ssp declaration and
the actual function. As a result, the compiler will generate no code
for the isr.



I just removed the enum and INT CH, int mode statements---still no luck...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 03, 2007 2:43 pm     Reply with quote

The 'int ch' and 'int mode' declarations have no effect on the generation
of the isr routine. You can leave them in place.
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

PostPosted: Thu May 03, 2007 2:43 pm     Reply with quote

davefromnj wrote:
PCM programmer wrote:
Quote:

I cannot however get C0 to light up when I put output_bit(PIN_C0, 0);
in the ssp_isr().

Quote:

#include "C:\temp\i2Cattempt2-logic-exp\PSUBOARD\main.h"
#int_SSP

enum {address, data};

void SSP_isr(void)
{
int ch;
int mode;

You have an enum statement in between the #int_ssp declaration and
the actual function. As a result, the compiler will generate no code
for the isr.



I just removed the enum and INT CH, int mode statements---still no luck...





Thank you for all of your time, I'm a friggin idiot:

I remarked out both global interrupts and the SSP_Isr.

It's now working with all 3 chips.


thank you!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 03, 2007 2:45 pm     Reply with quote

Also, your test program for the slave, as posted, has the
enable_interrupts() statements commented out. You'll never get
an INT_SSP interrupt.
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