View previous topic :: View next topic |
Author |
Message |
Geps
Joined: 05 Jul 2010 Posts: 129
|
Error In I2C Communications Between PICs |
Posted: Sun Mar 10, 2013 10:02 am |
|
|
Hi,
I'm setting up an I2C communication method between a single 18F46K22 and a single 12F1840. I have the following code compiled under 4.125 running on the 12F1840:
Code: | #include <12F1840.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP, NOMCLR
#USE delay(internal=32MHz)
#zero_ram
// -------------------------------------------------------------------------- //
// ------------------------DEBUG-MODE-ACTIVATION----------------------------- //
// -------------------------------------------------------------------------- //
//#define DEBUGMODE
#define BUFFER_ADDRESS 0x12
// -------------------------------------------------------------------------- //
// ----------------------------HARDWARE-SETUP-------------------------------- //
// -------------------------------------------------------------------------- //
#use RS232 (stream = DEBUG_SERIAL, baud=115200, xmit=PIN_A4, rcv=PIN_A5, ERRORS)
#use i2c(SLAVE, SDA=PIN_A2, SCL=PIN_A1, address=BUFFER_ADDRESS)
int8 CommandByte = 0x00;
#INT_SSP
void int_ssp_isr() {
int8 State = 0x00;
State = i2c_isr_state();
if((State == 0 ) || (State== 0x80)) {
i2c_read();
}
else if(State < 0x80) {
CommandByte = i2c_read(0);
}
else if(State > 0x80) {
i2c_write(0x00);
}
}
void main() {
delay_ms(1000);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
while(TRUE){
fprintf(DEBUG_SERIAL, "Running:%X", CommandByte);
delay_ms(10);
}
} |
I'm finding that regardless of what value I set in the i2c_write parameter to I consistently get 0x26 back.
When the master starts up before the slave I see 0xFFs, the slave has then started it switches to 0x26 so I'm confident it's not the master transmitting the value.
As I can't see a 0x26 anywhere in my code, can someone please explain the possible source for it?
Cheers, |
|
|
Geps
Joined: 05 Jul 2010 Posts: 129
|
|
|
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Sun Mar 10, 2013 8:58 pm |
|
|
Shot in the dark here.
Your #USE statement:
Quote: | #USE delay(internal=32MHz) |
Is that actually setting it up for 32MHz operation from the internal oscillator? I haven't used that chip but I thought it had something to do with setting it at 8Mhz and then enabling the 4XPLL.
Again, just a guess. |
|
|
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Sun Mar 10, 2013 11:40 pm |
|
|
No I think I'm wrong there.
Just looked at the compiled code.
Sorry |
|
|
|