Let's Make Robots!

Inter PICAXE serial communications advice? -SOLVED-

Main code summary: The 28X2 raises a pin high, triggering the interrupt on the 08M2. The 28X2 then sends a number (1 to 5) via serial connection to the waiting 08M2. The 08M2 then I2Cs the correct bits to an I/O expander to turn on an LED pattern:

28X2:

main:{
for b28 = 1 to 5
 LED_code = b28
 'debug
 call I2C_LED_code
 pause 1000
next b28
goto main
}
I2C_LED_code:{
high serint
pause 2
low serint
pause 2
serout ser_pin,N2400_8,(LED_code) 'set for triggering the interrupt with 08M2
return
}

08M2:

HI2CSETUP I2CMASTER, PCF_byte, i2cfast, i2cbyte 'set for I/O expander I2C
setfreq m8
setint %00010000,%00010000 'reset interrupt; rising edge,serint pin
}
main:{
serin ser_pin,N2400_8,LED_byte
if LED_byte <> LED_byte_hist then
 select case LED_byte
  case 0
   goto main
  case 1 'looking
   call looking
  case 2 'locked
   call locked
  case 3 'alert
   call alert
  case 4 'startup on
   call startup_on
  case 5
   call startup_off
 end select
endif
goto main
}
looking:{
hi2cout latch_register, (blue)
return
}
locked:{
hi2cout latch_register, (green)
return
}
alert:{
hi2cout latch_register, (red)
return
}
startup_on:{
hi2cout latch_register, (white)
return
}
startup_off:{
hi2cout latch_register, (none)
return
}
interrupt:{
serin ser_pin,N2400_8,LED_byte
setint %00010000,%00010000 'reset interrupt; state,pin
return
}

Believe me when I tell you the pins are connected correctly like the interrupt going to C.4, etc etc etc. No special resistors involved either. I tried pullups/downs out of frustration and they didn't result in anything different. I can get a non-interrupt version of the program to work fine but the above gets me nothing. I've spent several days on this and I'm having varing degrees of non-success. I'm getting ready to cry blue smoke here.

FWIW I'm trying to get the serial communications done on the C.3 pin of the 08M2 and the C.3 pin of the 28X2. I know the C.3 pin needs an external diode on th 08M2 for serin commands but it doesn't make a difference if it's there or not. I even had the serial byte get picked up on C.4 when it should have been on C.3. I'm chalking that up to a low battery but this is the kind of thing that's making me nuts-o-bonkers-crazy. I even moved the serial in line to C.4 on the 08M2 but the results were the same.

Ok, time for some thumb sucking and then some sleep. Four days wasted on this bug. Thanks for lookin.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The PICAXEs didn't seem to like the breadboard config I had. The 08M2 was plugged into the breadboard directly, no programming jack, with bypass caps. I yanked it out of the breadboard and installed it in an old PICAXE 08 Protoboard I have. Then I plugged the protoboard into the circuit and everything started working. For giggles I plugged things back together the way they were and I started getting garbled transmissions again.

Thanks for everyone's input. The help was A+.

The code that worked: 


28X2:

setfreq m16
pause 5000
main:{
for b28 = 1 to 5
 LED_code = b28
 debug
 call I2C_LED_code
 pause 2000
next b28
goto main
}
I2C_LED_code:{
high ser_pin 'serial pin now doubles as interrupt trigger
pause 1
low ser_pin
serout ser_pin,N2400_16,(LED_code) 'set for triggering the interrupt with 08M2
return
}

 

08M2:

HI2CSETUP I2CMASTER, PCF_byte, i2cfast_16, i2cbyte 'set for I/O expander I2C
setfreq m16
setint %00001000,%00001000 'serial pin doubles as the interrupt
}
main:{
if LED_byte <> LED_byte_hist then
 LED_byte_hist = LED_byte
 select case LED_byte
  case 0
   goto main
  case 1
   call looking
  case 2
   call locked
  case 3
   call alert
  case 4
   call startup_on
  case 5
   call startup_off
 end select
endif
goto main
}
looking:{
hi2cout latch_register, (blue)
return
}
locked:{
hi2cout latch_register, (green)
return
}
alert:{
hi2cout latch_register, (red)
return
}
startup_on:{
hi2cout latch_register, (white)
return
}
startup_off:{
hi2cout latch_register, (none)
return
}
interrupt:{
serin ser_pin,N2400_16,LED_byte
debug
setint %00001000,%00001000 'reset interrupt; state,pin
return
}

did-int you have trouble with the bread board when you were waking your m8 walker ? or something like that 

might need to get a new 1 :) just saying

Good news Jax. Yes breadboards can cause problems. I think I told you I had a similar problem when I had a 433 mhz transmitter and receiver plugged into breadboards and I couldn't get them to work. My hallelujah moment came when I  unplugged them and just connected individual wires to them.

Can't wait to see what your working on.

[ See bottom of this post about things specific to the 08M2 ]

Here is what I used for Shrödinger's left brain interrupt and it did/does work.

This was an early test that I used to prove out that it worked.

I hooked a bumper switch on C.5 and in the program code, I put:

__________________________________________ 

#picaxe 28X2
#revision 9

 ` b4 is used to count number of times thru turn speed loop  \
symbol TurnRate = b5 ` b5 globally used for Speed of turn    \
 ` b6 used temporarily within Turn subs                                \
 ` b7 used as For-Next variable in Turn subs.                         \  IGNORE THESE LINES
symbol RMotrMask = b8 `Global Use                                   /
symbol LMotrMask = b9 `Global Use                                  /
symbol RMotrPins = b10 `Global Use                                /
symbol LMotrPins = b11 `Global Use                               /

setint %00000000, %00100000         ;switch on c.5       <--------THIS IS WHAT YOU NEED !

Main: 

(fill in main loop as needed)

interrupt:                                                                     <----------YOU NEED THIS TOO.

(whatever you want the interrupt to do goes here)

setint %00000000, %00100000                                   <---------- AND IMPORTANT TO RESET THE INTERRUPT AT THE END.
return                                                                        <----------and then return to main program where you left it.

--------------------------------------------------------

In the 'setint' command above, the first number %00000000 means to interrupt if the pin (or pins) goes low, and the second number %00100000 tells which pin (or pins) to check (in the C-group, pin #s = 76543210) As you see I set 5 (c.5) to a one, meaning to check pin C.5 for an interrupt.

 In the case of two Picaxe's talking to each other, hook an output of one picaxe to pin C.5 of the second. and switching it will trigger the interrupt on the other picaxe.

 

I later changed this command to read:  setint OR %00000000, %11100000

What this did was interrupt if C.5 -OR- C.6 -OR- C.7 went low and I had C.5 hooked to on output on the other (right brain) picaxe, while C.6 and C.7 were hooked to right and left bumper switches.

For the left brain to know which was the source of the interrupt, it scanned an I²C memory slot to see if a certain number was there, telling it the other brain sent the interrupt. If that number was not there, then the interrupt came from one of the bumper switches and it double-checked those inputs to see which one was active.

_____________________________________________

From page 215 of Manual#2:

    

setint

Syntax:

SETINT OFF

SETINT input,mask (AND condition)

SETINT AND input,mask (AND condition)

Additional options for M2, X1 and X2 parts:

SETINT OR input,mask (OR Condition)

SETINT NOT input,mask (NOT the AND Condition)

Additional options for X2 parts:

SETINT input,mask,port

SETINT NOT input,mask,port

 

So, I have not used it, but on M2, X1 or X2 parts you can also use the B inputs by changing the setint command to read:

setint OR %00000000, %00010100, B                       (or something similar)

The above line would trigger an input if B.2 -OR- B.4 goes low.

conversely,

setint AND %00010100, %00010100, B

would trigger an interrupt if B.2 -AND- B.4 are BOTH high.

__________________________________________________________________________________________

One note it that when you use the SERIN command, the interrupts are disabled.

but I see you are only using it within the interrupt after the interrupt was triggered. That is okay.

If there were a SERIN command in your main program it could cause you trouble.

Ok, I see that you are using the 08M2 C.4 input (pin 3 on the chip according to manual#1, page 27) for your interrupt triggering so pin 3 must go high to trigger an interrupt. You might temporarily try a regular switch tied from pin 3 to +5 volts and see if you get the action you are supposed to get. Someone else mentioned having it turn on an LED. That is a very good way to see if the interrupt did trigger.

__________________________________________________________________________________________

I hope this clears things up. The interrupts were really simple to use, as long as you get the right commands in your programming for what you are doing.

 hi jax, could you test the following code

TX code

#Picaxe 28X2
Do
  SerOut C.0, N2400,( b0 )
  b0 = b0 + 1
  Pause 1000
Loop

 

RX code

#Picaxe 08M2
Do
  SerIn C.0, N2400, b0
  SerTxd( #b0," " )
Loop

 

can the picaxe do both i2c and serial in the same program?

i've read that the timing between the x2 amd m2 is slightly off

jinx

I did something similar, no loop on the 08M2, it was just SERIN xx, GOTO MAIN. The X2 part was the same as yours but ended at when the loop hit five. Worked as expected.

Interesting to know about the X2/M2 timing thing. I'll have to get CABLIBFREQ a try maybe.

I'll plug in your code though, don't worry. If someone offers help, I'll ride it out to the end :) Thanks

I've got to go fix a TV for a friend tonight but afterwards I'm going to dig into this badboy. I'll do the LED testing like merser suggested and then if there is nothing gained, the physical teardown and rebuild of the circuit and start from v.0.1

Hate is a very stong word. That being said, I hate the teardown/rebuild thing.

have you set up the correct interrupt

if i read the manual correctly that should interrupted on 3 when high, i think you had it on 4? never used interrupts before ,get a second opinion 

 
setint %00001000,%00001000

 

Yeah, damn. The interrupt is on the right pin. The bits read backward (MSB...LSB??) so it reads "%76543210." Good eyes though. My heart got all rabbity for a second lol

I saw the comment you and Chuck wrote, and I think (after reading carefully the manual, and your comments) that Chuck is right.
On your code you have "setint %00010000,%00010000" and Chuck suggested "setint %00001000,%00001000".
If I am not mistaken you have the setint on pin4 and Chuck suggested pin3

basile

P.S.: Disclaimer: I know jack about PICAXE.