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

I2C Problems once again.....

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



Joined: 16 Apr 2005
Posts: 23

View user's profile Send private message

I2C Problems once again.....
PostPosted: Mon May 09, 2005 7:18 am     Reply with quote

Hey, ive used snibb's I2C example that he has provided here and programmed my two 16f876A's. ive connected the hardware, pullups blah blah and connected the serial lines in.

in the slave part of the code i have un-commented the debug part.

when i press read on the master, it comes up with FFFF which seems ok, when i come to write it asks me what i want to write, i put it in, then read again and its still FFFF.

so i connected the serial line to the slave, leaving the transmit on the master, and did the write cycle again. nothing happens. the slave appears to never read the write part of the command.

any ideas????

cheers, phil
valemike
Guest







PostPosted: Mon May 09, 2005 8:34 am     Reply with quote

When the master reads back 0xFF, then that means the slave is not responding. You'll read back 0xFF also if there is no slave connected to the other end of the i2c lines. However, if the slave is held in reset, then the i2c functions will freeze and wait.

Also, you might try injecting in a few delay_ms(3) (3 is an arbitrary number) between each i2c function call. This is because the slave might be getting overrun. Unfortunately, the sample code doesn't handle overrun errors, but you may be able to reduce such overruns by putting in delays.

Delays are a kludgy way to do things. The proper way would be to check for acks, and retry if the ack is not '1'. However, try the delays first to get the rest of your program to work; then try some error handling later on.

-Mike
PhilWinder



Joined: 16 Apr 2005
Posts: 23

View user's profile Send private message

PostPosted: Mon May 09, 2005 9:07 am     Reply with quote

ok good call mike,

when i put the delays in, it now seems to be working, but like you described in the first part of your reply it is 'hanging'. so i checked to see whether it was held in reset by just putting a printf in the main() and it is working ok. so the problem is that it is not going into the interrupt. when you said a delay of 3ms, is that a guess or could it take longer?? since i only used 3ms. as for the code it is exactly the same as in the above example post, same pic, only difference is now that there are some delay_ms(3) between every i2c interaction.

thanks mike,

phil
valemike
Guest







PostPosted: Mon May 09, 2005 9:16 am     Reply with quote

3 ought to work just fine. if you use 10ms, things might start to get sluggish, but that will still work.

The fact that the Master is 'hanging' for you now is disturbing. Are you at least getting a few successful writes and reads, or is it hanging immediately.

I would like to say to take a look at the hardware. What is the size of your pullup resistors on RC3 and RC4? The hardware is simple enough, so that's probably not the problem.

You are enabling SSP interrupts on the slave, right? And you are setting up your SSPCON1 register to be an i2c slave, right (not regular i/o)?
PhilWinder



Joined: 16 Apr 2005
Posts: 23

View user's profile Send private message

PostPosted: Mon May 09, 2005 9:46 am     Reply with quote

hey mike, i was thinking about your resistor comment, cos i was using 10k's for pullups, thought this might be too high, so i went down to check and BBAAAMMM. i hadnt pulled up the clock line, just the data. a quick check and hey presto. however i do still have to put the delays in but 1ms does work.

actually, i did ask about the acks, but its not imperative so i edited this post. what im now trying to do is basically transferring a message to be shown on a LCD screen on the slave pic. ive managed to convert the code to only send and recieve a byte, so now it sends 1 character. my idea was to use this in the same way that lcd_putc works with printf. i.e.

printf(lcd_putc,"blah blah");

so would it work when i put,

printf(send_i2c_char,"hello!!");

where send_i2c_char is the routine that i now have for sending a single i2c byte.

And if it does work, then what would be the best way to putting it on the LCD screen, since i cannot send "\n" all at once. any thoughts are greatly appreciated.

thanks, phil Smile
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