20m2 code not working on 20x2

Sam1

New member
Hi,
I've searched forums, manuals etc but am stuck. Bit of a beginner so I hope I can be clear...

On my prototype I've a 20m2 performing actions based on a value it gets from a 14m2 via serin. I now wish to use a 20x2 in place of the 20m2 but the 20x2 refuses to work when I do a straight swap.

I have removed most of my code to test where the problem is and am still stuck.

The below test code works perfectly with the 20m2 but not 20x2. It uses an interrupt to blink an LED based on the val value received from the 14m2. Am I missing something obvious? The interrupt from the 14m2 is coming in on pin C.1

The reason I want to use a 20x2 is because I read elsewhere on this forum the x2 would be better to read MIDI which is the next step on my project.

Thanks in advance,
Sam

Code:
#picaxe 20x2   'change as necessary

symbol val = b1
symbol num = b2

main:

    let val = 0
    let num = 0

    setint %00000010, %00000010, C

stop

interrupt:

    high C.7                     ' send RTR message to other chip
    
    serin C.0, N2400, val             ' get the message

    gosub SendOutput              'act on the message

    low C.7                     ' clear RTR message to other chip to confirm message received

    do pause 5 loop until pinc.1 = 0     'wait to see that other chip has closed RTS message

      setint %00000010, %00000010, C     ' reset the interrupt

return
SendOutput:

    for num = 1 to val step 1
        high B.1
        pause 100
        low B.1
        pause 100
    next num
            
return
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

There's nothing I can see which would appear to be wrong with the code, anything which would make it not work on the 20X2 exactly as it does on the 20M2.

You could add "#TERMINAL 9600" at the top of the code and add SERTXD commands to see what's going on.

I would try these three programs first ...
Code:
#Picaxe 20X2
#Terminal 9600
#No_Data

Pause 2000
SerTxd( "Button Push Test Started", CR, LF )
Do
  Do : Loop Until pinC.1 = 1
  SerTxd(" Button on C.1 pushed", CR, LF )
  Do : Loop Until pinC.1 = 0
  SerTxd(" Button on C.1 released", CR, LF )
Loop
Code:
#Picaxe 20X2
#Terminal 9600
#No_Data

Pause 2000
SerTxd( "Button Interrupt Test Started", CR, LF )
Gosub Interrupt_Enable
Do:Loop

Interrupt:
  SerTxd( "Button on C.1 pushed", CR, LF )
  Do : Loop Until pinC.1 = 0
  SerTxd( "Button on C.1 released", CR, LF )
Interrupt_Enable:
  SetInt %00000010, %00000010, C
  Return
Code:
#Picaxe 20X2
#Terminal 9600
#No_Data

Pause 2000
SerTxd( "SERIN Test Started", CR, LF )
Do
  SerTxd( "C.7 receive ... " )
  High C.7
  SerIn C.0, N2400, b0
  Low C.7
  SerTxd( "Got ", #b0, CR, LF )
  Pause 1000
Loop
The #NO_DATA makes downloading slightly quicker when not using Data Eeprom.
 

inglewoodpete

Senior Member
Can you confirm that the download circuit resistors (10k + 22k) remain in place, even when the download cable is disconnected.
 

Sam1

New member
I'm sorry I've taken so long to answer - many other things eating my time...

Hippy's code all seemed to work ok.

I've got it working but I'm not really sure of the cause. I had a wrong value resistor on the 14m2 (the sender chip) which I corrected and also had way too high resistors between the two chips. I've made the circuit a lot simpler to get it to work (great) but really don't know how (not so great). Not a very methodical person I'm afraid.

Anyway. Now the communication is working at the chips' default frequencies I changed the 20x2 to 64MHz (setfreq m64) to get ready to start working out how to read MIDI. Now the serin isn't working again!

Is there something affecting serin when frequency is changed?
 

hippy

Technical Support
Staff member
Is there something affecting serin when frequency is changed?
You need to adjust all the baud rates to indicate you are running at 64MHz, for example N2400 would become N2400_64.

But that isn't a valid baud rate for 64MHz operation. It needs to be N9600_64, N19200_64, N38400_64 or N76800_64.
 

Aries

New Member
If you do need to stay at 2400 baud, then you can surround the serin (or serout) with appropriate setfreq statements - e.g.
Code:
Do
  SerTxd( "C.7 receive ... " )
  setfreq m8
  pause 100    ' allow frequency to stabilise
  High C.7
  SerIn C.0, N2400, b0
  setfreq m64
  pause 100    ' allow frequency to stabilise
  Low C.7
  SerTxd( "Got ", #b0, CR, LF )
  Pause 1000
Loop
If you don't have the sertxd statements in the loop, then you can put the setfreq statements outside the loop. Without the pauses, the sertxd outputs are often slightly corrupted.
 
Top