Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:28 25 Nov 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 : I2C AND MMBASIC

Author Message
ratsac
Newbie

Joined: 19/12/2011
Location: Australia
Posts: 8
Posted: 08:59pm 19 Dec 2011
Copy link to clipboard 
Print this post

Hi just new to this forum and to maximite Computers
Can anyone assit or redirect me in the use of I2C procol
I am using mmbasic and a PCF8574 (8* i/o device).
The commands I have used are
I2CEN 10,100 (enables i2c )
I2CSEND 64,0,1,0 (should set ports to low)
Doesn’t work I know about using the negitive –330 ohm resister –pcf8574
Has anyone had success with any I2C devices and mmbasic
Thanks

 
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 09:25pm 19 Dec 2011
Copy link to clipboard 
Print this post

RTC I2C "write" code snippet (courtesy of Ken)

720 REM I2CSEND i2caddr, 0, 1 , &h0
725 I2CSEND i2caddr, 0, 10, 0, 0, 0, seconds, minutes, hours, day, rtcwday, month, year
730 I2CDIS
770 ? "0=ok 1=nack 2=timeout"; MM.I2C <------ observe this code !!!!


Another I2C "write" code snippet

460 ' Write Time to RTC
470 i2caddr = &h68 ' DS3231 I2C address
480 I2CEN 400,100 ' Enable I2C <--- high speed 100 ms timeout
490 I2CSEND i2caddr, 0, 8, &h0, seconds, minutes, hours, rtcwday, day, month, year
500 I2CDIS


I2CEN 10,100 (enables i2c )
Only 10 KHz ? For I2C speed?

Make sure you got the proper pullups for the I2C ??? You need two of them.
See the Maximite manual.

Is this I2C device a 3.3 VDC device or a I2C 5 VDC device? Make sure the pullups
are tied to the same device VCC

Edited by DuinoMiteMegaAn 2011-12-21
 
Olimex
Senior Member

Joined: 02/10/2011
Location: Bulgaria
Posts: 226
Posted: 09:47pm 19 Dec 2011
Copy link to clipboard 
Print this post

if A0,A1,A2 are wired to ground try:

I2CSEND 32,0,1,0

 
ratsac
Newbie

Joined: 19/12/2011
Location: Australia
Posts: 8
Posted: 09:52pm 20 Dec 2011
Copy link to clipboard 
Print this post

Thanks For assistance
Have tried addresses 64 end 32 with no success repower pcf8574 with own +5v
but alas still no success even raised speed and shorten bus
will look for a logic alternative.javascript:AddSmileyIcon('')
 
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 12:54am 21 Dec 2011
Copy link to clipboard 
Print this post

What are you using for pullups?

Put this line of code after writing to your device.

? "0=ok 1=nack 2=timeout"; MM.I2C '<------ observe this code !!!!


And tell me what you got?Edited by DuinoMiteMegaAn 2011-12-22
 
ratsac
Newbie

Joined: 19/12/2011
Location: Australia
Posts: 8
Posted: 03:18am 21 Dec 2011
Copy link to clipboard 
Print this post

Have tried adding mm.i2c
10 I2CEN 100,300
20 I2CSEND 64,0,1,0 (ALSO 32 TRIED)
30 I2CDIS
40 ? "0=OK 1=NACK 2=TIMEOUT";MM.I2C
THE RESULTS ARE ALWAYS THE SAME 0 0 2 0 2 0 2
EVEN IF I DISC I2C PORTS NO CHANGE
NIL COMMUNICATIONS RESULT
THE BOARD HAS 3 * 10KOHM PULLUP RESISTORS MOUNTED O0N BOARD

RATSAC
 
Olimex
Senior Member

Joined: 02/10/2011
Location: Bulgaria
Posts: 226
Posted: 05:53am 21 Dec 2011
Copy link to clipboard 
Print this post

64 is not correct address for this device
you have to remove the last R/W bit 0 from the address as it's add from MM-BASIC
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 09:38am 21 Dec 2011
Copy link to clipboard 
Print this post

  ratsac said   Have tried adding mm.i2c

THE BOARD HAS 3 * 10KOHM PULLUP RESISTORS MOUNTED O0N BOARD

RATSAC

Are the three pullups connected to the address pins and V+?
If so try 39 as the address (32 + 7)

Jim
VK7JH
MMedit   MMBasic Help
 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 09:18am 22 Dec 2011
Copy link to clipboard 
Print this post

Hi.


First I will assume that the PCF 8574 is correctly connected (common ground with the Maximite, A0 - A2 connected to ground, SDA connected to IO pin 12 and pulled high by a 2.7K resistor to the Vcc pin of the device, SCL connected to IO pin 13 and pulled high by a 2.7K resistor to the Vcc pin of the device).

The following code should set the output pins high, then read the state of the pins:


10 I2CEN 100,100
20 I2CSEND 32,0,1,&hff
30 ? "MM.I2C after send: "; MM.I2C
40 I2CRCV 32,0,1,port
50 ? "MM.I2C after recv: "; MM.I2C;", Data from port: ";HEX$(port)
60 I2CDIS
70 END


Please post the output if you are still having issues.

Regards

Gerard

Regards

Gerard (vk3cg/vk3grs)
 
ratsac
Newbie

Joined: 19/12/2011
Location: Australia
Posts: 8
Posted: 02:25am 23 Feb 2012
Copy link to clipboard 
Print this post

have tried the above program the responses i received are

MM.I2C after send: 0
[4] 40 I2CRCV 32,0,1,port
Error: Receive variable not found

operates output in device ok

also is there any difference when using ubw32 as nil result is given
 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 02:56am 23 Feb 2012
Copy link to clipboard 
Print this post

You need to define port as an array with length as to what you receive to expect back from the i2c device.

So in the used example make line 5 something like this:

[code]
5 Dim RDBuff(5) ' length according to the response expected from your device
[/code]

From the manual:
[code]
I2CRCV addr, bus_hold, rcvlen, rcvbuf [,sendlen, senddata [,sendata ....]]

----

Receive data from the I2C slave device with the optional ability to send some data first.
'addr' is the slave i2c address (note that 10 bit addressing is not supported).
'option' is a number between 0 and 3
1 = keep control of the bus after the command (a stop condition will not
be sent at the completion of the command)
2 = treat the address as a 10 bit address
3 = combine 1 and 2 (hold the bus and use 10 bit addresses).
'rcvlen' is the number of bytes to receive.
'rcvbuf' is the variable to receive the data - this is a one dimensional array or if rcvlen is 1 then this may be a normal variable. The array subscript does not have to be zero and will be honoured; also bounds checking is performed.
Optionally you can specify data to be sent first using 'sendlen' and 'senddat'. These parameters are used the same as in the I2CSEND command (ie, senddata can be a constant, an array or a string variable).
Examples:
I2CRCV &h6f, 1, 1, avar
I2CRCV &h6f, 1, 5, anarray(0)
I2CRCV &h6f, 1, 4, anarray(2), 3, &h12, &h34, &h89 I2CRCV &h6f, 1, 3, anarray(0), 4, anotherarray(0)
The automatic variable MM.I2C will hold the result of the transaction.
[/code]
Edited by crackerjack 2012-02-24
 
ratsac
Newbie

Joined: 19/12/2011
Location: Australia
Posts: 8
Posted: 04:32am 27 Feb 2012
Copy link to clipboard 
Print this post

THANKS FOR ALL YOUR VALUABLE ASSISTANCE

SAC
 
Print this page


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

© JAQ Software 2024