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

Question about I2C communication

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



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Question about I2C communication
PostPosted: Sat Jan 11, 2014 1:22 pm     Reply with quote

Greetings! I'm working with a sensor through SPI interface! Sometimes my program blocks and there is no cpu reset, in spite of the WDT is running. Is it possible the SPI to cause this blockage??
Thanks!


Last edited by stoyanoff on Sun Jan 12, 2014 10:58 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9134
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jan 11, 2014 1:43 pm     Reply with quote

historically nothing should be able to interfere with the WDT from triggering a reset, provided it really is enabled, so SPI shouldn't be a factor.
Without seeing your code, we can't tell what PIC, whether the WDT is enabled or if you've compiled in 'debug' mode instead of 'release'.

hth
jay
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Question about SPI communication
PostPosted: Sun Jan 12, 2014 12:50 am     Reply with quote

I'm using 24GJ64GA306, MPlab v8.93, CCS v4.134. Here are parts of my code:
Code:

#include <24FJ64GA306.h>
#FUSES HS,WDT_SW,WPOSTS8,PR
#use delay(clock=20M)
#use I2C(MASTER,SCL=PIN_G2,SDA=PIN_G3,FORCE_SW)

void main()
{
setup_wdt(WDT_OFF);
d=restart_cause();
delay_ms(2000);
setup_wdt(WDT_ON);
 
while(!StartProcedure()); //sensor init

reset_wdt();

while(1)
  {
   //main program
   reset_wdt();
  }

}

Sometimes on power up my controller blocks and there is no reset until I don't turn off the power.
Thanks!
temtronic



Joined: 01 Jul 2010
Posts: 9134
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 12, 2014 6:38 am     Reply with quote

I don't use the 24 series but does the '1Hz blinking LED' program work?
There's a LOT of fuses nowadays and maybe you don't have the correct ones enabled/disabled?
It can easily be a hardware issue,1Hz proves basic PIC operation.

Something in here...
StartProcedure()
...could be 'blocking' your program...

Only giving us 'parts of my code' doesn't allow anyone to copy/paste/debug.

we need more info to further help you.

jay
jeremiah



Joined: 20 Jul 2010
Posts: 1320

View user's profile Send private message

PostPosted: Sun Jan 12, 2014 7:31 am     Reply with quote

Your code shows I2C rather than SPI. I2C can indeed block if the hardware is incorrect or the software has bugs. If you really are using I2C, you should start with PCM Programmers I2C bus scanning program and see if that locks up. It's in the code library forum.
jeremiah



Joined: 20 Jul 2010
Posts: 1320

View user's profile Send private message

PostPosted: Sun Jan 12, 2014 2:11 pm     Reply with quote

Stoyanoff is having trouble posting to the forums. He sent me a PM. Feel free to post any options. He can still read, but posting only goes to the preview page. I get the same forum issue from work. Can't post at all when I need to. Same browser/settings/etc. Anyways, his PM to me followed by my response:


stoyanoff wrote:
I`m sorry! It`s I2C. I can`t write into the forum. It shows only preview but doesn`t post my messages.
So how can I prevent I2C from blockage or to force cpu reset?!
Thanks!


It's ok, I have the exact same problem from work. *Sometimes* if I add a bunch of empty lines at the end of my post it goes through (like 5% of the time, so not really worth it). So I normally only post from home now.

First thing is you really need to verify the hardware. Try out that I2C bus poller program from the code dev forums. Preventing the I2C from blocking can really only be prevented once we know what is causing the blocking.

Some basic things:
1. Correct pullup resistors on the SDA and SCL lines (this is extremely important these are the right values).

2. PIC and I2C device are the same voltage levels (don't mix n match 3.3v and 5v devices without a level shifter inbetween.

If when you try out the bus poller program, it fails, tell me (us) what fails exactly. Does the poller program lockup? Does it work but no address gets printed? Be as specific as you can. Once we figure out the source, then we can determine which way to correct the I2C portion.

I'll post this on the forums for you.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Mon Jan 13, 2014 3:46 am     Reply with quote

My controller is on 3.3, but the sensor is on 5V. I tried with level shifter, but the sensor doesn`t respond! So I`ve changed the pull-up resistors values and now it`s working but with bugs! For level shifter I user 2 MOSFET transistors as the I2C specification says.
I suppose I have to remake my schematic to work on 5V.
jeremiah



Joined: 20 Jul 2010
Posts: 1320

View user's profile Send private message

PostPosted: Mon Jan 13, 2014 8:50 am     Reply with quote

Some of the more veteran users might correct me, but I believe when making your own level shifter for I2C, you have to take care with MOSFET selection. Things like the MOSFET's capacitance and on resistance can effect it.
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