two PICs talking to each other

GeorgeB

Member
Hi

I'm new to picaxe and to microcontrollers and I was trying to make two 18m2 chips talk to each other. I have some questions:
Do I have to connect my connection wires to only the serial in and serial out pins on the pics or does any general pin would do it?
Would I need any resistors in the connection or just the output from the first to the input to the second and vice versa?
In terms of programming do i program every pic on its own and then connect the wires or program while the connection is already there?
in terms of sync between the two pics do I have to do anything with that or not ( I need a feedback loop so everything I sent has to be sent back to my control pic)?

that's it :D

sorry if the questions are too long. I'm just confused and still have lots of questions without answers but those are the most important ones :D ;D

Thanks in advance

George
 

hippy

Technical Support
Staff member
The "Serial In" and "Serial Out" pins are usually the ones used for downloading code from the PC. It is best to use other digital inputs and outputs with SERIN and SEROUT which can use most pins of a PICAXE. There are also HSERIN/HSEROUT pins which can useful in some cases.

The best way to gain more knowledge is to configure two PICAXE and start sending single bytes from one to the other. Build up from there.

On programming / downloading; yes each PICAXE will have to be programmed separately.

Connection is digital output from one to digital input to the other, plus the 0V of each side must be connected together. It's not absolutely necessary to put a resistor between the TX and RX pins but a 1K will help prevent accidents if both are made output pins at the same time.

Synchronisation can be achieved by sending a marker byte before the actual data and have the receiver wait for that. For example sending a byte from one to the other ...

SendByte: SerOut TX, TX_BAUD, ( $AA, b1 )

ReceiveByte: SerIn RX, RX_BAUD, ( $AA), b7
 

inglewoodpete

Senior Member
I have used an additional wire between two M2-series chips so that the slave can reliably signal to the master. In my case, the slave was an 08M2 and the master a 14M2.

The slave's serial output is switched high when the slave has data to send. This is interpreted by the master as a "Request to Send" (RTS) signal. When the Master is ready to receive the data, it sets the additional wire high to indicate this (Clear to Send (CTS)). The slave waits a couple of milliseconds before sending the data, to ensure that the master is indeed ready, and clears the RTS signal before sending. The master resets the CTS output after receiving the data.

The additional wire refer to could also be used as a reverse data channel by using the same signalling principles.
 

depeet

New Member
You can use Serial like Hippy wrote. Many OLED or LCD from picaxe , like AXE033, have a PIC to perform the serial communication.

I2C is also possible, but then you'll have to implement 2 pull-up resistors and configure 1 PIC as master and the other PIC as slave.
 

GeorgeB

Member
Thanks all of you that was very helpful
I have another question why is the timeout on the serin command doesn't work when you have a qualifier in the beginning of your message it just stops the whole program and waits indefinitely till the qualifier is received? does anyone have an answer to this?
it seems the same question was asked before on the forums but no one really answered the question they offered different methods to solve the problem!!
 

hippy

Technical Support
Staff member
I have another question why is the timeout on the serin command doesn't work when you have a qualifier in the beginning of your message it just stops the whole program and waits indefinitely till the qualifier is received? does anyone have an answer to this?
Having a qualifier does not in itself stop the timeout occurring. The following code runs on a physical 18M2 with C.0 tied to 0V, prints "Continuing" every five seconds when the SERIN timesout -
Code:
#Picaxe 18M2
#Terminal 4800
Do
  SerIn [5000], C.0, N4800, ($AA), b0
  SerTxd( "Continuing", CR, LF )
Loop
But, if C.0 is left floating, or connected to a wireless module which puts out random data when nothing is being sent to it, that random data will prevent the timeout from occurring.

The timeout is on "no data received", not "no qualifier match".
 
Top