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

#int_ssp not working(?)

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







#int_ssp not working(?)
PostPosted: Wed Apr 11, 2007 1:29 pm     Reply with quote

I am developing a program where i am using the PIC16F819 to be a I2C (SMBUS) slave. I have set up the SSP interrupt as is from the EX_Slave.c. When i run the program and have my host device write to the PIC, nothing happens. When i look at the data on a scope, it does not look like the PIC ever acknowledges its address, the host writes it correctly and then lets the clock and data lines float and the PIC never acknowledges by pulling the SDA line low. Now, i have tested the host device with other I2C/SMbus devices and i know that it works. Here is the code. Compiler V 4.027
Please review my code and see if i am doing something incorrectly.
Thanks

#include <16F819.h>
#device adc=10
#use delay(clock=4000000, RESTART_WDT)
#fuses WDT,INTRC_IO, PUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT
#use i2c(SLAVE,Fast,sda=PIN_B1,scl=PIN_B4,address=0x16,smbus)
#include <math.h>

#use fast_io(A)
#define LED1 PIN_A0 //100% led
#define LED2 PIN_A1 //80% led
#define LED3 PIN_A2 //60% led
#define LED4 PIN_A3 //40% led
#define LED5 PIN_A4 //10-20% led, yellow
#define LED6 PIN_A6 //below 10% or fault led, red

#use fast_io(B)
#define sw_in PIN_B0 //switch
#define SMBD_E PIN_B1 //smbus data external
#define SMBD_I PIN_B2 //smbus data internal
#define SM_BP PIN_B3 //smbus by pass switch
#define SMBC_E PIN_B4 //smbus clock external
#define SMBC_I PIN_B5 //smbus clock internal

#define INTS_PER_SECOND 15


////////////////////////////////////////////////////////////////////////////////

BYTE address, buffer[0x10];
char i,loop,int_count,bus_free,fault;
int lb_current,hb_current,count,lsb,msb;
long time1,seconds,voltage,percent,status,temperature;
signed long current;


////////////////////////////////////////////////////////////////////////////////
#int_rtcc
clock_isr()
{
if(--int_count==0) //decrement counter until 0
{
++seconds; //count up seconds
int_count=INTS_PER_SECOND; //reset counter
if (seconds>=65000)
seconds=65000;
}
}


////////////////////////////////////////////////////////////////////////////////
#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()
{
output_low(sm_bp); //disconnect externa and internal
output_float(SMBC_I); //release data line
output_float(SMBD_I); //release clock line
output_float(SMBC_E); //release data line
output_float(SMBD_E); //release clock line
output_high(LED1); //turn led off
output_high(LED2); //turn led off
output_high(LED3); //turn led off
output_high(LED4); //turn led off
output_high(LED5); //turn led off
output_high(LED6); //turn led off

setup_oscillator(osc_4mhz);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_8);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_256);
set_rtcc(0);
enable_interrupts(INT_RTCC);
ext_int_edge(0,H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
port_b_pullups(false); //added to see if this could be used on chg

set_tris_a(0b00000000);
set_tris_b(0b00000001);

loop=1; //initialize all vairables
int_count=INTS_PER_SECOND; //used for timer
seconds=0; //clear out variable
time1=30; //counter for time,30 seconds
delay_ms(1000);
//percent=0;
count=0;
bus_free=0;
fault=0;

while (TRUE)
{

delay_ms(100);
//output_low(LED1);
delay_ms(100);
// output_high(LED1);
output_float(SMBC_I); //release data line
output_float(SMBD_I); //release clock line
output_float(SMBC_E); //release data line
output_float(SMBD_E); //release clock line
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 11, 2007 2:16 pm     Reply with quote

Quote:
setup_oscillator(osc_4mhz);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_8);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_256);
set_rtcc(0);
enable_interrupts(INT_RTCC);
ext_int_edge(0,H_TO_L);

I didn't look at your program in detail, but the setup_spi() statement
will turn off the hardware i2c module. That means it shuts down
your i2c slave. Delete that line.
nrmeyer34
Guest







PostPosted: Wed Apr 11, 2007 2:24 pm     Reply with quote

I figured it was something simple that i missed. I copied some of this over from another project and that was left over. I have deleted it and it is now responding as i would expect it to.
Thanks for the help!
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