I’m porting an RTC over I²C mini library from Arduino nano to Maple mini: https://github.com/Naguissa/RTCLib
I’m trying to use HardWare I²C ports and added a private variable handling correct Wire option:
#ifdef _VARIANT_ARDUINO_STM32_
HardWire RTCLIB_WIRE = HardWire(2);
#else
Wire RTCLIB_WIRE = Wire;
#endif
*.h:
#define WIRE_WRITE HWIRE.write
Setting up my I2c OLED on I2c2
Setting up Serial (is HW on nucleo), Serial1 and Serial2
looping:
draw some things on OLED
serial.print on all three ports.
code is running and running….
Results for maple mini:
Using I2c1 (because I2c2 shares USART3)
Everything works as expected, so HW wire and serial(1-3) together is working for me
I’ll check later.
However we need to do some testing first to see if this change has any unintended side effects
See the announcement section
BTW the new code also doesn’t flash the LED in an ASSERT
However the number of places that use ASSERT is very small, so it seems unlikely that the code has asserted
If it is an assert try connecting a USB to serial adapter to hardware serial, it may be writing out an error message
Serial –> Nothing shown. It’s RX & TX between USB and SPI2 pins, right?
FILE: hardware/Arduino_STM32/STM32F1/cores/maple/libmaple/i2c.c
FUNCTION: int32 i2c_master_xfer
LINE: ASSERT(dev->state == I2C_STATE_IDLE);
LINE #: 228
Seems I have latest version as mini’s led is not flashing.
As test I’m using this:
#include "Arduino.h"
#ifdef _VARIANT_ARDUINO_STM32_
#include "HardWire.h"
#else
#include "Wire.h"
#endif
#include "RTCLib.h"
RTCLib rtc;
unsigned int pos;
void setup() {
delay (2000);
Serial.begin(9600);
Serial.println("Serial OK");
// Max position: 32767
for(pos = 0; pos < 100; pos++) {
rtc.eeprom_write(pos, (unsigned char) pos % 256);
}
// Only used once, then disabled
rtc.set(0, 42, 16, 6, 2, 5, 15);
// RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
pos = 0;
#ifdef _VARIANT_ARDUINO_STM32_
Serial.println("Board: Maple");
#else
Serial.println("Board: Other");
#endif
}
void loop() {
Serial.println();
Serial.println("Loop!");
rtc.refresh();
Serial.print("RTC DateTime: ");
Serial.print(rtc.year());
Serial.print('/');
Serial.print(rtc.month());
Serial.print('/');
Serial.print(rtc.day());
Serial.print(' ');
Serial.print(rtc.hour());
Serial.print(':');
Serial.print(rtc.minute());
Serial.print(':');
Serial.print(rtc.second());
Serial.print(" DOW: ");
Serial.print(rtc.dayOfWeek());
Serial.print(" ---- ");
Serial.print(pos);
Serial.print(": ");
Serial.print(rtc.eeprom_read(pos));
Serial.println();
pos++;
pos %= 1000;
delay(99);
}
Especially for a simple device like a Rtc
Did you try the i2c scanner sketch from the Arduino site, it normally works and shows what devices are connected.
Can you try that first and let me know if it detects your clock
After that, I modified it to use “Wire” or “HardWire” depending on a define (as my library, using a pointer). Wire works OK but HardWire hangs Maple.
As I understand, Maple’s Wire was software Wire, but I also thought that it was using other pins -19 and 20- (I tested ‘as is’, without changing connections, and it worked).
I’ll change to use Wire and that’s all….
Finally I’ve used standard Wire, that works on I2C1.
It’s tested and merged to master: https://github.com/Naguissa/RTCLib
Now, let’s continue with Wifi, SDCard, Soil sensor… some with common libs, other with self-made ones. I had wifi and sol sensor working in my nano (not in libraries) just before my hard disk died…
Do you have an example code we could include in an examples folder
Thanks
About example, it’s basically the one posted before:
#include "Arduino.h"
#include "Wire.h"
#include "RTCLib.h"
RTCLib rtc;
unsigned int pos;
void setup() {
delay (2000);
Serial.begin(9600);
Serial.println("Serial OK");
// Max position: 32767
for(pos = 0; pos < 1000; pos++) {
rtc.eeprom_write(pos, (unsigned char) pos % 256);
}
// Only used once, then disabled
// rtc.set(0, 42, 16, 6, 2, 5, 15);
// RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
pos = 0;
#ifdef _VARIANT_ARDUINO_STM32_
Serial.println("Board: Maple");
#else
Serial.println("Board: Other");
#endif
}
void loop() {
rtc.refresh();
Serial.print("RTC DateTime: ");
Serial.print(rtc.year());
Serial.print('/');
Serial.print(rtc.month());
Serial.print('/');
Serial.print(rtc.day());
Serial.print(' ');
Serial.print(rtc.hour());
Serial.print(':');
Serial.print(rtc.minute());
Serial.print(':');
Serial.print(rtc.second());
Serial.print(" DOW: ");
Serial.print(rtc.dayOfWeek());
Serial.print(" ---- ");
Serial.print(pos);
Serial.print(": ");
Serial.print(rtc.eeprom_read(pos));
Serial.println();
pos++;
pos %= 1000;
delay(100);
}
I was just going to make it into the new library structure, where the cpp and h are in a sub folder and there is a descrition file etc
Otheriwse the IDE starts to give warning messages for some people (especially linux)
Thanks
Roger
I will see if I can add it as a git submodule
Thanks
Its been added as a sub module i.e the repo references your repo for the files.