Helpful ReplyHot!How to do Multi Master I2C communication in PIC??

Page: < 12 Showing page 2 of 2
Author
Mysil
Super Member
  • Total Posts : 3279
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/23 09:20:12 (permalink)
0
Hi,
In datasheet chapter 14.0:
'PIC16F87XA devices have a Watchdog Timer which
can be shut-off only through configuration bits.'
 
If you are running the program with Debugger,
then watchdog cannot be enabled.
 
    Mysil
#21
qhb
Superb Member
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/23 14:08:23 (permalink)
0
nikhilms
Can I enable/disable Watchdog timer during run time in PIC16F877A?.

No.

Newer pic has WDTCON register, but in 16F877A it is added in Configuration words.

Which is why the answer is "no"
 

It is for resetting devices in I2C bus when stuck.

How on earth do you imagine disabling (or even enabling) the WDT is going to help you reset I2C devices?
 
Just to be clear:
[1] it is the Slave, not the PIC that requires resetting.
[2] MCLR is NOT an output pin. It does not output a reset pulse when the WDT activates.
 
post edited by qhb - 2019/03/23 14:47:02
#22
NiKHiL
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/11/24 05:02:22
  • Location: India
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/24 22:48:28 (permalink)
0
My slave device is DS3232 and it has a reset pin too. This reset pin must be connected to a port pin. So when the bus hangs WDT reset the controller. The code for resetting the DS3232 will  be written at the beginning of the code. So whenever the pic restarts, DS3232 also restarts. I did't implement it, so not sure.
 
If wdt can be enabled at run time, it is easier to control, just enable it before I2C read, now i have to reset the timer before the timeouts occurs through out the code.
 
My normal I2c read/write took around 3ms, so if WDT is set to 10ms, the concept might works.
#23
qhb
Superb Member
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/24 23:14:22 (permalink)
0
So you have the DS3232 RST pin connected to a PIC port pin?
Why pick such an awkward way to do a reset then?
If you want to reset the chip, just toggle the pin low then high. Why force your PIC to do a complete restart from scratch?
If you REALLY want to do that, then just exit from your main() function, and XC8 will restart your code.
 
#24
NiKHiL
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/11/24 05:02:22
  • Location: India
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/24 23:43:46 (permalink)
0
Thanks for the reply,
First I tried to reset the DS3232 alone using a piece of wire when it hanged, but nothing changed, then i reset the pic by pulling down the MCLR pin, then both pic started to read from DS3232. Thus i came to the conclusion that both pic's and DS3232 needs a reset when it hangs.
 
"If you REALLY want to do that, then just exit from your main() function, and XC8 will restart your code."

For waiting for 10ms, the best way is to use timers. Suppose DS3232 hangs during run time, how can i get the current execution line, it may inside the function for waiting idle bus condition or somewhere inside the I2c code.
Even if i use interrupt, i must set an error flag and return to main by monitoring error flag from a couple of nested functions, then exit from main. So i felt WDT is easier, just reset whenever timeout occurs. 
If any function in xc8 for resetting the code, please let me know, it is easier.
#25
qhb
Superb Member
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/24 23:48:45 (permalink)
0
nikhilms
If any function in xc8 for resetting the code, please let me know, it is easier.

Do you mean like
RESET();

Which IS documented in the XC8 User Guide.
 
#26
NiKHiL
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/11/24 05:02:22
  • Location: India
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/25 00:48:29 (permalink)
0
Thanks
RESET(); will works.
IS there any assembly version for this, I searched in assembler directives, but didn't found any, because one pic's code is in assembly. 
clear pcl and pclath is an option but resetting stack pointer is not possible
#27
qhb
Superb Member
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/25 00:56:27 (permalink)
0
nikhilms
but resetting stack pointer is not possible

You don't need to reset the stack in this PIC.
It's circular. It is impossible to detect if it has over or under flowed anyway.
#28
NiKHiL
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/11/24 05:02:22
  • Location: India
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/25 01:28:43 (permalink)
0
Ok, Thanks for the valuable advice. 
Now i am not going to use  WDT, instead using this reset method.
I will post the result later.
#29
Mysil
Super Member
  • Total Posts : 3279
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re: How to do Multi Master I2C communication in PIC?? 2019/03/25 17:15:09 (permalink)
0
Hi,
In obsolete PIC  devices without RESET instruction in the assembly instruction set,
a RESET() macro, as documented in XC8 user guide,
might just point the program counter to Reset address in program memory,
and start the firmware from there, without doing hardware register initializations.
 
Then in datasheet for DS3232, Maxim Integrated 19-5337; Rev 5; 7/10,  there is:
'Interface Timeout'  'tIF' documented to be between 25 ms and 35 ms:
"If SCL is held low for greater than tIF, the internal I2C
interface is reset. This limits the minimum frequency at
which the I2C interface can be operated. If data is
being written to the device when the interface timeout is
exceeded, prior to the acknowledge, the incomplete
byte of data is not written."
 
So maybe you are trying to solve a problem that will not occur for the real-time clock device.
 
    Mysil
#30
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5