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 support@ccsinfo.com

Error In I2C Communications Between PICs

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



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

Error In I2C Communications Between PICs
PostPosted: Sun Mar 10, 2013 10:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 10, 2013 12:40 pm     Reply with quote

Since posting I've been trying to enable the hardware UART buffer and found an old post by PCM Programmer in this thread that suggests the support for this chip is flawed:

http://www.ccsinfo.com/forum/viewtopic.php?t=47249&postdays=0&postorder=asc&start=0


So for now I'll put it down to compiler issues if nobody has anything...?
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Sun Mar 10, 2013 8:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 10, 2013 11:40 pm     Reply with quote

No I think I'm wrong there.
Just looked at the compiled code.


Sorry
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