Forum

Please consider registering
guest

Log In Register

Register | Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
TimerOne+i2c+HardwareSerial not work
2016 年 10 月 31 日
16:10:15
zealot01
New Member
Forum Posts: 2
Member Since:
2016 年 10 月 31 日
Offline

I was going to do the IMU on i2c bus. The frequency of data acquisition without delay is very important to me, so I used a TimerRTC to read the data from the sensor bus i2c every 1ms. But this solution did not work, the software crashed after few seconds Frown. By throwing out all superfluous code, I understand that hangs due to a hardware serial port(i was send data to esp8266 time to time). When I commented out i2c code or hardware serial port program does not hang.
Run on 86duino zero
When i commented
Wire.beginTransmission(4);
Wire.endTransmission();
or
Serial1.print("test");
program work fine

#include "Wire.h"
#include "TimerOne.h"
#include "i2c.h"

void setup()
{
Wire.begin();
i2c_SetSpeed(0, I2CMODE_AUTO, 400000L);

Serial.begin(9600);
Serial1.begin(115200);
while (!Serial);
TimerRTC.initialize(1000);
TimerRTC.attachInterrupt(callback);
}

void callback(){
Wire.beginTransmission(4);
Wire.endTransmission();
}

void loop()
{
Serial.println("hello");
Serial1.print("test");
delay(500);
}

2016 年 11 月 03 日
14:12:33
cucubutter
Moderator
Forum Posts: 84
Member Since:
2014 年 04 月 10 日
Offline

Hi zealot01

http://cache.nxp.com/documents.....M10204.pdf

This is Official I2C Specification Version 6,the table3 describe that i2c have some reserved addresses. Maybe you can choose address other than i2c reserved addresses.

#include "Wire.h"
#include "TimerOne.h"
#include "i2c.h"

void setup()
{
Wire.begin();
i2c_SetSpeed(0, I2CMODE_AUTO, 400000L);

Serial.begin(115200);
Serial1.begin(115200);
Serial2.begin(115200);

TimerRTC.initialize(1000);
TimerRTC.attachInterrupt(callback);
}

void callback(){
Serial.println("in");
Wire.beginTransmission(8);
Wire.write("Hello slave!", 12);
Wire.endTransmission();
Serial.println("out");
}

void loop()
{
Serial1.print("test");

while(Serial2.available() >0)
{
Serial.print((char)Serial2.read());
}
Serial.println();

delay(500);
}

I connect 86Duino's Serial1 to 86Duino's Serial2 and connect 86Duino's I2C to Arduino YUN's I2C. And this Code is working fine.

cucubutter

2016 年 11 月 07 日
15:04:01
zealot02
New Member
Forum Posts: 7
Member Since:
2016 年 11 月 07 日
Offline

Ok, i have L3G4200D gyroskope on i2c (address 0x68) and esp8266 on Serial1, run on 86dune zero. This code crash after a few seconds (5-10) after start. Timer1 instead TimerRTC not working at all

#include "Wire.h"
#include "TimerOne.h"
#include "i2c.h"

void setup()
{
Wire.begin();
i2c_SetSpeed(0, I2CMODE_AUTO, 400000L);

Serial.begin(9600);
Serial1.begin(115200);
while (!Serial);

delay(5000);

Serial.println("Init");

TimerRTC.initialize(1000);
TimerRTC.attachInterrupt(callback);
}

void callback(){
Wire.beginTransmission(0x68);
Wire.write(0x20);
Wire.write(0xff);
Wire.endTransmission();
}

void loop()
{
while(Serial1.available()>0){
char c=Serial1.read();
Serial.print(c);
}

Serial1.println("AT");

delay(500);
}

Forum Timezone: Asia/Taipei

Most Users Ever Online: 229

Currently Online:
5 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Dinosaur: 27

leutenecker: 13

mrZagg: 10

hippy: 9

UIdahoCIT: 8

smeezekitty: 8

Ekkehard: 8

lukeross: 8

tomka: 8

blaxxun: 7

Member Stats:

Guest Posters: 11

Members: 1488

Moderators: 14

Admins: 5

Forum Stats:

Groups: 2

Forums: 11

Topics: 248

Posts: 1114

Newest Members: fungus, MixThors, Shcookius, modtra, alan1974, Sergeyfup, mitunsclusa, Dennissot, bb4000, Ovendaanalolymn

Moderators: Glaux: 70, uaa: 11, guigra: 17, Android_Lin: 228, bcarroll: 12, cucubutter: 84, recycled-air: 12, stevemork: 16, zerozaber: 52, pongraczi: 26, jejump: 14, George Andrews III: 56, poto: 11, garpastym: 20

Administrators: eveshih: 1, anthony: 31, viky6: 0, roboard: 135, hcl: 1