i2c between 08M2 and 18M2

Vroom

Member
I have done with i2c between two 20X2 communicate use LEDs, send command use i2cmaster, and receive different i2cslave with if hi2cflag = 0 then, hi2cflag = 0, get hi2clast,b1 for partX2 only.
Anyway, I have trying use 08M2 send to 18M2 receive, same i2cmaster both, for practice with led first before own project, not working hi2cin nothing response LED, something wrong.

For the 08M2 sender
Code:
'08M2 sender

hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte

main:	

let b1=2
hi2cout 0,(b1)
pause 500

let b1=3
hi2cout 0,(b1)
pause 500

goto main

and for the 18M2 receiver
Code:
'18M2 receiver
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte

main:
hi2cin 0, (b1)

if b1=2 then one
if b1=3 then two

goto main

one:
high C.1
goto main


two:
low C.1
goto main

Sorry, I have tried to figure out how put code area on post, I cant remember where click add code or type.
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
You cannot simply use HI2CIN to receive from a PICAXE which is using HI2COUT. You can only use HI2COUT and HI2CIN to interact with an I2C device or a PICAXE acting as an I2C slave device. None of the PICAXE M2 chips can act as an I2C slave device.
 

jims

Senior Member
This routine will let you use "background receive" on the 18M2 hserin pin; with the 08M2 xmitting data using serout. Jims
Code:
[color=Green]'******************************************
'* Picaxe 18m2 uses hserin and select case
'* to turn B.7 high (ON) or low (OFF).
'******************************************[/color]

[color=Blue]symbol rcv_pin[/color][color=DarkCyan]=[/color][color=Blue]B.2      [/color][color=Green]'pin 8 (hserin).[/color]
[color=Blue]symbol [/color][color=Purple]rcv_data[/color][color=DarkCyan]=[/color][color=Purple]w1[/color]
[color=Navy]#picaxe [/color][color=Black]18m2[/color]
[color=Blue]SetFreq M8
HSerSetup B9600_8[/color][color=Black], [/color][color=Navy]%000 [/color][color=Green]'Setup baud 9600 @ 8Mhz
' "H" = 72  "L" =76 .[/color]
[color=Black]main:[/color]
[color=Blue]Do
  [/color][color=Purple]b3 [/color][color=DarkCyan]= [/color][color=Navy]1
  [/color][color=Blue]Do
    HSerIn [/color][color=Purple]rcv_data     [/color][color=Green]'Put hserin data byte into W0.
  [/color][color=Blue]Loop Until [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]0     [/color][color=Green]'Wait for data in.
  [/color][color=Blue]Select Case [/color][color=Purple]b2
    [/color][color=Blue]Case [/color][color=Red]"H" [/color][color=Black]: [/color][color=Blue]High B.7 [/color][color=Green]'If data is H then high B.7
    [/color][color=Blue]Case [/color][color=Red]"L" [/color][color=Black]: [/color][color=Blue]Low  B.7 [/color][color=Green]'If data is L then low B.7.
  [/color][color=Blue]End Select
Loop[/color]
 
Last edited:

westaust55

Moderator
Sorry, I have tried to figure out how put code area on post, I cant remember where click add code or type.
Option 1:
manually - by hand, insert [code] and [/code] tags at the start and end of the code section respectively.
It's explained in the ReadMe First! sticky thread at the top of the Active forum area:
http://www.picaxeforum.co.uk/showthread.php?7679-Read-Me-First!

Option 2:
Within the PE use the EDIT/Copy for forum
and then just past into the post

Option 3:
Click on the Go Advanced button at bottom right of the Post area
then select the code area and click on the hash (#) icon at right of middle row to ad the code tags


Fixed you post for you on this occassion.
 
Last edited by a moderator:
Top