View previous topic :: View next topic |
Author |
Message |
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Tue Jan 27, 2015 9:58 am Post subject: i2c multibus in 2.0.7.8.001 |
|
|
Hi All,
I'm currently playing with the new i2c multibus lib and am having major Problems getting it working. If I use the following code it works as expected (i2c bus scan finds all chips):-
Code: |
$lib "i2cv2.lib"
Config I2cdelay = 5
Config Scl = Portb.0 '
Config Sda = Portb.1 'setup I2C bus
I2cinit 'init the pins and state
|
If I use the following code the i2c scanner doesn't find anything on the i2c bus
Code: |
Config I2cdelay = 5
$lib "i2c-multibus.lib"
Config I2cbus = 0 , Scl = Portb.0 , Sda = Portb.1 'each bus requires a configuration of the SCL and SDA pins
I2cbus = 0
I2cinit 'init the pins and state
|
The rest of the code is identical.
Regards
Ian Dobson
(BASCOM-AVR version : 2.0.7.8 ) _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 27, 2015 10:16 am Post subject: |
|
|
which chip do you use?
this lib was developed for a customer who wanted to share with bascom users.
we tested with proteus and 4 slaves.
if a normal soft i2c works, the multi should work too. The multi was based on the i2cv2.
I assume you do have pull ups ?
you can best put in some ERR prints to see which commands fail.
or try the sample from the samples folder.
since you use portb it is unlikely there is a problem with the port address (the ddrd, port and pin need to be in sequence without gaps) _________________ Mark |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Tue Jan 27, 2015 10:51 am Post subject: |
|
|
Hello Marc,
Using a m1284pdef @ 3.684MHz (rampz maybe?).
I have external pullups on the bus.
The i2cv2 lib works without any Problems (I left it running over night "pinging" all sensors on the bus).
I've already sent an email to Support@mcselec.com with a copy of the code/Compiler Output.
The code is almost the same as the multibus example, apart from cpu, stack sizes and buffered Serial Output.
For the i2cbus scanner I'm just using:
Code: |
Print #2 , "i2c bus=";
For Temp_byte = 0 To 254 Step 2 'Scan every even address
I2cstart 'Ping chip
I2cwbyte Temp_byte 'get result
If Err = 0 Then 'err=hw problem
Print #2 , Temp_byte ; "," ; 'no error so device
End If 'ie. no i2c device
I2cstop 'stop bus
Next Temp_byte 'loop through each sensor
Print #2 , ""
|
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 27, 2015 3:07 pm Post subject: |
|
|
using my original test code with 4 slaves i could not find a problem. i2c traffic was ok too. but then i noticed the ERR bit.
it does work but the ERR bit is not set correctly. that is why the scanner will not work.
the reason is a bug. it is simple to fix :
-open the lib file
- search for the code
_i2c_get_ack:
rcall _SDA_HIGH ; release SDA to make it 1
Rcall _i2c_hp_delay ; half period delay
Rcall _release_scl ; release scl to make it 1
Rcall _i2c_hp_delay ; half period delay
Clt ; clear t flag
ld r23,Z
and r23,r10 ; and with sda ORmask , which will leave only sda bit 0/1
^^^^^^ THIS MUST BE R10 and NOT R11
breq _i2c_write2 ; check result of Z
Set ; set t flag
_i2c_write2:
- change r11 into r10 and save and compile the lib _________________ Mark |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Tue Jan 27, 2015 3:30 pm Post subject: |
|
|
Hello Mark,
Thanks for the very quick answer. The scanner is now working:-
Code: |
i2c bus 0 =2,10,64,240,
i2c bus 1 =78,92,94,146,160,162,
i2c bus 0 =2,10,64,240,
i2c bus 1 =78,92,94,146,160,162,
|
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Tue Feb 03, 2015 5:05 am Post subject: |
|
|
Health to you!
When using I2cbus, configuration CSL and SDA is allowed only on one port?
So works!
Config I2cbus = 0 , Scl = Portc.1 , Sda = Portc.0
Config I2cbus = 1 , Scl = Portb.2 , Sda = Portb.3
Config I2cbus = 2 , Scl = Portd.5 , Sda = Portd.4
Config I2cbus = 3 , Scl = Portd.7 , Sda = Portd.6
On different ports does not work, so conceived, or a small glitch?
Config I2cbus = 0 , Scl = Portc.1 , Sda = Portc.0
Config I2cbus = 1 , Scl = Portb.2 , Sda = Portb.3
Config I2cbus = 2 , Scl = Portd.5 , Sda = Portd.4
And so, not work?
Config I2cbus = 3 , Scl = Portb.7 , Sda = Portd.6 |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Tue Feb 03, 2015 7:47 am Post subject: |
|
|
Hello,
Sorry I don't understand what you mean, I can't see the difference in your examples. I'm using this:-
Config I2cdelay = 5
Config I2cbus = 0 , Scl = Portb.0 , Sda = Portb.1 'each bus requires a configuration of the SCL and SDA pins
Config I2cbus = 1 , Scl = Portd.6 , Sda = Portd.7 'each bus requires a configuration of the SCL and SDA pins
I2cbus = 0
I2cinit
I2cbus = 1
I2cinit
and it works for me.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Feb 03, 2015 9:48 am Post subject: |
|
|
yes the scl and sda pins must be on the same port. this is because this is dynamic code and a pointer to the pin is passed.
the pin,ddr and port registers also must be in normal sequence : PIN, DDR, PORT
Some older chips have odd orders for some ports, or missing registers. Will add this to the help. _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Feb 03, 2015 9:53 am Post subject: |
|
|
I added this info:
[PICTURE notice.jpg]Both SCL and SDA pins must be on the same PORT. Also, the PIN, DDR and PORT register addresses of the processor must be in ascending order and need to exist.
For example the M1284P portA group :
PORTA = $02
DDRA = $01
PINA = $00
This is ok to use. But some processors have no DDR register because a port can only be used in output or input mode. Such a port can not be used.
An example of a bad port is PORTF in the M128. As you can see there is a gap in the address between PINF and DDRF and this will make it fail.
PORTF = $62
DDRF = $61
PINF = $00 _________________ Mark |
|
Back to top |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Tue Feb 03, 2015 4:16 pm Post subject: |
|
|
Many thanks for the clarification! |
|
Back to top |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Mon Feb 09, 2015 7:06 am Post subject: |
|
|
Health to you!
Please tell me, does not work concluded on LCD RDX0xxx when using multi i2s? |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Mon Feb 09, 2015 9:42 am Post subject: |
|
|
Hello,
You Need to init each i2c bus
This won't work:
Code: | For Channel_i2c = 0 To 1
I2cbus = 0
I2cinit
Waitms 50
Next |
This should work
Code: | For Channel_i2c = 0 To 1
I2cbus = Channel_i2c
I2cinit
Waitms 50
Next |
Don't Forget to select the correct i2cbus before using it!
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Mon Feb 09, 2015 10:09 am Post subject: |
|
|
It remains from different attempts.
Code: | $map
$regfile = "m328pdef.dat" 'http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf
$crystal = 1000000
$framesize = 64
$hwstack = 64
$swstack = 64
'===============================================================================
' C O N F I G U R A T I O N LCD
'===============================================================================
'---------------- Used for library LCD RDX0xxx -------------------------------
' It is necessary to declare the bus initialization i2c, otherwise not working
$lib "glcd-UC1601.lib"
'===============================================================================
' C O N F I G U R A T I O N i2c
'===============================================================================
$lib "i2c-multibus.lib"
Config I2cdelay = 1
Config I2cbus = 0 , Sda = Portc.4 , Scl = Portc.5
Config I2cbus = 1 , Sda = Portc.2 , Scl = Portc.3
Config I2cbus = 2 , Sda = Portc.0 , Scl = Portc.1
Config I2cbus = 3 , Sda = Portb.1 , Scl = Portb.2
Dim Channel_i2c As Byte
For Channel_i2c = 0 To 3
I2cbus = Channel_i2c
I2cinit
Waitms 50
Next
I2cbus = 0
'===============================================================================
' C O N F I G U R A T I O N LCD
'===============================================================================
Config Graphlcd = 192x64sed ', Rst = Portc.3 'Optional Hardware Reset
' Select the type of LCD RDX0xxx: 0 = RDX0032 or RDX0048; 1 = RDX0077; 2 = RDX0120; 3 = RDX0154
Const Lcd_type = 3 ' Select the type of LCD RDX0xxx: 0 = RDX0032 or RDX0048; 1 = RDX0077; 2 = RDX0120; 3 = RDX0154
' Select the type of LCD RDX0xxx: 0 = RDX0032 or RDX0048; 1 = RDX0077; 2 = RDX0120; 3 = RDX0154
Initlcd
Waitms 50
Const Rotate_180 = 0 ' 1=Rotate 180°, 0=Not Rotate
Lcdcontrast 100 ' contrast
' Glcdcmd 164 ' Turning off all the pixels
' Glcdcmd 165 ' Inclusion of all pixels
' Glcdcmd 166 ' Output in the positive
' Glcdcmd 167 ' The conclusion in the negative
' Glcdcmd 192 ' Hardware 180 ° rotation
' Glcdcmd 194 ' Rotating in X
' Glcdcmd 196 ' Rotating in Y
' Glcdcmd 198 ' Rotating the X and Y
Cls
'===============================================================================
Do
Setfont Font_6x8
Lcdat 1 , 1 , "Health to You"
Wait 1
Cls
Loop
End
'===============================================================================
$include "Font_6x8.font"
|
Tried all the options, and does not work!
Last edited by sasha_1973 on Mon Feb 09, 2015 12:20 pm; edited 1 time in total |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Mon Feb 09, 2015 11:52 am Post subject: |
|
|
Hi,
OK in your example that you say works SDA/SCL is on PortC4/5
In the Version that you say doesn't work, SDA/SCL on PortC4/5 is on bus 0 but in your code you select bus 3????
Just try a simple i2cbus scan for all your i2c buses just to see if anything works.
Also may be increase you i2cdelay a bit (once you get it working you can start seeing how fast your Hardware can run).
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Mon Feb 09, 2015 12:04 pm Post subject: |
|
|
Tried all possible options, and does not work!
Config I2cdelay = 1...100
I2cbus = 0....3
If you use the version without the multi i2c, everything works! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|