Serial messaging chip to chip

Lobobo

Member
Hi. I am trying to send messages from chip 40x1 to 08M2 chip. This was my choice because of shortage of RAM, EEPROM and TABLE memory on single chip. All I need is to save data from 0 to 255 to 08M2's EEprom. To trigger read on 08M2 I am using interrupt on input pin. So 40x1 is sender, 08M2 is receiver and I am getting mess on receiver (different data every time). I connected pin 7 (serial out) on 40x1 to pin 2 (serial in) on 08M2 with 10K resistor in series. The same I've done with interrupt connection - 10K in series.
There is my code:
Sender
Code:
#Picaxe 40x1
main:
	b0 = 25 				'for example "25" is data we need to send
	if pin0 = 1 then			'push button to trigger data send
	gosub send_message_to_08
	endif
	goto main

send_message_to_08:
	do
	loop while pin0 = 1	'loop here to avoid multiple messages
	high 7			'trigger interrupt on 08M2
	pause 50
	low 7
	sertxd(b0)			'send data over serial conection pins
	return
Receiver:
Code:
#Picaxe 08M2
let dirsC = %00010001			'Define 2 outputs, rest of pins are inputs
setint %00001000, %00001000, c	'Interrupt on input C.3 when high

main:
	'the code
	goto main
	
interrupt:
	serrxd [1000],b0			'store received data into b0, timeout 1s		'
	pause 10
	debug					'to monitor
	setint %00001000, %00001000,c	'reinitialise interrupt
	return
I tried to monitor received data on LCD as well, but results are messy all the time. Why is this doesn't work?
Thanks.
 

hippy

Ex-Staff (retired)
All I need is to save data from 0 to 255 to 08M2's EEprom.
I would suggest using simpler code, particularly not using SERRXD and SERTXD to communicate between chips to start with.

The following code demonstrates a simple system for an 18M2 ( could become 40X1 ) sending data to an 08M2 which reports on the Terminal what it has received ...

Code:
#Picaxe 18M2
#No_Data

' Connect C.0 to pin 3 ( leg 4 ) of 08M2

Low C.0
Pause 2000

Do

  For b0 = 0 To 255
    Gosub SendB0To08M2
    Pause 1000  
  Next

  Pause 10000

Loop

SendB0To08M2:
  High C.0
  Pause 1
  SerOut C.0, T2400, ( b0 )
  Low C.0
  Return
Code:
#Picaxe 08M2
#No_Data
#Terminal 4800

Do
  Do : Loop Until pin3 = 0
  Do : Loop Until pin3 = 1
  SerIn 3, T2400, b0
  SerTxd( "Received ", #b0, CR, LF )
Loop
 
Last edited:

hippy

Ex-Staff (retired)
Here's some code which lets the 18M2 access the 08M2 as if it were a 256 x 8 Eeprom over serial ...

Code:
#Picaxe 18M2
#No_Data
#Terminal 4800


' Connect C.0 to pin 3 ( leg 4 ) of 08M2
' Connect C.1 to pin 4 ( leg 2 ) of 08M2

Low C.0
Pause 2000

SerTxd( "Writing " )
For b0 = 0 To 255
  b1 = b0 + 3
  Gosub WriteTo08M2
  SerTxd( "." )
Next
SerTxd( CR, LF )

Do

  For b0 = 0 To 255
    Gosub ReadFrom08M2
    SerTxd( "At ", #b0, " = ", #b1, CR, LF )
  Next

  Pause 10000

Loop

WriteTo08M2:

  High   C.0
  Pause  1
  SerOut C.0, T2400, ( "W", b0, b1 )
  Low    C.0
  Return

ReadFrom08M2:

  High   C.0
  Pause  1
  SerOut C.0, T2400, ( "R", b0, 0 )
  SerIn  C.1, N2400, b1
  Low    C.0
  Return
Code:
#Picaxe 08M2
#No_Data

Low 4
Do
  Do : Loop Until pin3 = 0
  Do : Loop Until pin3 = 1
  SerIn 3, T2400, b0, b1, b2
  If b0 = "W" Then
    Write b1, b2
  Else
    Read  b1, b2
    SerOut 4, N2400, ( b2 )
  End If
Loop
 

Lobobo

Member
Thanks guys. In both examples it shows that serin, serout over ordinary outputs works better than standard serial pins with sertxd. Of course the most important is to achieve the target, to get it working, but I have learnt that some tasks surprisingly doesn't do as expected like sertxd...
Anyway ,Thank you very much. I have messages coming now.
 

hippy

Ex-Staff (retired)
SERRXD and SERTXD can be used as SERIN and SEROUT can but there isn't the flexibility of signal polarity, you face the difficulty of interfacing for inter-PICAXE working without interfering with the download mechanism, and of course you usually lose easy debugging ability.

If SERTXD is used in downloading or debugging, and controls something else, there's every chance that a download or using debugging will confuse that something else which can also cause problems.

Best way is to get it all fully working and tested first with SERIN and SEROUT then, if SERRXD and/or SERTXD connections are essential, swap to those one at a time, altering the code as appropriately.

I'd recommend that unless absolutely required then use SERIN and SEROUT. It's often easier to use a larger PICAXE with more pins to allow that than struggling with fewer pins. Once you have lost download or debugging abilities it's hard to get them back and that can present problems if code needs to be changed or 'stops working' and you have to try and figure out why.
 
Top