were fixing compiler errors and doing some testing on github - maple-ide/ branch=soft-i2c right now. It *may* be working by the time you get to it? It doesnt compile yet...heh. We added "Wire" to the external libs.
libmaple i2c API
(97 posts) (15 voices)-
Posted 5 years ago #
-
Well I won't be able to touch it for a few hours, so it might be working by the time you get to it.
Posted 5 years ago # -
We got something working. It's still pretty alpha, but using Wire semantics we can talk to the xl345. check it out in the soft-i2c branch of the maple-ide. To use it, go to sketch->import library->wire and use the regular arduino wire api.
if you build your own IDE, then just work out of the git repo. However, if you just want to dump this into your existing IDE installation, copy the "Wire" directory from here:
http://github.com/leaflabs/maple-ide/tree/soft-i2c/libraries/into the equivalent place in your IDE installation.
Let us know if it explodes.
Posted 5 years ago # -
I'll test it with my ADXL345 tonight (I'd test with more items, but the speed controllers are currently else where) and let you know how I go. If it all works, I'll write a guide on how to 'install' it.
Posted 5 years ago # -
<Testing of DS3231 RTC>
I got Wire to compile.Changes to my sketch.(above)
Made instance "TwoWire Wire;"Changed SDA pin in Wire.h from 7 to 5
Testing DS3231 Results: Failed.
Time/date is "garbled" or received time / date values are out of range?Testing changes:
Changed I2C delay from 1 to (2 thru 5) with no results.Note: I did check the end of transmission return values and they were 0;
Note: The DS3231 ChronoDot was previously tested good on another 3.3 VDC
microcontroller.
Note: I only copied "Wire" into the libraries if other changes were made to other
modules then let me know.
Note: The DS3231 has a fast clock I2C interface. (400KHz)----------------------------------------------------------------------
Questions: What determines the SCL clock frequency of the I2C, in your software?
Posted 5 years ago # -
Additional troubleshooting I2C DS3231 RTC details.
I changed I/O pins SCL & SDA - no help.
I put delays between wire.send - no help.
I put delays between wire.receive - no help.
I changed both pullups from 10k to 1K to 3.8K - no help.I believe there is something in the alpha I2C code that does not translate the bytes
properly to and from the DS3231 RTC?Another question: What is the GPIO speed of the Maple?
also ...
What determines the SCL clock frequency of the I2C, in your software?Posted 5 years ago # -
According to http://leaflabs.com/docs/maple/
GPIOs toggle at up to 18MHz
I haven't had a chance to look at the SoftI2C library yet and doubt I will until tomorrow.
Posted 5 years ago # -
My quotes above: "Time/date is "garbled" or received time / date values are out of range?"
"I believe there is something in the alpha I2C code that does not translate the bytes
properly to and from the DS3231 RTC?"Reply: The I2c library Wire (alpha - soft I2C) file "Wire.cpp" needed a read patch to make it work properly. Just replace the old I2C function "i2c_shift_in(); with this patch below.
Note: I left the I2C-delay at 1 in wire.cpp.
Note: This patch made it possible for my I2C DS3231 RTC to work. (See sketch below)
Note: No other changes were made to the wire library except for the SDA SCL pin #s.
Note: More testing is on going ..."IC2 does not work until a RTC works with it!" <-------- Today is a great day!
//---------------------------------------------------------------------
// Patch or fix for wire.cpp (software I2C alpha)
// Just remove the other function and replace with this one.uint8 i2c_shift_in(Port port) {
char x = 0;
uint8 data = 0;
digitalWrite(port.sda,HIGH);
for(x=0; x<8; x++) {
data <<= 1;
do {
digitalWrite(port.scl,HIGH);
}
while((digitalRead(port.scl))==0); // wait for any SCL clock stretching
I2C_DELAY;
if((digitalRead(port.sda))) data |= 1;
digitalWrite(port.scl,LOW);
}
if(i2c_get_ack(port)) digitalWrite(port.sda,LOW);
else digitalWrite(port.sda,HIGH);
digitalWrite(port.scl,HIGH);
I2C_DELAY; // send (N)ACK bit
digitalWrite(port.scl,LOW);
digitalWrite(port.sda,HIGH);
return data;
}
//--------------------------------------------------------------------------
// Sketch for Maxim-IC RTC Ds3231//--------------------------------------------------------
/*
Program Description: Reads and writes to the Maxim-IC I2C RTC - DS3231Program Name: DS3231
Author: Hacker
Date: 8/16/10
Time: 01:35
Platform: Windows XP SP3
Devices: Maple/I2C RTC DS3231 w/3.8K pullups
IDE: 0.0.6 uses soft I2C wire library (alpha) with patch fix
Status: Works OK ... more testing on going
*/#include <Wire.h> // <----- software I2C wire library (alpha) with patch fix
#define BLUE_LED_PIN 13
#define COMM Serial2
// ---------------------DS3231 I2C RTC Defines-----------------------------------------
#define DS3231_I2C_ADDRESS 0x68 //I2C Addresss of DS3231//--------------------- Global variables----------------------------------------------
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; // DS3231 global variables
//int second, minute, hour, dayOfWeek, dayOfMonth, month, year; // DS3231 global variables
int toggle = 0;/* ----------------------- DS3231 I2C Functions -----------------------------*/
//DS3231 I2C// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}// Stops the DS3231, but it has the side effect of setting seconds to 0
// Probably only want to use this for testing
/*void stopDS3231()
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.send(0);
Wire.send(0x80);
Wire.endTransmission();
}*/// 1) Sets the date and time on the DS3231
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock <-----------------MILITARY TIME !!!!!!!!!!!!-------------
// Assumes you're passing in valid numbersvoid setDateDS3231(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7 Sunday = 1
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDS3231)
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}// Gets the date and time from the DS3231
void getDateDS3231(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}void read_RTC_DS3231() // DS3231 local library function call - FOR TESTING ONLY!
{
// second, // 0-59
// minute, // 0-59
// hour, // 1-23
// dayOfWeek, // 1-7 1=Sunday
// dayOfMonth, // 1-28/29/30/31
// month, // 1-12
// year) // 0-99getDateDS3231(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); // <----- uses global variables !!!!
COMM.print(hour, DEC);
COMM.print(":");
COMM.print(minute, DEC);
COMM.print(":");
COMM.print(second, DEC);
COMM.print(" ");
COMM.print(month, DEC);
COMM.print("/");
COMM.print(dayOfMonth, DEC);
COMM.print("/");
COMM.print(year, DEC);
COMM.print(" Day_of_week:");
COMM.println(dayOfWeek, DEC);
}void set_Time_Date(void)
{
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDS3231 call.
second = 0;
minute = 21;
hour = 15; //<---------------Military Time !!!!!
dayOfWeek = 4; // Sunday = 1
dayOfMonth = 16;
month = 9;
year = 10;
setDateDS3231(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}TwoWire Wire; //<--------------------- Instance <---------------<<<<<<<<<<<<<
void setup()
{
/* Set up the LED to blink */
pinMode(BLUE_LED_PIN, OUTPUT);COMM.begin(9600);
Wire.begin(); // DS3231 I2C pins setup default in cpp >>>-------> I2C- SDA D30 SCL D29
//set_Time_Date(); //<-------------<<<< use once and comment out
delay(1000);} // End of setup code
void loop()
{
toggle ^= 1;
digitalWrite(BLUE_LED_PIN, toggle);
// Read DS-1307 RTC
read_RTC_DS3231(); // DS3231 local library function call - FOR TESTING ONLY!
delay(750);
}// end of main loop
//-------------------------------------------------------------------------------------BTW ... This code will also work for the less accurate but cheaper
I2C DS1307 RTC - no changes required.Posted 5 years ago # -
Quote: "This code will also work for the less accurate but cheaper
I2C DS1307 RTC - no changes required."Reply: Clarification ... The DS1307 is software compatible but ... it will not work
on the 3.3 VDC Maple. The DS1307 VCC supply only goes down to ~4 VDC.
Sorry, for the mis-understanding.Posted 5 years ago # -
Great! So the patch is that youre handling I2C clock streching now. I dont think there was a bug in how we were parsing the data (data += digitalRead(sda) << (7-i) ), we were getting good data out of an xl345 with it.
The Wire library here is by no means the final version for 0.0.7 (0.0.7 will still be soft i2c though). Well add support for configurable i2c frequency (I bet it will max out at ~750KHz as written). I2C is a slow protocol so we were generous with ourselves with all the function calls.
In case you didnt notice, the wire.begin can now take two arguments, scl and sda! ala: Wire.begin(8,10); Of course, thanks to c++, the Wire.begin() on the default pins is still good.
Posted 5 years ago # -
Oh I should mention....this was one of your "markers of maturity" for maple! Yes! Thanks for the help! Well push your patch in.
Posted 5 years ago # -
Quote: "this was one of your "markers of maturity" for maple!"
Reply: And the other "marker" are external interrupts, on ALL the Maple's I/O pins, with the level interrupt option.
Posted 5 years ago # -
for my part, I'm unable to make my itg-3200 work! event with the patch of leaflabsandy. every thing is plugged like I plug it on the arduino! but, no way I can have a response from the gyro!
Posted 5 years ago # -
Kenny9999 ... We need more "data" so we can help you out!
So far, soft I2C works on xl345 and the DS3231 RTC.Post your test code!
What size (ohms resistance) are your I2C pullups?
Are you using the interrupt pin?
Have you checked your voltages to see if they are correct?
Have you tried to adjust the built-in delay? (Default 1 <in wire.cpp>)
Have you tried in small steps (without the full Arduino code) to read and/or write to the itg-3200?
A good "test code" would be to read reg. 0 "Who am I" which only reads the I2C address.
It could be a possibility that "burst reads and writes" needs adjustment in the soft I2C.Posted 5 years ago # -
Try again with many configuration, no luck
/////////////////////////////////////////////////////////////
#include "Wire.h"
TwoWire Wire;#define GYRO_ADDRESS 0x69
void setup()
{
SerialUSB.println("SETUP");Wire.begin();
}
void loop()
{
SerialUSB.println("LOOP");Wire.beginTransmission(GYRO_ADDRESS);
Wire.send(0x00);
Wire.endTransmission();
delay(50);
Wire.requestFrom(GYRO_ADDRESS, 1);
int data = Wire.receive();
if (data == GYRO_ADDRESS)
{
SerialUSB.println("yeeee");
}
else
{
SerialUSB.println(data);
}delay(250);
}/////////////////////////////////////////////////////////////////
voltage is ok at 3.3v
no pull ups used since I do not need any on the arduino, this may be the problem!
but, I do not understand any of thoses pull-up down thing, I have no backgroung in electricity or electronics! But, just hoping to bypass this pull-up thing
no interrupt pin used
Tried many delay, many pins, mostly SCL on 6 and SDA on 7 as defined in the Wire.h files
Also tried 29 and 30. and 5 and 9... never get other answer than 255.Posted 5 years ago #
Reply »
You must log in to post.