Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Connecting two PIC18Fxxxx microcontrollers together with I2C

Status
Not open for further replies.

mikkolaa

Newbie level 4
Joined
Sep 18, 2006
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Espoo
Activity points
1,339
i2c communication between two microcontrollers

Hello,

I am starting programming programs whitch communicate between two PIC18F6520.
(It is possible to use SPI also, but what is maximum cable lenght between SPI devices?)
The protocol should be very easy. It will be send only 2-4 bytes at one time.
I think I need use dual master mode, because second PIC send error codes to
master PIC.
I have no idea how to start the I2C project. (The master PIC is working now
without I2C, but next I will write I2C protocol to "slave" and current "master" pic.

I am using MPLAB 7.4 ASM coding.

Can you anyone advice some to start project? Example code?
I have PIC18C Reference Manual.
 

i2c between two pic

Hello!
It would be nice if you could give us more information about your project!!!
So, please, describe your project in few words and then show us what you did so far.
Finally ask us your questions!
regards
 

ssp1buf

Kabanga said:
Hello!
It would be nice if you could give us more information about your project!!!
So, please, describe your project in few words and then show us what you did so far.
Finally ask us your questions!
regards

I am writing software for gaming project. (Flip a coin machine).
For an example, i made one game electronics few years ago:
**broken link removed**
That machine has two PIC microcontollers, second pic executes payouts
and main pic sends commands to second pic by USART (RS232) interface.
The second pic send error codes to main pic if necessary.

But this new machine has tree microcontollers, one is main procsessor and
second pays coins from motor controlled payout units (USART RS232 commands ).
Third microcontoller will execute solenoid payout from playfield. (14 pcs solenoids).
Main microcontroller will send command to third by I2C.
I will get PCBs for this solenoid payout unit at the next week, so program writing
could start now.

That solenoid payout controller has two Altera chips for muxing I/O ports.
There is one output signal and three input signals / solenoid. That why I use
PIC18F6520 tqpf64. (I use same pic for main procsessor).

My question was to generic use. All examples that I found at internet was
for I2C memory write / read. But I quess someone did code for communicate
between two microcontrollers.
 

i2c connect 2 pic

hello,

i was trying to do something that sounds very similar to what you are trying to do not so long ago.

in the end i decided not to use I2C because it is probably the most complex communication method on the chip.

if you are able to i would suggest using USART or EUSART as they are far easier to implement.

in my project i also needed to comunicate between several devices as i was building a unit which had one master chip and multiple slave devices. it is quite easy to make a routine that can talk to the slaves individually.

i done this by using 9 bit mode. this allows the byte you want to send plus one extra bit to be sent as one. if you use this bit to indicate that an address is being sent you can speak to 1 device at a time.

it seems to be a reliable way of getting short peices of data from one chip to another and is quick to get working.

although i was working with the 16f877A device im sure it would be a simple task to get this working on your device.

the downside is that it will most likely require a change of pin allocations to migrate to this form of communication, but the upside is that you wont spend long getting the rest of the code written.

best of luck!
 

comunication two pics i2c

shaun_c_m said:
hello,

i was trying to do something that sounds very similar to what you are trying to do not so long ago.

in the end i decided not to use I2C because it is probably the most complex communication method on the chip.

if you are able to i would suggest using USART or EUSART as they are far easier to implement.

in my project i also needed to comunicate between several devices as i was building a unit which had one master chip and multiple slave devices. it is quite easy to make a routine that can talk to the slaves individually.

i done this by using 9 bit mode. this allows the byte you want to send plus one extra bit to be sent as one. if you use this bit to indicate that an address is being sent you can speak to 1 device at a time.

it seems to be a reliable way of getting short peices of data from one chip to another and is quick to get working.

although i was working with the 16f877A device im sure it would be a simple task to get this working on your device.

the downside is that it will most likely require a change of pin allocations to migrate to this form of communication, but the upside is that you wont spend long getting the rest of the code written.

best of luck!

Hello,

I made PCB for the mainboard about 1½ years ago. I impelemded
some PORTC pins to extra connector and TX and RX pins to controlling
second controller.
Now I need that extra connector to use with new board. Unfortunately
there is no available RX/TX pins (routed pins). USART port 2 uses two pins
on PORTG, but that needs some wires to onboard -> If I will use USART...

Maybe I can write code to use MASTER / Slave mode. (New board will be slave
and mainboard has master I2C) And few extra pins on that connector are used
for handshakin.
 

pic i2c multimaster .asm

Hi ,
I am working on a similar project in which I am connecting two PIC18F8722 devices through I2C bus.There are also a EEPROM,RTC and DAC on the same I2C bus.

But I am am having problem while sending data from slave to master cpu.
I can receive data correctly from master to slave.

But as soon as I read data from slave, master hangs and keeps on waiting for BF bit to be set.It seems SCL line is permanently low.

I am using same code as used for communicating to RTC in master.Please see below:

StartI2C();
IdleI2C();
varslave1 = putcI2C(address); // control byte to write
IdleI2C();
varslave1 = putcI2C(0xAB);
IdleI2C();
StopI2C();

StartI2C();
IdleI2C();
varslave1 = putcI2C(address);
IdleI2C();
varslave1 = getcI2C(); //Read data from slave
IdleI2C();
StopI2C();

Slave cpu has interrupts enabled on I2C.The code for slave is:
void I2CInterruptHandlerHigh(void)
{
BYTE var;
INTCONbits.GIE = 0; //disable global interupt
if(PIR1bits.SSP1IF) //respond to I2C slave interupt
{
// I2C stop bit detected (Page 81) so it's a I2C Slave Transmission
/*if(SSP1STATbits.P == 1)
{
SSP1BUF = 0; // SSPBUF=0 (Page 19)
SSPCON1bits.CKP = 1;// set_bit(SSPCON,4) aka CKP, SSPBUFF must be write before (Page 82)
}*/

if(SSP1STATbits.BF == 1) //else it's a //I2C Slave Reception
{

AddDelayMs(10);
gFnCode = SSP1BUF; // save data
var = putsI2C(0x31);//send data to master
ComputeENQ(gFnCode);
}

PIR1bits.SSP1IF = 0;
}//END IF
INTCONbits.GIE = 1; // enable global interrupt
}

I am totally lost.Any help is greatly appreciated.

Thanks,
Amit
 

i2c between to 2 pic

I did have same problems. So I can't help.
I think microchip's i2c hardware is not so easy
(with assembler).
I worked almost month with the I2c problems.
Today I replace communication to SPI or similar
software based data communication.
Reazon is that I do not have any other devices on the same net and I don't wan't anymore use time to try use microchip I2C modules.

Communication protocol is the question. I do not need transmit and receive huge data my packets are only few bytes. (few data bytes and cheksum).
 

pic18 i2c ckp

Colleagues,

Is it possible to switch between I2C Master and Slave modes during run time by writing to the SSPCON register?

I will have two PICs in the system. One will handle the display, another one will control the process. When the process isn’t running, the display PIC should be the Master. When the process is running, the display PIC should display the parameters. But the problem is that I have a requirement from the guy, who developed the current version of the control PIC firmware, that the control PIC shouldn’t be interrupted for serial communication. I’m contemplating about making a multimaster bus, where the process control PIC is a Master, when the process is running, and the display PIC is a Master for the rest of the time. I’ll probably add a handshaking line too. Do you think that this is a good approach?

Cheers,
- Nick

P.S. Another option would be to replace I2C with CAN, which is a peer-to-peer bus to begin with. Unfortunaltely, it's too late to do it.
 

connecting i2c to a pic

Even better than the CAN is the LIN, but as you mentioned is too late to implement.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top