Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:43 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Maximite, I2c and PicAxe’s

Author Message
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5004
Posted: 01:37pm 29 Jul 2011
Copy link to clipboard 
Print this post

I'm diving in and having a go at learning to use I2C. I like the idea of I2C, especially if it lets a Maxiimite talk to the PicAxce range of chips.

For my test setup I have a 20X2 chip connected to the Maximite. Pin 12 (SDA) of the Maximite is to pin 13 of the 20X2, and Pin 13 (SCL) is going to pin 11 of the 20X2.

Now I'm getting confused on the speed settings and addresses. The PicAxe was set up as a slave on address &1010000, which I assume is &H50 for the Maximite, but even though it appears the Maximite is sending data ( I can see the data stream on my cro ), the PicAxe is ignoring it.

Just wondering if anyone has connected a Maximite to a PicAxe yet? The sample bits of code dont explain it very well, and the very different syntax between PicAxe and MMBasic isn't helping me, I'm not getting that light bulb moment when it all suddenly makes sense.

Once we get the Maximites talking to PicAxe, I think it will open up new possibilities. The PicAxes are very good at talking to other devices, like RC servos and steppers, and have PWM output.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 07:08pm 29 Jul 2011
Copy link to clipboard 
Print this post

Dont forget you need place your Picaxe or Maximite into slave mode


JG
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5004
Posted: 10:54pm 29 Jul 2011
Copy link to clipboard 
Print this post

Yeah did that, Or at least I think I did. The examples I find are a bit confusing, like some use the readI2c command, but others say thats outdated and use another command. I think its addressing I'm getting confused with.

I've added the 4.7k resistors too.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
stuarts

Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 194
Posted: 11:04pm 29 Jul 2011
Copy link to clipboard 
Print this post

Glenn, when you look at the I2C standard, you will see that the first byte is the address plus the r/w bit. the r/w bit is bit 0. So if the address of the slave is 1010000 then the first byte will be 10100000 or 10100001 depending upon whether it is read or write. the address byte will therefore be &HA0 or &HA1.

Stuart
Time is nature's way of keeping everything from happening all at once.
 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 11:06pm 29 Jul 2011
Copy link to clipboard 
Print this post

Hi Glenn.

If you can let me know what data you are intending to send from the Maximite to the PicAXE I will post some sample code for both the PicAXE and Maximite to get you started. I assume from your previous post that the PicAXE will be the slave.

Regards

Gerard (vk3cg/vk3grs)

Regards

Gerard (vk3cg/vk3grs)
 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 11:59pm 29 Jul 2011
Copy link to clipboard 
Print this post

Hi Glenn.

Here is some sample code (untested!) that will send 4 bytes from the Maximite to the PicAXE:


20 I2C_BusHold = 1
30 I2C_10BitAddr = 2

40 timeout = 1000 ' set I2C timeout to 1 second (1000 milliseconds)
50 speed = 100 ' set I2C bus speed to 100kHz
60 I2C_Option = 0 ' release I2C bus after each command (ie issue I2C stop)
70 addr = &h50 ' PicAXE address
80 complete = 0 ' interrupt flag byte

100 ' Maximite code to send 4 bytes of data to the PicAXE (slave)
101 ' The PicAxe emulates a serial EEPROM device, so it expects an address byte followed by the data bytes

110 i2cen speed,timeout,500 ' set i2c master mode with 100kHz bus, 1 second timeout and interrupt routine at line 500

200 i2csend addr,I2C_Option,5,0,&h40,&h41,&h42,&h43 ' send 1 address byte (0) and 4 databytes to the PicAXE
210 do while complete <> 1 ' wait for send command to complete
220 loop
230 complete = 0
240 if mm.i2c <> 0 then ' check for errors
250 ? "Error during i2csend - error: "; mm.i2c
260 else
270 ? "Send to PicAXE completed"
280 endif
290 end

500 ' I2C interrupt routine - just sets a flag
510 complete = 1
520 ireturn



'PicAXE code to read 4 bytes of data from Maximite.

init: hi2csetup i2cslave, %10100000

main:
if hi2cflag = 0 then main ; poll flag, else loop

hi2cflag = 0 ; reset flag
get 0,b1,b2,b3,b4 ; get 4 data bytes from Maximite
goto main


Regards

Gerard (vk3cg/vk3grs)

Regards

Gerard (vk3cg/vk3grs)
 
vasi

Guru

Joined: 23/03/2007
Location: Romania
Posts: 1697
Posted: 12:06am 30 Jul 2011
Copy link to clipboard 
Print this post

Hi Glenn,

Maybe these articles can help:
http://jallib.blogspot.com/2008/12/i2c-master.html
http://jallib.blogspot.com/2009/01/step-by-step-building-i2c -slave part 1
http://jallib.blogspot.com/2009/01/step-by-step-building-i2c -slave part 2
http://jallib.blogspot.com/2009/01/step-by-step-building-i2c -slave part 3 Edited by vasi 2011-07-31
Hobbit name: Togo Toadfoot of Frogmorton
Elvish name: Mablung Miriel
Beyound Arduino Lang
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5004
Posted: 12:31am 30 Jul 2011
Copy link to clipboard 
Print this post

Got it working. Thanks guys. Had the light bulb moment.

Looks like I had the PicAxe code working, but I was doing something wrong with the Maximite code.

Talk about a lot of code and hardware just to dim a LED

I'll play around with the code and post something back when I get it working. Basically its simply adjusting a LED brightness from the Maximite, pretty straight forward now, but lots of applications.

Glenn


The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5004
Posted: 04:06am 30 Jul 2011
Copy link to clipboard 
Print this post

OK, just a throw together. Using a Maximite to send commands to a PicAxe chip, in this case a 20X2. I did buy a 08M chip the other day for this, but then realised the 08M doesn't support I2C.

This is the Maximite code.

10 CLS
20 I2C_BusHold = 1
30 I2C_10BitAddr = 2
40 timeout = 1000 ' set I2C timeout to 1 second (1000 milliseconds)
50 speed = 100 ' set I2C bus speed to 100kHz
60 I2C_Option = 0 ' release I2C bus after each command (ie issue I2C stop)
70 addr = &h50 ' PicAXE address
80 complete = 0 ' interrupt flag byte
90 ' Maximite code to send 2 bytes of data to the PicAXE (slave)
100 ' The PicAxe emulates a serial EEPROM device, so it expects an address byte followed by the data bytes
110 I2CEN speed,timeout,260 ' set i2c master mode with 100kHz bus, 1 second timeout and interrupt routine at line 500
120 FOR tempdec=1 TO 150 STEP 5
130 GOSUB 290
140 I2CSEND addr, I2C_Option,3,0,&h01,hex
150 DO WHILE complete <> 1 ' wait for send command to complete
160 LOOP
170 complete = 0
180 IF MM.I2C <> 0 THEN ' check for errors
190 LOCATE 0,20 : ? "Error during i2csend - error: "; MM.I2C
200 ELSE
210 LOCATE 0,0 : ? "Dutycycle "; INT(100/150*tempdec); "%"
220 ENDIF
230 PAUSE 100
240 NEXT
250 END
260 ' I2C interrupt routine - just sets a flag
270 complete = 1
280 IRETURN
290 ' Convert to Hex
300 hex = FIX(tempdec / 10) * 16
310 hex = hex OR ((tempdec / 10) - (FIX(tempdec / 10))) * 10
320 RETURN

Its partly Gerards code above and the dec to hex converter from Johns work on the Internal RTC post. All its doing is sending a incrementing number to the PicAxe.

In the picaxe I have this code


init:
hi2csetup i2cslave, %10100000

main:
if hi2cflag = 0 then main ; poll flag, else loop
hi2cflag = 0 ; reset flag
get 0,b0, b1
if b0=1 then Option1
if b0=2 then Option2
goto main

Option1:
w2=b1*4
pwmout C.5, 199, w2 '5kHz PWM out, w2 duty cycle
goto main

Option2:
' Do other stuff
goto main

Again thanks to Gerard. Basically, the PicAxe reads b0 and b1 from memory, b0 is used to redirect the b1 data to whatever routine you want. The idea is the PicAxe chip could be have several "things" attached to its outputs, in this case we are only using Option1, which is PWM a LED connected to the C.5 pin. The PWMOUT command will continue to run once its value has been set.

Using the PicAxe chips for PWM free's up the Maximite to do other stuff.

GlennEdited by Gizmo 2011-07-31
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 01:39am 18 Aug 2011
Copy link to clipboard 
Print this post

*** ARE POSTS BELOW THE LATEST I2C EXAMPLES *****

Having now downloaded revision 2.5 of MM I'm keen to give Gerard's (aka sec061)implimentation of I2C a run maybe just speaking to a DS18B20 temperature sensor or a 1307 RTC.
Question is are their some examples posted or even a tutorial that I've not seen. I notice the examples to PicAxe in posts below.
Regards

RayB from Perth WA
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 03:09am 18 Aug 2011
Copy link to clipboard 
Print this post

Hi RayB

This thread has sample code for a I2C rtc http://www.thebackshed.com/forum/forum_posts.asp?TID=3790&PN =2

The DS18B20 is a one wire device not I2C ( Go vote for one wire support)

Regards

John
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 03:41am 18 Aug 2011
Copy link to clipboard 
Print this post

Excellent --- Thanks jman some of these posts get sooooo longggggg.

Of course your correct re DS18B20 being one wire - just getting excited having some I2C to get into maybe over the weekend.

My task is to now for example take the DATALOG.BAS example and add the I2C RTC using a FutureLec board them publish for all to use.

Thanks
RayB from Perth WA
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024