|
|
View previous topic :: View next topic |
Author |
Message |
gil.fonea@sds-tech.com
Joined: 24 Mar 2010 Posts: 24
|
i2c interrupt for data byte doesn't pop |
Posted: Sun Sep 19, 2010 9:01 am |
|
|
Hi,
I am using PIC18f662 and a CCS compiler ver 4.077 as a i2c slave.
The master send me 1 byte of data. The ssp_interupt() works for the address byte, but not coming again for the data byte (I can see the ack for the data byte over the oscilloscope).
This is my code:
Code: |
#INT_SSP
void ssp_interupt()
{
BYTE incoming, state;
output_high(no_connected_RA5); //gil debug
CKP = 0;
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
rcv_buffer[address] = incoming;
}
if(state == 0x80) //Master is requesting data
{
i2c_write(rcv_buffer[address]);
}
CKP = 1;
output_low (no_connected_RA5);
}
|
Please help/ _________________ Gil F. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 19, 2010 6:05 pm |
|
|
Show us both the master and the slave code.
But show us very short versions of each of these programs. They
must be compilable. Don't include any unneeded "Wizard" code.
For example, here is a short i2c Master test program. Your program
could be made shorter than this:
http://www.ccsinfo.com/forum/viewtopic.php?t=32368&start=3
The i2c Slave code should include the code that you posted above, and
a very small main(), and #include, #fuses, #use delay() and #use i2c(),
and no unnecessary code. |
|
|
gil.fonea@sds-tech.com
Joined: 24 Mar 2010 Posts: 24
|
i2c interrupt for data byte doesn't pop |
Posted: Mon Sep 20, 2010 1:37 am |
|
|
Hi,
Follow are the master and slave codes.
The original issue is that removing the printf (denoted below) causes i2c reception to fail (no end bit is sent by the master and no second interrupt pops on the slave side).
Thanks,
--------------- slave code --------------------------
Code: |
#include "16f882.h"
#fuses INTRC, NOWDT, NOPROTECT, NOPUT
#fuses BORV21
#use delay(internal=8M)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x52)
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x52)
#define I2C_CMD_WRITE 0x00
#INT_SSP
void ssp_interupt()
{
BYTE incoming, state;
output_high(no_connected_RA5);
CKP = 0;
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
rcv_buffer[address] = incoming;
}
if(state == 0x80) //Master is requesting data
{
i2c_write(rcv_buffer[address]);
}
CKP = 1;
output_low (no_connected_RA5);
} |
---------------- slave main loop -----------------------
Code: |
void main(void)
{
BYTE i;
setup_oscillator(OSC_8MHZ);
INTCON = 0x00; // clear all interrupts
Init_reset();
event_in = no_event;
SEN = 1;
//--------------------------------------
// enable interrupts here
//--------------------------------------
enable_interrupts (INT_SSP);
enable_interrupts (GLOBAL);
disable_interrupts (GLOBAL);
//--------------------------------
// enter sleep mode
//--------------------------------
while(1)
{
if (event_in == no_event) // check for no event
{
INTCON = 0xD0; // enable interrupts
setup_uart(FALSE);
SLEEP();
setup_uart(TRUE);
printf(" exit_sleep " ); <--------- removing this printf causes i2c reception to fail
}
INTCON = 0x00; // disable interrupts
//--------------------------------
// uart rx flag
//--------------------------------
if (uart_rx_flag != 0) uart_rx_flag = 0;
execute_event();
}
}
|
--------------- master code --------------------------
Code: |
#define set_i2c_master() #use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3)
#define set_i2c_slave() #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x50)
void write_i2c(BYTE command)
{
BYTE ack_result[2];
//---------------------------
set_i2c_master()
//---------------------------
i2c_start();
ack_result[0] = i2c_write(0x52 | I2C_CMD_WRITE);
ack_result[1] = i2c_write(command);
i2c_stop();
// return to slave mode ...
//---------------------------
set_i2c_slave()
//---------------------------
} |
_________________ Gil F. |
|
|
|
|
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
|