|
|
View previous topic :: View next topic |
Author |
Message |
jpts
Joined: 08 Mar 2017 Posts: 40
|
2 pics sharing same eeprom with I2c |
Posted: Fri Apr 21, 2017 2:14 pm |
|
|
How the best way to implement 2 pics (16f628) sharing 2416 eeprom using I2C bus.
PIC1 PIC2
| |
| |
|_______|i2c bus
|
eeprom (slave)
Should I implement any bus control for PIC 1 and PIC 2 to avoid send command (read and write ext eeprom) same time to eeprom ?
Regards, Jpts |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Apr 21, 2017 11:33 pm |
|
|
One word answer.
Yes....
I'd suggest you look at how semaphore signalling is done on railways, for single track operation. Your bus is the 'track', and before either chip accesses this, it must have the 'semaphore' to say it may do so.
You can use one line with a pull up resistor, and pull this low, as the semaphore. Just need a little extra care to ensure that the two devices don't accidentally operate it at the same moment. So the chip does:
Test if line is high?.
If not other chip is using the bus. Loop and wait till it releases.
If it is, pull it down.
Now wait for a moment, release it for just one cycle, then test and if high pull low again. If low, loop back to start.
Ideally use a slightly variable delay for the 'moment'. So either have one chip delay (say) 10uSec, and the other 15uSec, or use a psuedo random number generator for the delay.
This way, if both chips attempt to take the semaphore at the same moment, the one with the shorter delay, will effectively 'yield' to the other.
Only if you have the 'semaphore' (so are the chip pulling the line low), may you talk to the EEPROM.
Once you have finished your transactions, then release the line. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sat Apr 22, 2017 4:51 am |
|
|
You could do it without using any more pins if you have the PIC running an SW RTC. PIC A could access the EEPROM on even minutes, PIC B on odd minutes.
Another possible method is to have the PICs read one address of the EEPROM. PIC A writes a control byte to let PIC B if it's his turn to use the EEPROM.
There are maybe 1/2 dozen mor ewys to do the task but...
I have to ask WHY 2 small PICs? A larger one seems the obvious solution though I suspect this is not a real project, rather a school quiz?
Jay |
|
|
jpts
Joined: 08 Mar 2017 Posts: 40
|
|
Posted: Sat Apr 22, 2017 9:09 am |
|
|
Reason to use 2 pics is for TIMERs as count. I did a test using just 1 pic link with eeprom. I need to count two pulses and add for just one output. I did this way:
Code: |
delay(crystal=4MHz)
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1|RTCC_8_bit);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
set_timer0(0);
set_timer1(0);
main()
if (get_timer0() > 0)
{
pulse1 = get_timer0();
set_timer0(0);
}
if (get_timer1() > 0)
{
pulse2 = get_timer1();
set_timer1(0);
}
pulse_total = pulse1 + pulse2;
while(pulse_total > 0)
{
output_high(PIN_B0);
delay_us(150);
output_low(PIN_B0);
delay_us(150);
pulse_total--;
}
puls1 = 0;
puls2 = 0;
}
|
Testing just one channel pulse1 or pulse2 separate no problem with frequency up to 2khz. Pulse in = Pulse out 100%. But using both same time, pulse1+pulse2 for frequency about 1khz, the pulse out is not = pulse1+pulse2. It "loses" pulses. For frequency below lets say 100hz it works..if any suggestion to solve, I back to 1 PIC. |
|
|
|
|
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
|