| View previous topic :: View next topic |
| Author |
Message |
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Tue Apr 08, 2008 10:04 am |
|
|
Oups, it works.
I2C writing process works now.
The interrupt occurs 5 times! Correct
(Slave addressW, 0x00, 0xAA, 0x55, 0xA5) forget about 0x5A, i removed it.
[No interrupts for S & P]
Still have a problem in the reading process. The interrupt occurs only three times (Slave addressW, 0x00 & Slave addressR) instead of 6. the last three are related to collecting data from slave
[SCL stays LOW]
my isr is:
| Code: |
void SSP_isr(void)
{
BYTE incoming, state;
state = SSPSTAT & SSPSTATMASK;
RX_LOS_SFP = 0; //LED indicator
switch (state)
{
case 0B00001001: // i2c write operation, last byte was address
incoming = SSPBUF;
InternalAddress = TRUE;
if (incoming == 0xE0) // check address
{
PORTA ^= 0x01;
}
break;
case 0B00101001: // i2c write operation, last byte was data
//incoming = i2c_read(); // data read
incoming = SSPBUF;
if (InternalAddress)
{
InternalAddressCounter = incoming;
InternalAddress = FALSE;
if (incoming == 0x00) //check internal address
{
PORTA ^= 0x01;
}
}
else
{
Page[InternalAddressCounter++] = incoming;
}
break;
case 0B00001101: // i2c read operation, last byte was address
incoming = SSPBUF; //dummy read
i2c_write(Page[InternalAddressCounter++]); // data write
break;
case 0B00101100: // i2c read operation, last byte was data
i2c_write(Page[InternalAddressCounter++]); // data write
break;
case 0B00101000: // slave i2c logic reset by NACK from master
break;
default:
if (BF)
{
incoming = SSPBUF;
}
break;
}
SSPOV = 0;
RX_LOS_SFP = 1; //LED indicator
}
|
!? |
|
 |
Matro Guest
|
|
Posted: Tue Apr 08, 2008 11:20 am |
|
|
Then try with this isr:
| Code: |
#INT_SSP
void i2c_isr()
{
unsigned int8 state;
state = i2c_isr_state();
if(state >= 0x80)
{
i2c_write(state);
//you can add here a serial trace or a LED toggle (not on port C)
}
else
{
state = SSPBUF
//you can add here a serial trace or a LED toggle (not on port C)
}
}
|
or you can also try to change your isr to :
| Code: |
#int_SSP NOCLEAR
void SSP_isr(void)
{
BYTE incoming, state;
state = SSPSTAT & SSPSTATMASK;
clear_interrupt(int_SSP);
// continue te code
|
Matro |
|
 |
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Tue Apr 08, 2008 11:41 am |
|
|
Are we talking about compiler bugs ?!?!?!?!?
Note that PIC18F2431 has an SSP and not an MSSP.
I'll try it by tomorrow, I'm out of the lab right now.
Thanks again  |
|
 |
Matro Guest
|
|
Posted: Tue Apr 08, 2008 11:45 am |
|
|
Maybe a compiler bug or a mistake in the device header file.
We should analyze the .lst file generated by compilation but I've got no time for that.
You can send a mail to CCS support if you strongly believe in a compiler bug.
Matro. |
|
 |
Matro Guest
|
|
Posted: Tue Apr 08, 2008 11:49 am |
|
|
And yes, 18F2431 SSP doesn't support master operation at hardware level but only through software emulation.
Matro. |
|
 |
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Wed Apr 09, 2008 6:09 am |
|
|
It works now
my ISR:
| Code: |
#INT_SSP
void SSP_isr(void)
{
BYTE incoming, state;
state = SSPSTAT & SSPSTATMASK;
switch (state)
{
case 0B00001001: // i2c write operation, last byte was address
incoming = SSPBUF; //dummy read
InternalAddress = TRUE;
break;
case 0B00101001: // i2c write operation, last byte was data
case 0B00100001: // strange state !?!?!?!?!?
incoming = SSPBUF; //data read
if (InternalAddress)
{
InternalAddressCounter = incoming;
InternalAddress = FALSE;
}
else
{
Page[InternalAddressCounter++] = incoming;
}
break;
case 0B00001100: // i2c read operation, last byte was address
SSPBUF = Page[InternalAddressCounter++]; // data write
CKP = 1; // release the clock
break;
case 0B00101100: // i2c read operation, last byte was data
SSPBUF = Page[InternalAddressCounter++]; // data write
CKP = 1; //release the clock
break;
case 0B00101000: // slave i2c logic reset by NACK from master
InternalAddress = TRUE;
break;
default:
break;
}
}
|
|
|
 |
|